Tomcat docBase with versioned deploy - tomcat7

Now I usually deploy a web app as ROOT in tomcat 7.
I want map a folder that contains images, pdf and so on, and I use ad alias
so my server.xml contains this:
<Context path="" docBase="ROOT"
aliases="/tomcat-reources=/C:/Workspace/path-to-tomcat/tomcat-resources"
reloadable="true"/>
and I'm able to show resources in C:/Workspace/path-to-tomcat/tomcat-resources
in urls, such as
<img src="/tomcat-reources/googfy.png" />
I have the problem when I try to version the app, calling the war like
ROOT#20180925.war:
the web app is deployed, but links to tomcat-reources do not work

I've not found a good solution, so my workaroud is manage static resourcs by web server (I use nginx)

Related

Jetty use a servlet

I am trying to make a jetty web app to display content from a template.
The code I have is a java file with the class that holds the information, a pom file, and a template.tpl file.
When I run mvn jetty:run, it spins up a server on port 8080 and points to the root od my web app folder.
How do I make it so when I type /template.tpl i can run java to fill the template?
Thanks in advance
Have you configured a web.xml file yet? Here's a guide on how to do this.
Basically in your web.xml file, you configure the Servlets you write and map them to matching urls.

How to deploy multiple applications in tomcat with the same port and change in context?

I want to deploy multiple web applications in my tomcat 8.5 server with the same port and different application context. So far by putting all the war in the Webapps directory, I am able to achieve that. Now the use case is one of those application needs to be deployed on 80 port while others will be on 8080 port.
So the set looks like:
http://x.x.x.x:8080/xyz
http://x.x.x.x:8080/abc
http://x.x.x.x:8080/foo
http://x.x.x.x/bar
Now there is a link in /xyz application which redirects to /bar application and these two should share the session between them, otherwise, the link in /xyz application is redirecting to login page.
My query is whether I need to configure anything at tomcat level in order to achieve that. Note that my applications are built on top of Spring MVC
Use context docbase as mentioned below
<Context docBase="/your/path/app1"
path="/app1" reloadable="true" />
<Context docBase="/your/path/app2"
path="/app2" reloadable="true" />

How to use logback for several web apps on Tomcat7?

I can successfully configure logback for a single web app and deploy it to Tomcat7 with the dependent jars in WEB-INF/lib. Then, when I move my dependent jars to the lib folder in CATALINA_HOME, it seems that the logback.xml config file is not found. I have a separate logback.xml file for each web app, sitting in the classes folder of each deployed war file. I have separate logback config files for each web app because I want each web app logging to a different rolling file appender, if possible. With some quick google searches, I failed to find documentation for this style of setup. Can anyone point me to a helpful resource, or just some good advice?
My boss, Venu, solved this problem yesterday by following a hunch. I suggested that he try to force tomcat to use logback for all of its logging, and then we may be able to control our logging in each of the web apps. When he tried that, it worked great. We then decided we did not need to log to different files for each web app because we can grep by the logger name, as our logging pattern includes it. A google search finds plenty of blog posts on how to force tomcat7 to use logback.

Debugging GWT Client in Eclipse while running on Tomcat (multiple WARs)

I've recently started a new job wherein I have to fix bugs with and make additions to a suite of GWT applications which have had a lot of contributors/developers of the years :(
App Server: Tomcat 6.0.16
JRE: Java 6
GWT: 2.5.0
Eclipse: Juno
The strange thing about this configuration is that for each application in the suite (there's about 4) the client-side code is separated into it's own war file and the server-side code is separated into several war files.
The problem is that the various components (war files) have reliance's on one another and interact during runtime.
Request
Basically, I have gotten server-side debugging working but I would like to get client-side debugging working via Eclipse; so far I haven't been able to.
Code Layout
When the code is fully deployed to Tomcat, it looks like this:
webapps
serverPiece1
WEB-INF
classes
...
web.xml
...
serverPiece2
WEB-INF
classes
...
web.xml
...
clientApp1
WEB-INF
web.xml
index.html
...
clientApp2
WEB-INF
web.xml
index.html
...
clientApp3
WEB-INF
web.xml
index.html
...
Past Experiences
At my last job my team was the only team developing using GWT and Maven.
We were able to design and implement the applications and thus we kept things simple.
For each application, we kept all of the client & server code in 1 WAR file.
All shared components that we created (window management system, etc...) were JAR'd up and included in each applications WAR file.
Doing things this way made for a very simple debug setup; we were able to debug both the client & server code using Eclipse while running the applications in Tomcat or Weblogic.
There is a setting which allows you to start the GWT dev mode with an external server.
See here for more details. Basically you do following things:
Start your App server in debug or run mode (depending if you want to also debug your backend code in eclipse).
Start GWT dev mode with the -noserver option (which won't start the embedded jetty container).
Go to the URL that is served by your app server (i.e. http://localhost:8080/index.jsp?gwt.codesvr=localhost:9997)
If you use maven you can run the dev mode with following command : mvn gwt:run -Dgwt.noserver=true

Clear web pages cache in jboss

I develop a web app:
frontend javascript
transport json
backend Java EE
JBoss AS 6.1
All static html and js files are in an exploded .war directory which itself is in an exploded .ear directory.
Normally everything works fine! Today I changed a html file and copied it to the .war directory.
When the browser loaded the file it was the old one. So I started wireshark and saw in wireshark the get request and the returned OLD file, even when I changed the filename in the .war directory.
So there is some caching in jboss. I started Googling and found some posts about the tmp and work folders.
I looked in my "...\server\default\work..." folders, but everything was empty.
In "...\server\default\tmp" I found some files but no one seems to be related to my cached page.
As this is a tomcat-in-jboss issue, you have to go to the tomcat area in jboss.
In my case ..\server\default\deploy\jbossweb.sar. In this directory you should find a file called context.xml.
Now stop jboss.
In the context tag there are 2 attributes - cookies and crossContext. Now just add the attribute cachingAllowed="false" and start jboss again:
<Context cookies="true" crossContext="true" cachingAllowed="false">
If you need only one time solution, just create fresh ear with fixed HTML file, undeploy the old one and deploy the new one.

Resources