• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading Javascript from a webapp  RSS feed

 
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear coderanch,

I'd like to load a Javascript file from another webapp.  I have an html file in webapp-A that loads some Javascript relatively from a directory inside its own webapp i.e.



However I need to refactor this so that "my.js" now sits outside of webapp-A, and inside another webapp-B.

How can I load / reference /soource JS files from one webapp to another?

Regards, Sam
 
Saloon Keeper
Posts: 7994
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It completely depends on how the separate web-apps are going to be deployed. If they both are going to live on the same host, with a fixed path, you can reference them using a path relative from the root directory:

 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Stephan van Hulst,

Thank you for your reply.

I did try that, but Im getting 404.

My two webapps, webapp-A, and webapp-B are completely separate webapps hosted on the same tomcat. i.e. tomcat/webapps/



But trying your suggestion results in 404



From webapp-A

<script type="text/javascript" src="/mywebapp-1.0-SNAPSHOT/someDir/js/my.js"></script>

Regards, Sam


 
sam wootton
Ranch Hand
Posts: 105
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is using something like this in server.xml of tomcat better?

<Context docBase="mywebapp-1.0-SNAPSHOT/someDir/js/" path="/my-js" />

The only problem is that I need more than one file referenced like this, can I have multiple <Context elements loading in different files?

Regards, Sam
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why the script can't be shared at the build level. Why does it need to be scraped from the other web app?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!