user1598467
user1598467

Reputation:

EC2 Tomcat7 Spring Not Finding WebApplicationInitializer, But Works Locally

I'm frustrated at this.

Locally

Fresh install of Tomcat 7.0.50 WAR built with maven, drop WAR into Tomcat, start Tomcat, see all the logs I should, deploys fine, can hit locally. No Context defined in server.xml. No context in WAR, configured with xml-free Spring 3.1.0.

Remote EC2 Server

Fresh t1.micro instance -> 'sudo yum update' -> 'sudo yum install tomcat7'. Installs a Tomcat 7.0.47. Compared server.xml, tomcat's web.xml, all files are exact same as my local. Drop WAR. Start tomcat. Nothing. localhost log file shows 'No WebApplicationInitializer detected on classpath'.

What is inherently different about these setups that is ruining my EC2 box from finding the class in the WAR? It explodes the WAR into a folder and then just drops the ball.

I've been working at this for hours now (literally over 6) and have had no luck.

Tried the following

Adding various combinations of Context tags to the server.xml.

Deploying war as "ROOT.war"

Hitting every URL combination I could imagine. (I hit the tomcat server and get the tomcat 404 everywhere except at "tomcat:8080" I just get a white screen 404.

I can't find many thorough explanations of the tomcat classpath.

DISCLAIMER: I have found some but they are just unhelpful. My WebApplicationInitializer class is in WEB-INF/classes of the WAR and clearly Spring/Tomcat is NOT finding it.

I am defeated.

Anyone who even attempts to figure this out has my gratitude.

Upvotes: 1

Views: 942

Answers (2)

Kayaman
Kayaman

Reputation: 73558

Luckily I didn't spend too many hours on this, and I barely cried at all.

My problem was with Tomcat 8, but I didn't realize that the JDK installed was openjdk-1.7.0, when I wanted Java 8. Installing openjdk-1.8.0 fixed my problem.

What threw me off was that the logs showed that JerseyAutoConfiguration (in Spring Boot) was found, but my initializer wasn't.

Upvotes: 0

yoram givon
yoram givon

Reputation: 612

I spent more than a few hours trying to figure out why this is happening. As expected the solution was so simple it made me want to cry :-) All I had to do in my case to solve the issue was to upgrade my Java to 7.0 on the ubuntu machine that was running my tomcat (Apache Tomcat/7.0.26), once I did that, everything worked as expected.

To change your ubuntu java to version 7 do the following:

sudo apt-get purge openjdk*
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-set-default

This will perform the following tasks:

  1. Remove all previous openjdk installs

  2. Install the add-apt-repository command

  3. Add an external repository that has oracle java package

  4. Install Java 7

If after you do this you suddenly get an error "* no JDK found - please set JAVA_HOME" when you try to start Tomcat7 service, just update the JAVA_HOME location under /etc/default/tomcat7

Upvotes: 1

Related Questions