Skip to content
Advertisement

Webapp deployment fails after maven implemtation

I am facing issue in deploying my web app on tomcat after I have implemented Maven for dependency management. Before Maven implementation, it was a plain web app where every thing was used to be managed manually. I started upgrading app with frameworks for learning and decided to implement Maven for dependency management as first step. While I implemented Maven and everything works fine from eclipse, it does not work when I deploy war file on a standalone tomcat.

I am defining path to my app in Catalina properties against shared.loader property and a context xml under Catalina folder within tomcat conf directory (see the directory structure below)

directoryStructure

JavaScript

Following are the relevant entries from Tomcat configuration

catalina.properties

JavaScript

server.xml (apart from default host tag, I have added one more for my app)

JavaScript

OpsMan.xml

JavaScript

In “C:Windowssystem32driversetchosts” file following entry has been created and port proxy set to redirect HTTP requests on port 80 to 8080.

JavaScript

log4j2.xml

JavaScript

pom.xml

JavaScript

jars in “WebAppWEB-INFlib” folder

lib folder with Maven

jars in “WebApp_20220102WEB-INFlib” folder

lib folder without Maven

web.xml in the “WebAppWEB-INF” folder

JavaScript

Now when I start tomcat I get error in deployment of OpsMan. Following is the console output

JavaScript

With the same setup if I rename “WebApp” to “WebApp_New” and “WebApp_20220102” to “WebApp” (basically the old app) then everything works fine without any problem.

I have compared all configuration files within “WebApp” folder, e.g. log4j2.xml, web.xml etc. but not able to figure out the problematic entry. I have also tried replacing jars from old app (WebApp_20220102WEB-INFlib) to the new app’s lib folder but nothing changed. I continue to get the issue in deploying new app, but if I rename WebApp folders and launch old app, it works just fine.

Advertisement

Answer

Since I was able to run the app when deployed on tomcat within Eclipse, I started looking at differences in configuration of standalone tomcat and that within eclipse. I did not find any differences or I matched the config of both servers.

After this I decided to look at each and every file within Web App folder and I found difference in size of .class files. I realized that when eclipse is deploying it on the internal tomcat, it is compiling the output to the target folder but when this is done using maven, class files are generated in /target/classes folder. This folder is copied to the /WEB-INF/classes folder at the time of packaging.

In my case, I do not know how, I had classes folder within the project’s WebContent/WEB-INF/classes directory. This directory had very old version of classes, with very small size (3KB Vs 10KB). I removed the classes directory from the WebContent/WEB-INF folder and maven started copying target/classes folder to WEB-INF/classes. This resolved the issue.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement