• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2256
  • Last Modified:

Java application runs fine, Java Servlet throws NoClassDefFoundError

Hey experts, I am having difficulty getting my Java Servlet to run properly.  I am attempting to connect to an Amazon Web Services S3 server where I need to manage files etc for a website I am building.  Basically, I have written a very simple program using the JetS3t API library for Amazon's S3.   I am able to successfully execute the code when running it as a java application, however the same code throws back a NoClassDefFoundError when running it as a java servlet.  

I am using eclipse europa, apache tomcat 6.0.18, sun java jdk 1.6.0_02 as my environment.

The jar file required for the NoClassDefFoundError (BadPaddingException) is the jce.jar.  This jar is included in my classpath via JRE System Library.  However, when running as a java servlet, tomcat does not seem to be able to read this.  I have attempted to load the jce jar in the Tomcat JVM classpath settings, placing it in the web-inf/lib classpath of my java project, as well as in the Apache Software Foundation\Tomcat 6.0\lib folder to no avail.  

Below is the code I am using to connect to Amazon's S3.  The first block of code is the code I use when connecting as a java application, the second block of code is the code used in my java servlet, the third is the stacktrace I am receiving when running the java servlet.  I am fairly confident in that the problem does not lie in the code, but how tomcat reads the appropriate jar files (or in this case, is not reading them).  

Any help would be greatly appreciated, thanks!
import org.jets3t.service.S3Service;
import org.jets3t.service.S3ServiceException;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.model.S3Bucket;
import org.jets3t.service.security.AWSCredentials;
 
public class S3Download {
 
	private static final String awsAccessKey = "***********";
	private static final String awsSecretKey = "************************";
 
	public static void main(String args[]){
		try{
			AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
			S3Service s3Service = new RestS3Service(awsCredentials);
			
			S3Bucket testBucket = s3Service.createBucket("the-test-bucket");
 
		}catch (S3ServiceException e){
			e.printStackTrace();
		}
	}
}
 
 
 
 
 
 
import java.io.IOException;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.jets3t.service.S3Service;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.model.S3Bucket;
import org.jets3t.service.security.AWSCredentials;
 
public class ProfileServlet extends HttpServlet{
	
	private static final String awsAccessKey = "**********";
	private static final String awsSecretKey = "**********************";
	
	public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		try{
			AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
			S3Service s3Service = new RestS3Service(awsCredentials);
			
			S3Bucket testBucket = s3Service.createBucket("the-test-bucket");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
 
 
 
org.jets3t.service.S3ServiceException: S3 PUT connection failed for '/'
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:491)
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestPut(RestS3Service.java:775)
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.createObjectImpl(RestS3Service.java:1343)
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.createBucketImpl(RestS3Service.java:1214)
	at org.jets3t.service.S3Service.createBucket(S3Service.java:1486)
	at org.jets3t.service.S3Service.createBucket(S3Service.java:1238)
	at org.jets3t.service.S3Service.createBucket(S3Service.java:1265)
	at vagabondery.servlets.ProfileServlet.service(ProfileServlet.java:27)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
	at vagabondery.servlets.ProfileRoutingFilter.doFilter(ProfileRoutingFilter.java:84)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at vagabondery.servlets.WebauthFilter.doFilter(WebauthFilter.java:30)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NoClassDefFoundError: javax/crypto/BadPaddingException
	at sun.security.rsa.RSASignature.engineVerify(RSASignature.java:173)
	at java.security.Signature$Delegate.engineVerify(Signature.java:1140)
	at java.security.Signature.verify(Signature.java:592)
	at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:441)
	at sun.security.x509.X509CertImpl.verify(X509CertImpl.java:389)
	at javax.crypto.SunJCE_b.d(DashoA13*..)
	at javax.crypto.SunJCE_b.c(DashoA13*..)
	at javax.crypto.SunJCE_b$1.run(DashoA13*..)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.crypto.SunJCE_b.<clinit>(DashoA13*..)
	at javax.crypto.Mac.getInstance(DashoA13*..)
	at org.jets3t.service.utils.ServiceUtils.signWithHmacSha1(ServiceUtils.java:133)
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.authorizeHttpRequest(RestS3Service.java:562)
	at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:319)
	... 29 more

Open in new window

0
Vagabondery
Asked:
Vagabondery
  • 10
  • 8
1 Solution
 
objectsCommented:
u sure tomcat is running using 1.6?
do you jhave any pre-1.4 versions of java installed?

0
 
VagabonderyAuthor Commented:
I posted the tomcat startup info to verify its version of 6.0.18.  The earliest version of JRE/JDK I have installed on this computer is 1.5.0_12 .   My tomcat JVM JRE is set to the JDK 1.6.0_02, and my tomcat base is set to C:\Program Files\Apache Software Foundation\Tomcat 6.0
Feb 18, 2009 9:14:37 PM 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: C:\Program Files\Java\jdk1.6.0_02\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.6.0_02\jre\bin;C:\Program Files\Java\jre6\bin\client;C:\Program Files\Java\jre6\bin;C:\Program Files\PHP\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Common Files\Ulead Systems\MPEG;C:\Program Files\Java\jdk1.6.0_02\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin;C:\PHP;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\SSH Communications Security\SSH Secure Shell
Feb 18, 2009 9:14:37 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 18, 2009 9:14:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 422 ms
Feb 18, 2009 9:14:37 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 18, 2009 9:14:37 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Feb 18, 2009 9:14:38 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Feb 18, 2009 9:14:38 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Feb 18, 2009 9:14:38 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/27  config=null
Feb 18, 2009 9:14:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 977 ms

Open in new window

0
 
objectsCommented:
jce should already be available as part of the jdk
have u made any changes to the tomcat startup options

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
whats in your web-inf/lib directory?

0
 
VagabonderyAuthor Commented:
Not that I am consciously aware of.  I did not personally setup my tomcat/eclipse environment.  Is there anything in particular I should look into?
0
 
VagabonderyAuthor Commented:
My web-inf/lib directory includes the jar files required for the JetS3t API library.  Along with a few logging scripts.  I took a screenshot of my build path for my project.
buildpath.jpg
0
 
objectsCommented:
what about once deployed?

0
 
VagabonderyAuthor Commented:
I apologize, but I am not sure I understand what you mean exactly by 'once deployed'.

If it helps any, the servlet is able to run the code up until I try to create a bucket.  I can connect with the AWSCredentials and create a new RestS3service, but I get thrown the error when I attempt to create a bucket (or manipulate any data on the S3 server for that matter).
0
 
objectsCommented:
I mean when you deploy your webapp to tomcat.
Or are you running tomcat from within eclipse?

0
 
objectsCommented:
I have attempted to load the jce jar in the Tomcat JVM classpath settings, placing it in the web-inf/lib classpath of my java project, as well as in the Apache Software Foundation\Tomcat 6.0\lib folder to no avail.  

have u removed all of those changes?

0
 
VagabonderyAuthor Commented:
Ah, sorry for not mentioning previously.  I have a tomcat plugin for eclipse.
0
 
VagabonderyAuthor Commented:
Yes, the only jce.jar remaining is the one located in my JRE Systems Library.
0
 
objectsCommented:
can you try deploying to tomcat to see if the issue is caused by the plugin

0
 
VagabonderyAuthor Commented:
Also, the stacktrace I received before was when I had the jce.jar in my Tomcat JVM classpath, as well as my JRE Systems Library.  When i remove the jce.jar from my Tomcat JVM Classpath settings (and retain the jar in my JRE Systems Library), I receive the following stacktrace:
Feb 18, 2009 9:54:04 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet ProfileServlet threw exception
java.lang.NoClassDefFoundError: javax/crypto/BadPaddingException
	at vagabondery.servlets.ProfileServlet.service(ProfileServlet.java:24)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
	at vagabondery.servlets.ProfileRoutingFilter.doFilter(ProfileRoutingFilter.java:84)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at vagabondery.servlets.WebauthFilter.doFilter(WebauthFilter.java:30)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)
Feb 18, 2009 9:54:04 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet ProfileServlet threw exception
java.lang.NoClassDefFoundError: javax/crypto/BadPaddingException
	at vagabondery.servlets.ProfileServlet.service(ProfileServlet.java:24)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
	at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
	at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
	at vagabondery.servlets.ProfileRoutingFilter.doFilter(ProfileRoutingFilter.java:84)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at vagabondery.servlets.WebauthFilter.doFilter(WebauthFilter.java:30)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

Open in new window

0
 
VagabonderyAuthor Commented:
Alright I deployed the war to tomcat, and I received the same error (posted below).
HTTP Status 500 -
 
type Exception report
 
message
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception
 
javax.servlet.ServletException: Servlet execution threw an exception
	vagabondery.servlets.ProfileRoutingFilter.doFilter(ProfileRoutingFilter.java:84)
	vagabondery.servlets.WebauthFilter.doFilter(WebauthFilter.java:30)
 
root cause
 
java.lang.NoClassDefFoundError: javax/crypto/BadPaddingException
	vagabondery.servlets.ProfileServlet.service(ProfileServlet.java:24)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	vagabondery.servlets.ProfileRoutingFilter.doFilter(ProfileRoutingFilter.java:84)
	vagabondery.servlets.WebauthFilter.doFilter(WebauthFilter.java:30)
 
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.

Open in new window

0
 
VagabonderyAuthor Commented:
Found out the problem, it was an issue with with the boot classpath configuration for my tomcat server. I had the wrong rt.jar mapped from an older JDK installation.
0
 
objectsCommented:
thats what I thought when I asked earlier regards version s of java installed.
good to hear u got it sorted

0
 
VagabonderyAuthor Commented:
Objects, thank you for your patience, you were right on the money I just had to investigate it a little further.  I appreciate your help good sir!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now