0

I have 2 wars deployed under single tomcat instance.

Can i use static resources (js/css) of one war into another to avoid duplicay of the code. If yes how can i use them. Is giving the full path sufficient.

eg.

A.war

B.war

I want to use sample.js file from A.war into B.war index.html

Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
  • Yes you can, but shutting down or undeploying one app will cause the other to break. Css and JavaScript files are very small, just deploy them twice. – Stefan Aug 12 '16 at 11:56
  • @techprat i am not asking about java classes/methods, instead to access static resources – Ankur Singhal Aug 12 '16 at 11:58
  • @Stefan Thanks, but to reduce duplicay of code , i do not want to have the same code at 2 places. Also if i can access static resources from another war, is it the path i need to set or something else as well. – Ankur Singhal Aug 12 '16 at 11:58
  • It's totally possbile to do a library with static code, this way you avoid codeduplication and still have js and css in both wars. Look in particular for wars overlays or webjars. – user2189998 Aug 12 '16 at 14:03

1 Answers1

1

Yes, you can. You simply need to put the context root of application A in the path for the script reference, e.g. like this

<script src="/A/sample.js"></script>
Guenther
  • 2,035
  • 2
  • 15
  • 20