Search code examples
java-8classpathlog4j2noclassdeffounderrortomcat9

Web application throws NoClassDefFoundError in Unix server whereas locally in Eclipse it works properly


I'm newbee in web application deployment and stuff related to this. I have simple maven web application which works cool locally in my Eclipse & Tomcat9 server. Application has jsp file and main class, both try to call log4j2 classes like Logger or LogManager:

<% Logger.getLogger("bla").toString()%>

or in main:

private statis final Logger logger = LogManager.getLogger("blablabla");

Just in addition I call getPath() method on those classes and they show me my local maven repository.

After I deployed it on Unix server I get NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.status.StatusLogger in browser and if I try to call it again I always get a bit different: NoClassDefFoundError: Could not initialize class org.apache.log4j.LogManager

Trying to execute main class through the PuTTY I get the same however after setting up a export CLASSPATH=$CLASSPATH:./WEB-INF/lib/* to the path with the libraries the program exetutes in console showing me enviroment CLASSPATH exactly as i've set before but continuing to not to work as web application through the browser.

I've tried to set CLASSPATH through the command above (startup.sh\setenv.sh etc...) but nothing. The command ...catalina.sh version shows me a CLASSPATH but app still doesn't work. I can only run a main class in PuTTY after manual setting up the CLASSPATH as I said above.

I've run out of ideas, probably you guys can give me some tips & hints about it? Maybe there is some script to set it each time starting the app. Unfortunatelly I'am not able to attache some code stuff.


Solution

  • The problem was related to the SecurityManager which was turned off on my local whereas it was turned on on a server. First I had simulated problem on my local, then I found out what permissions are missed debagging SecurityManager. I then added an VM argument -Djava.security.debug=access,failure to a run conf. Be carefull because of huge amount of output in console and better to log it in external txt file. After that I ran through the log.txt serching a word like "denied\failed\fail" and added necessary permission to a catalina.policy file.

    Hope that will be helpfull for somebody.