Extracting startup errors from Spring contexts - java

Consider the following output from a Tomcat server under Eclipse:
INFO: Initializing Coyote HTTP/1.1 on http-8080
INFO: Initialization processed in 634 ms
INFO: Starting service Catalina
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
SEVERE: Error listenerStart
SEVERE: Context [/MyServlet] startup failed due to previous errors
I would like to figure out what exception caused "Error listenerStart", but Spring seems to be preventing me from finding the error via Eclipse. I'd love to start Catalina manually, but that doesn't seem to do anything.
What's the best way to find the hidden exception? I'm not afraid to use torture methods.

In my case, the answer was:
Debug java.util.logging.SimpleLogger to find out what exceptions were being hidden.
Figure out that my logging.properties file, cut-and-pasted from the Tomcat docs, was bunk. Several exceptions were going into black holes in log files (maybe they weren't flushed)? Switching everything to a single ConsoleLogger enabled me to see all exceptions.
Make sure that -Djava.util.logging.config.file="/<path>/logging.properties" was present in my Run Configuration.

Try to configure logger (Log4j for example) and log errors to console.

Check tomcat's logs directory, see if it logged to an alternate log file.

Related

Cannot run JAX-WS Java Web Service on Apache Tomcat

Summary
I've been tasked to write a Java web service to integrate two disparate systems in our enterprise environment. Since I'm actually an experienced C#.NET MVC developer and only consider myself intermediate at Java, I began by searching for "Java Web Service Tutorials". I am trying to run this common tutorial, but I'm unable to run the tutorial service due to an HTTP 404 error.
Process
I'm using the Java Web Application template in Netbeans 8.0.2. I used JDK 1.6.0.25 to compile the tutorial (since the eventual service I need to write will need this Java version to be compatible with some other JARs I'll be using). Everything compiles to a WAR file just fine.
I then deployed the WAR file by loading the server's Tomcat Manager GUI and using the WAR file to deploy feature. When I do so, the WAR file is copied, and the application starts. However, when I attempt to access the service via the link "http://localhost:8080/HelloWorld/hello" from the tutorial, the service returns a 404 error.
Server Environment
Oracle Enterprise Linux distro, version 3.8.13-44.1.1.el6uek.x86_64
Apache Tomcat 6.0.24
JVM 1.7.0_75-mockbuild_2015_01_20_16_42-b00
If the advice is that I need to change the Java or Tomcat versions or platforms, I need to know that as well since I have little experience with these technologies. However, I may not be able to change all the factors due to limitations with my Linux distro (per my server admin).
Things I've tried (in order):
Setup a Local Tomcat Server on Windows
I installed a local Tomcat Server on my Windows 7 laptop. Since the Linux server is running Java 1.7.0.75, I installed a matching Windows version of JRE 1.7.0.75 from Oracle's support page. I then downloaded Apache Tomcat 6.0.24 Windows Service from their archives and installed it successfully, using the JRE 1.7.0.75 and local port 1985 (to separate it from the GlassFish local server used within Netbeans).
Just as on the Linux server, my local Tomcat server couldn't start the tutorial. Manually clicking the start command link gives me the message "FAIL - Application at context path /com.mkyong.ws could not be started". My local server's logs don't show anything about that application failing to start either.
Adding JAX-WS RI JAR files to {$Tomcat}/lib
Per section 5 on the tutorial mentioned above, I then added the indicated JAR files to the server's {$Tomcat}/lib folder and restarted the server. This time, the application started, but I still couldn't access the service. The link "http://localhost:8080/HelloWorld/hello" from the tutorial returns a 404 error. I even tried copying the entire JAX-WS RI/lib folder to the {$Tomcat}/lib directory with no changes, so I backed out this change.
For reference, here's a list of the files I've copied:
gmbal-api-only.jar
ha-api.jar
jaxb-core.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
management-api.jar
policy.jar
stax-ex.jar
streambuffer.jar
Enabling DEBUG mode in the local Tomcat Server
I un-deployed the WAR file. Using the Apache Tomcat Monitor, I stopped the service, deleted the existing logs, enabled the DEBUG logging level, and restarted the service. I then re-deployed the tutorial WAR file. I again saw it didn't start, and then I opened all the log files. There is not even a mention of the failure to access the service, but perhaps 404 errors aren't logged.
Running the service using the Netbeans-embedded Glassfish server
When I first created the Web Application, Netbeans offered to set me up with a local Glassfish server. I accepted, and I set everything up with defaults. When I try to run the tutorial against this server, I cannot access the service. The link "http://localhost:8080/HelloWorld/hello" from the tutorial still returns a 404 error.
Researching other posts and tutorials
Here are some other StackOverflow posts and websites I've reviewed without finding a resolution:
JAX-WS on Tomcat server (doesn't apply)
Deploying JAX-WS webservice as War in Apache Tomcat (similar to the tutorial in recommending to copy the extra JAR files)
JAX-RPC / JAX-WS runtime in Apache Tomcat (just informational)
how to deploy a jax-ws service to eclipse or tomcat? (similar to the tutorial in recommending to copy the extra JAR files)
https://myarch.com/create-jax-ws-service-in-5-minutes/ (similar to the tutorial but without deployment help)
Questions I'm Pondering
Is there something wrong with the code in the tutorial? (Doesn't seem likely since from the comments others have had success.)
Is there a significant difference in the versions of Java or Tomcat he's using in the tutorial? (He doesn't give an versions of Java or Tomcat.)
Should I run local Tomcat against a JDK instead of a JRE?
Should the tutorial be compiled against the same JDK as Tomcat is using? (I hope not as this would seem very limiting...)
Can I even run JAX-WS in Tomcat? (Based on pages like http://tomee.apache.org/apache-tomee.html, it seems like the base TOmcat might not even support JAX-WS? Again, just my limited experience.)
I'd appreciate any troubleshooting guidance anyone can offer. Thank you in advance for the help!
UPDATE #1
Per the request of #NIKETBHANDARY, I stopped the service, deleted the logs, restarted the service, and browsed in Chrome to localhost:1985/helloworld/hello - still getting the 404 error. I then opened the catalina.log file, but it's completely empty. Only jakarta_service.log has any log entries, and all are about the service starting. I also verified that the logging level is set to debug. What else can I change to get additional log messages?
I also ran a search for "com.mkyong" in the entire Tomcat directory. Only the webapp WAR file, webapps/../META-INF/context.xml, webapps/../WEB-INF/sun-jaxws.xml, and /conf/cataline/localhost/com.mkyong.we.xml files returned any hits. Nothing in any logs. Could that indicate that this is a configuration problem?
UPDATE #2
Apparently, Tomcat doesn't flush its log messages fully until the thread closes as the service shuts down (probably due to the logging configuration). As such, I stopped the service which flushed the log files. Here's the entire contents of the catalina.log file (which does contain a reference to com.mkyong):
Aug 17, 2015 9:51:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.19.
Aug 17, 2015 9:51:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Aug 17, 2015 9:51:19 PM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-1985
Aug 17, 2015 9:51:19 PM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
Aug 17, 2015 9:51:19 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2121 ms
Aug 17, 2015 9:51:19 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 17, 2015 9:51:19 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Aug 17, 2015 9:51:19 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor com.mkyong.ws.xml
Aug 17, 2015 9:51:20 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
Aug 17, 2015 9:51:22 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
INFO: WSSERVLET14: JAX-WS servlet initializing
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Aug 17, 2015 9:51:22 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-1985
Aug 17, 2015 9:51:22 PM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3895 ms
UPDATE #3
I'm becoming more convinced there's a configuration problem somewhere. On a hunch, I studied and installed Apache TomEE 1.7.2 for Windows, pointing to the same JRE as the regular Tomcat. After studying the running.txt file and experimenting with the properties and settings, I was finally able launch a local version of TomEE. I deployed the same WAR file as before, and I found it would not load the WAR application due to the following error:
java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener
Googling that error led (again) to MKYong's blog for a fix (copy the jaxws-rt.jar file to the {$tomcat}/lib folder. I redeployed the WAR file, and the manager loaded the application. HOWEVER, just like on regular Tomcat, the URL "http://localhost:8080/HelloWorld/hello" from the tutorial still returns a 404 error. So, the results are exactly the same.
Short of compiling the tutorial against other versions of JDK, I'm running out of ideas quickly... :-)
UPDATE #4
Per another request below, here's a list of all JAR files in the {$Tomcat}\lib folder:
annotations-api.jar
catalina.jar
catalina-ant.jar
catalina-ha.jar
catalina-tribes.jar
el-api.jar
gmbal-api-only.jar
ha-api.jar
jasper.jar
jasper-el.jar
jasper-jdt.jar
jaxb-core.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
jsp-api.jar
management-api.jar
policy.jar
servlet-api.jar
stax-ex.jar
streambuffer.jar
tomcat-coyote.jar
tomcat-dbcp.jar
tomcat-i18n-es.jar
tomcat-i18n-fr.jar
tomcat-i18n-ja.jar
The {$Tomcat}\webapps folder contains the following:
..\com.mkyong.ws
..\docs
..\examples
..\host-manager
..\manager
..\ROOT
..\com.mkyong.ws.war
Update #5
The {$Tomcat}\webapps\com.mkyong.ws directory contains the following:
Here's a screenshot of the Tomcat Manager GUI:
Here's a screenshot of the HTTP 404 error I'm receiving along with the URL:
I've also confirmed that the files in the WAR exactly match the tutorial.
There is problem in deployment of your ws module.
U have just copied the whole folder from the MKyoung sample.
I doesn't work that way around.
Not only that now display all the folders and files structure inside the ws module delete the rest of the modules from your post.I wanted only the structure of ws module.
The module name has to sample instead of com.mkyoung.ws
and the structure for it has to be
**sample**
------WEB-INF
------index.jsp
WEB-INF
----classes
----web.xml
----sun-jaxws.xml
classes
----com
--------mkyoung
-----------ws
ws
-----Helloworld.class
-----HeloworldIMPL.class
#NIKETBHANDARY helped me understand what was wrong and how to quickly correct it. I'd also like to post exactly what I did wrong and how I fixed it permanently so that future coders can benefit from my five-day experience. :-)
When I originally built the tutorial using Netbeans, I used the Java Web --> Web Application template (which is available after installing the Java EE Base plugin accessible through Netbeans --> Tools --> Plugins):
I built all the files exactly per the tutorial, but I failed to really read through step #5, especially this line:
<jar jarfile="${dist}/war/HelloWorld-${DSTAMP}.war" basedir="${dist}/war/build/"/>
After further review, I found that the build script was producing a WAR file called HelloWorld.war. Then, when that file was deployed to Tomcat, the web application was called HelloWorld in the Tomcat Manager. That's why the service endpoint was set to http://localhost:8080/HelloWorld/hello. The "HelloWorld" is literally the name of the Tomcat application, and the "/hello" part corresponds with the endpoint from the sun-jaxws.xml file. (Looking back, it makes total sense given typical web hosting organization. IIS pretty much works the same way.)
So, to fix the problem, I needed to modify the Netbeans project to produce a WAR file named HelloWorld.war. In the tutorial, he includes an actual Ant build script. In this case, I needed to take these steps:
Right-click on the project in the Netbeans Project Explorer.
Choose Properties.
Click on the Build --> Packaging category.
Set the WAR file field to HelloWorld.war.
Here is a screenshot:
Once that was done, I created a new build, deployed to my local Tomcat server, and everything worked as expected. I was also able to deploy the WAR file to my Linux server and test it successfully. Problem solved! :-)

FAIL - Application at context path /Appcould not be started by Tomcat Manager 6

I was trying to deploy a war file via tomcat manager 6. Once deployed get always the same
error :
FAIL - Application at context path /App could not be started
The war file is under apache-tomcat-6.0.0/webapps folder.
I was googling and tried different options like :
removing apache-tomcat-6.0.0/work/Catalina/localhost folder and also apache-tomcat-6.0.0/webapps/App
restarting the server and redeploying again.
As I could see in the catalinalog file :
INFO: Deploying web application archive App.war
3:32:47 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
2012 3:32:47 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/App] startup failed due to previous errors
2012 3:32:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
2012 3:32:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/App] startup failed due to previous errors
Any ideas ?
Add a “log4j.properties” file under ‘/WEB-INF/classes’ directory inside your WAR to help debug which one of the listeners is throwing this error.
This holds true for Tomcat versions < 6.0
In Tomcat 6 or above, the default logger is the”java.util.logging” logger and not Log4J. So if you are trying to add a “log4j.properties” file – this will NOT work. The Java utils logger looks for a file called “logging.properties” as stated here:
http://tomcat.apache.org/tomcat-6.0-doc/logging.html
So to get to the debugging details create a “logging.properties” file under your”/WEB-INF/classes” folder of your WAR and you’re all set.
And now when you restart your Tomcat, you will see all of your debugging in it’s full glory!!!
Sample logging.properties file:
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler
and you will most likely see a “ClassNotFound” exception.

google app engine service unavailable

I'm was following http://googcloudlabs.appspot.com/ tutorial to create new Google App Engine project. It throws me an error as per below when I try to run the from my local host, but when I deployed it working fine. (http://mynewcloudcom.appspot.com/). Please help.
HTTP ERROR: 503
Problem accessing /. Reason:
SERVICE_UNAVAILABLE
Powered by Jetty://
Eclipse Console
Mar 05, 2012 10:42:46 AM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Mar 05, 2012 10:42:46 AM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed C:\Smartag_Eclipse_Project\DontEditProject\war\WEB-INF/appengine-web.xml
Mar 05, 2012 10:42:46 AM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed C:\Smartag_Eclipse_Project\DontEditProject\war\WEB-INF/web.xml
Mar 05, 2012 6:42:48 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The server is running at http://localhost:8888/
Mar 05, 2012 6:42:48 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The admin console is running at http://localhost:8888/_ah/admin
Found the answer. I need to run in JDK1.6. Once i changed the Java Compiler(right click project -> properties -> Java Compiler -> (Check) Enable project specific settings -> change the Compiler compliance level), its works fine now. Thanks.
I had the same problem. I justed changed the port from 8888 to 80 in the Debug Configuration and it worked for me.
I had the same issue.
for me the problem was one of my filters had an exception. specifically objectify - it was not loaded properly. you can delete the filter and see if that's it
When using Java 1.7, also check for the Execution Environment and set it to JavaSE-1.7.
You can look into the Execution Environment in:
Right Click -> Properties -> Java Compiler
And you have the option above Restore Defaults and Apply.
I faced the same issue and resolved it by selecting "Automatically select an unused port" in run configuration.
Sometimes it happens there is a "hanging" process that blocks the port. Therefore changing port in Run configuration helps, as well as checking "Automatically select an unused port" in run configuration.
It happened with me too. In my case, I had Run the project and due to some error in my code, the Project ran with errors. So, I debugged it and Run it again but without cancelling the earlier one in the console and it gave me that error. After cancelling or stopping the Project, it ran fine.
i had the same issue. Seems that Plugin is stocked on creating and opening the socket for the server. i don't really know why happens, I've resolved in this way.
Open Run Configurations.
Open Server tab. Change the Embedded server Port.
Open Arguments tab.
3.1 - VM arguments box. i've deleted all that stuff there and just let this
line and save changes and run it.
-Xmx512m -javaagent:/Applications/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.7.5/appengine-java-sdk-1.7.5/lib/agent/appengine-agent.jar
It has worked pretty good 4me.
If someone know which events or configuration change are the reason for . please let us know it
NOTE: "I'm not responsible for unexpected behave. I'm don't know if there is side effects ahead"
The solution working for me is to run appEngineServer from command line using Gradle, as comments in generated build.xml for endpoints module proposes. And gradle config includes option for Java 1.7 compatibility, so it's no reason to use Java 1.6 if You want 1.7:
gradlew modulename:appengineRun
Currently, the appengine gradle plugin's appengine devappserver
launch doesn't interact well with Intellij/AndroidStudio's
Gradle integration. As a temporary solution, please launch from the command
line. ./gradlew modulename:appengineRun
I had a condition where a servlet defined in the web.xml with non existent class name. I specified proper class name, worked!

Unable to run struts program

I developed one web applications using struts. Now when i tried to run in another machine I am getting the following error. Following is taken from glassfish server log
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts-default.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Unable to locate configuration files of the name struts-plugin.xml, skipping
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts-plugin.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Parsing configuration file [struts.xml]
SEVERE: INFO [http-thread-pool-8080-(1)] (CommonsLogger.java:31) - Loading global messages from ApplicationResources
Also in the browser I am getting java.lang.reflect.InvocationTargetExceptionthis message. Please tell me where the problem lies.
This seems to be a similar problem to what is described in this article:
http://www.java.net/node/705006
It appears to be a GlassFish bug to incorrectly put "SEVERE:" before the log message that actually starts with "INFO".
FYI I came across this with SL4J and Glassfish 3.1. The exact same code logging via the JUL logger works perfectly, and then you get the "SEVERE:" when you swap it out with a proper logger.
Sadly I have not been able to find a resolution, and will post it when I find it. It is equally possible that they re-fix the bug in the next version of GlassFish.

Java web-app debugging not possible due to direct undeploy on debug

When i try to debug my webapp it starts up the tomcat server and the application, but shuts down the debugger shortly before the app gets usable. I see the debugging toolbar for a second before it vanishes again, though the app keeps running.
Tomcat-log:
Listening for transport dt_socket at address: 11555
23.03.2010 01:24:35 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
23.03.2010 01:24:35 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
23.03.2010 01:24:35 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 847 ms
23.03.2010 01:24:35 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
23.03.2010 01:24:35 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
23.03.2010 01:24:41 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
23.03.2010 01:24:41 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
23.03.2010 01:24:41 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/78 config=null
23.03.2010 01:24:41 org.apache.catalina.startup.Catalina start
INFO: Server startup in 5855 ms
23.03.2010 01:24:42 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context []
23.03.2010 01:24:45 org.apache.catalina.core.StandardContext start
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/] has already been started
Debugging log:
Attached JPDA debugger to localhost:11555
Checking data source definitions for missing JDBC drivers...
Deploying JDBC driver to /Applications/NetBeans/apache-tomcat-6.0.20/lib/mysql-connector-java-5.1.6-bin.jar
Stopping Tomcat process...
Waiting for Tomcat...
Tomcat server stopped.
Starting Tomcat process...
Waiting for Tomcat...
Tomcat server started.
Undeploying ...
OK - Undeployed application at context path /
In-place deployment at /path/to/project/dir/build/web
deploy?config=file%3A%2Fvar%2Ffolders%2FZP%2FZPbqxGrbHFaUlXzAfgWV1%2B%2B%2B%2BTQ%2F-Tmp-%2Fcontext734173871283203218.xml&path=/
OK - Deployed application at context path /
start?path=/
Start is in progress...
OK - Started application at context path /
debug-display-browser:
Browsing: http://localhost:8084/
connect-client-debugger:
BUILD SUCCESSFUL (total time: 18 seconds)
System is Netbeans 6.8 on MacOS 10.6.2.
You should see if the TC server is still in debug mode. The easiest way to do that is to Debug->Attach Debugger to localhost;11555. If it is still running 'debuggable', you will be able to do a fair bit of debugging that way.
I had similar problem where debugging started but kind of stopped immediately. The application was deployed however. I was not even able to attach to debugger manually, even if the Tomcat was running in debug mode. By creating a simple debuggable hello world project and starting debugging it also made debugger to break to my "problem project"'s break points as well.. But this was not really way to work.
My problem was "solved" by dropping mysql-connector-java.jar from my web project. I don't see any reasoning, but it simply works now. FYI also, the Netbean's Tomcat config's property "Enable JDBC driver deployment" did not have effect.
My environment was Netbeans 6.9.1 and project type was maven2, run on on Win7.

Categories