rstaveley
asked on
NoClassDefFoundError... which .jar?
I've been doing things "the Maven way" and have a nice little web application up an running, which works just fine with Jetty. I need to deploy the .war on a JBoss server now, but I've run into a NoClassDefFoundError.
I guess that means that Jetty and/or my JRE in the DEV system has a .jar that JBoss and/or the JRE on my server is lacking, but how do I find it? It looks like it is something that http://java.sun.com/j2se/1.5.0/docs/api/javax/crypto/Mac.html#getInstance(java.lang.String) is trying to instantiate (presumably a hmac-sha1 Mac, presuambly something in JCE??).
How do I go about finding the appropriate .jar?
I guess that means that Jetty and/or my JRE in the DEV system has a .jar that JBoss and/or the JRE on my server is lacking, but how do I find it? It looks like it is something that http://java.sun.com/j2se/1.5.0/docs/api/javax/crypto/Mac.html#getInstance(java.lang.String) is trying to instantiate (presumably a hmac-sha1 Mac, presuambly something in JCE??).
How do I go about finding the appropriate .jar?
org.jets3t.service.S3ServiceException: S3 GET connection failed for '/'
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:427)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRestGet(RestS3Service.java:583)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.listAllBucketsImpl(RestS3Service.java:832)
at org.jets3t.service.S3Service.listAllBuckets(S3Service.java:1089)
....(my stuff)...
Caused by: java.lang.NoClassDefFoundError
at javax.crypto.Mac.getInstance(DashoA12275)
at org.jets3t.service.utils.ServiceUtils.signWithHmacSha1(ServiceUtils.java:131)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.buildAuthorizationString(RestS3Service.java:786)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.performRequest(RestS3Service.java:278)
... 8 more
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It is Sun 1.5
10:08:53,096 INFO [ServerInfo] Java version: 1.5.0_10,Sun Microsystems Inc.
10:08:53,096 INFO [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_10-b03,Sun Microsystems Inc.
10:08:53,096 INFO [ServerInfo] OS-System: Linux 2.6.18-3-k7,i386
10:08:53,100 DEBUG [ServerInfo] java.home:
/usr/lib/jvm/java-1.5.0-su n-1.5.0.10 /jre
10:08:53,100 DEBUG [ServerInfo] java.specification.vendor: Sun
Microsystems Inc.
10:08:53,100 DEBUG [ServerInfo] user.language: en
10:08:53,100 DEBUG [ServerInfo] java.vm.info: mixed mode
10:08:53,100 DEBUG [ServerInfo] java.version: 1.5.0_10
10:08:53,100 DEBUG [ServerInfo] java.ext.dirs:
/usr/lib/jvm/java-1.5.0-su n-1.5.0.10 /jre/lib/e xt
10:08:53,100 DEBUG [ServerInfo] sun.boot.class.path:
/usr/local/jboss/lib/endor sed/serial izer.jar:/ usr/local/ jboss/lib/ endorsed/x alan.jar:/ usr/local/ jboss/lib/ endorsed/x ercesImpl. jar:/usr/l ib/jvm/jav a-1.5.0-su n-1.5.0.10 /jre/lib/r t.jar:/usr /lib/jvm/j ava-1.5.0- sun-1.5.0. 10/jre/lib /i18n.jar: /usr/lib/j vm/java-1. 5.0-sun-1. 5.0.10/jre /lib/sunrs asign.jar: /usr/lib/j vm/java-1. 5.0-sun-1. 5.0.10/jre /lib/jsse. jar:/usr/l ib/jvm/jav a-1.5.0-su n-1.5.0.10 /jre/lib/j ce.jar:/us r/lib/jvm/ java-1.5.0 -sun-1.5.0 .10/jre/li b/charsets .jar:/usr/ lib/jvm/ja va-1.5.0-s un-1.5.0.1 0/jre/clas ses
10:08:53,096 INFO [ServerInfo] Java version: 1.5.0_10,Sun Microsystems Inc.
10:08:53,096 INFO [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_10-b03,Sun Microsystems Inc.
10:08:53,096 INFO [ServerInfo] OS-System: Linux 2.6.18-3-k7,i386
10:08:53,100 DEBUG [ServerInfo] java.home:
/usr/lib/jvm/java-1.5.0-su
10:08:53,100 DEBUG [ServerInfo] java.specification.vendor:
Microsystems Inc.
10:08:53,100 DEBUG [ServerInfo] user.language: en
10:08:53,100 DEBUG [ServerInfo] java.vm.info: mixed mode
10:08:53,100 DEBUG [ServerInfo] java.version: 1.5.0_10
10:08:53,100 DEBUG [ServerInfo] java.ext.dirs:
/usr/lib/jvm/java-1.5.0-su
10:08:53,100 DEBUG [ServerInfo] sun.boot.class.path:
/usr/local/jboss/lib/endor
ASKER
The following beanshell script worked fine on the server, using the same JRE, proving that listAllBuckets works OK with the server's JRE, when not in JBoss. My guess is that JBoss loads something that puts the spanner in the works. I wonder how to work around this??
#!/usr/lib/jvm/java-1.5.0-sun/jre/bin/java bsh.Interpreter
/*
These are the .jars in the WEB-INF/lib directory:
bcprov-jdk15-136.jar commons-logging-1.1.1.jar junit-3.8.1.jar
lucene-lucli-2.3.1.jar tar-2.5.jar commons-codec-1.3.jar
jets3t-0.6.1.jar log4j-1.2.14.jar spring-2.0.5.jar
typica-1.3.jar commons-httpclient-3.1.jar jline-0.9.91.jar
lucene-core-2.3.1.jar tagsoup-1.1.3.jar
*/
// Add .jars from the deployed .war
String webLib = "/usr/share/java/jboss-4.2.2.GA/server/default/tmp/deploy/tmpxxxxxxx-exp.war/WEB-INF/lib/";
// Minimum set of .jars required for the jets3t test
addClassPath(webLib+"jets3t-0.6.1.jar");
addClassPath(webLib+"commons-logging-1.1.1.jar");
addClassPath(webLib+"commons-httpclient-3.1.jar");
addClassPath(webLib+"commons-codec-1.3.jar");
print("BeanShell test");
import org.jets3t.service.security.AWSCredentials;
import org.jets3t.service.S3Service;
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.model.S3Bucket;
//import org.jets3t.service.model.S3Object;
import org.jets3t.service.S3ServiceException;
/* S3 service */
S3Service getS3Service() throws S3ServiceException {
String awsAccessKey = "xxxxxxxxxxxx";
String awsSecretKey = "xxxxxxxxxxxx";
AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
return new RestS3Service(awsCredentials);
}
// Amazon S3 service
S3Service s3Service = getS3Service();
String bucketName = "lucy-services";
boolean gotBucket = false;
S3Bucket[] buckets = s3Service.listAllBuckets();
print("Found "+buckets.length+" buckets in S3");
S3Bucket lucyBucket = null;
for (S3Bucket bucket : buckets) {
print("S3 bucket: "+bucket.getName());
if (bucket.getName().equals(bucketName)) {
gotBucket = true;
lucyBucket = bucket;
}
}
print(gotBucket?"Bucket located OK":"Bucket not found :-(");
ASKER
It looks like JBoss isn't loading javax.crypto.Mac, itself.
The test in the snippet gets...
Mac: javax.crypto.Mac
Provider: com.sun.crypto.provider.Su nJCE - SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
Algorithm: HmacSHA1
...from the JRE, but putting the equivalent code into the web app gets:
2008-08-15 07:10:24,475 ERROR [STDERR] Exception in thread "Timer-13"
2008-08-15 07:10:24,475 ERROR [STDERR] java.lang.NoClassDefFoundE rror
2008-08-15 07:10:24,476 ERROR [STDERR] at javax.crypto.Mac.getInstan ce(DashoA1 2275)
(in JBoss only - it is fine with Jetty).
I can confirm that jce.jar is in the JRE lib directory, but unless my understanding of the error message it wrong, the class is somehow not on the classpath??
The test in the snippet gets...
Mac: javax.crypto.Mac
Provider: com.sun.crypto.provider.Su
Algorithm: HmacSHA1
...from the JRE, but putting the equivalent code into the web app gets:
2008-08-15 07:10:24,475 ERROR [STDERR] Exception in thread "Timer-13"
2008-08-15 07:10:24,475 ERROR [STDERR] java.lang.NoClassDefFoundE
2008-08-15 07:10:24,476 ERROR [STDERR] at javax.crypto.Mac.getInstan
(in JBoss only - it is fine with Jetty).
I can confirm that jce.jar is in the JRE lib directory, but unless my understanding of the error message it wrong, the class is somehow not on the classpath??
#!/usr/lib/jvm/java-1.5.0-sun/jre/bin/java bsh.Interpreter
import javax.crypto.Mac;
import java.security.Provider;
try {
Mac mac = Mac.getInstance("HmacSHA1");
if (mac == null) {
print("No Mac found");
exit();
}
Provider provider = mac.getProvider();
print("Mac: "+mac.getClass().getName());
print("Provider: "+provider.getClass().getName()+" - "+provider.getInfo());
print("Algorithm: "+mac.getAlgorithm());
exit();
}
catch (Exception e) {
e.printStackTrace();
}
ASKER
The problem appears to have been the JBoss class loader. I appear to have fixed it, by following the advice at http://jaitechwriteups.blogspot.com/, using an isolated class loader for the web application, by setting up jboss-web.xml as indicated in that blog.
ASKER
Thanks!
ASKER