NoClassDefFoundError

344 views
Skip to first unread message

rob

unread,
Aug 13, 2008, 12:57:55 PM8/13/08
to JetS3t Users
I've posted a question on ExpertsExchange here:
http://www.experts-exchange.com/Programming/Languages/Java/Q_23645220.html
but this may me a more appropriate place to ask.

I've got a web application up and running using Jetty in Maven2. The
application works with Amazon SQS and S3, using JetS3t for S3. It
works fine in Jetty on my Windows test system, using Java 6, but
throws the following on my server, which uses JBoss on Linux on Java
5:

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

My WEB-INF/lib contains:

commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
jets3t-0.6.0.jar
jline-0.9.91.jar
junit-3.8.1.jar
log4j-1.2.14.jar
lucene-core-2.3.1.jar
lucene-lucli-2.3.1.jar
spring-2.0.5.jar
tagsoup-1.1.3.jar
tar-2.5.jar
typica-1.3.jar

Any ideas what .jar I need?

James Murty

unread,
Aug 13, 2008, 5:09:01 PM8/13/08
to jets3t...@googlegroups.com
Make sure you are using Sun's version of Java on the Linux machine,
and not an open source alternative like GNU Java. The open source
alternatives tend to lack the cryptographic libraries required by
JetS3t.

---
http://www.jamesmurty.com

Rob Staveley (Tom)

unread,
Aug 13, 2008, 6:15:30 PM8/13/08
to jets3t...@googlegroups.com
It is Sun. Could the libs loaded for JBoss be upsetting the crypto?

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-sun-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-sun-1.5.0.10/jre/lib/ext

10:08:53,100 DEBUG [ServerInfo] sun.boot.class.path:
/usr/local/jboss/lib/endorsed/serializer.jar:/usr/local/jboss/lib/endorsed/x
alan.jar:/usr/local/jboss/lib/endorsed/xercesImpl.jar:/usr/lib/jvm/java-1.5.
0-sun-1.5.0.10/jre/lib/rt.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/i
18n.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/sunrsasign.jar:/usr/lib
/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/jsse.jar:/usr/lib/jvm/java-1.5.0-sun-1.
5.0.10/jre/lib/jce.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/charsets
.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/classes

# ls /usr/share/java/jboss-4.2.2.GA/server/default/lib
activation.jar hibernate-entitymanager.jar
jboss-monitoring.jar jbossws-spi.jar
antlr.jar hibernate3.jar
jboss-remoting-int.jar jmx-adaptor-plugin.jar
autonumber-plugin.jar hsqldb-plugin.jar jboss-remoting.jar
jnpserver.jar
bcel.jar hsqldb.jar jboss-saaj.jar
joesnmp.jar
bindingservice-plugin.jar javassist.jar
jboss-serialization.jar jpl-pattern.jar
bsf.jar jaxen.jar jboss-srp.jar
jpl-util.jar
bsh-deployer.jar jboss-cache-jdk50.jar
jboss-transaction.jar jsp-api.jar
bsh.jar jboss-common-jdbc-wrapper.jar jboss-vfs.jar
log4j-snmp-appender.jar
cglib.jar jboss-ejb3x.jar jboss.jar
log4j.jar
commons-codec.jar jboss-hibernate.jar
jbossjta-integration.jar mail-plugin.jar
commons-collections.jar jboss-j2ee.jar jbossjta.jar
mail.jar
commons-httpclient.jar jboss-jaxrpc.jar jbossmq.jar
properties-plugin.jar
commons-logging.jar jboss-jaxws.jar jbosssx.jar
quartz.jar
dom4j.jar jboss-jca.jar jbossts-common.jar
scheduler-plugin-example.jar
ejb3-persistence.jar jboss-jsr77.jar jbossws-common.jar
scheduler-plugin.jar
el-api.jar jboss-jsr88.jar
jbossws-framework.jar servlet-api.jar
hibernate-annotations.jar jboss-management.jar
jbossws-jboss42.jar xmlentitymgr.jar

James Murty

unread,
Aug 13, 2008, 6:44:27 PM8/13/08
to JetS3t Users
Hmm, I guess the Jboss libraries might cause a conflict. From the
class path you provided it looks like all the required Java libraries
are there.

Could you try running a small test JetS3t program, or the Synchronize
application, from outside JBoss? If this test works, we can be sure
it's something to do with the app server rather than the JVM or system.

I'm not sure what would cause a conflict on JBoss, but we should be
able to work through it and figure it out.

James

On 14/08/2008, at 8:15 AM, "Rob Staveley \(Tom\)"

Rob Staveley (Tom)

unread,
Aug 14, 2008, 12:12:14 PM8/14/08
to jets3t...@googlegroups.com
The following beanshell script worked fine on the server, proving that
listAllBuckets works OK with the server's JRE, when not in JBoss:

--------8<--------
#!/usr/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 current working directory (from the deployed .war
String webLib =
"/usr/share/java/jboss-4.2.2.GA/server/default/tmp/deploy/tmp20676xxxxxxx-ex
p.war/WEB-INF/lib/";

// Test for jets3t
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");

System.out.println("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;

/*
reference to 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 :-(");
--------8<--------

Rob Staveley (Tom)

unread,
Aug 14, 2008, 12:29:59 PM8/14/08
to jets3t...@googlegroups.com
FYI... here are the JBoss jars:

root@seseiaa4:/usr/share/java/jboss-4.2.2.GA/server/default/lib# echo `ls`
activation.jar antlr.jar autonumber-plugin.jar bcel.jar
bindingservice-plugin.jar bsf.jar bsh-deployer.jar bsh.jar cglib.jar
commons-codec.jar commons-collections.jar commons-httpclient.jar
commons-logging.jar dom4j.jar ejb3-persistence.jar el-api.jar
hibernate-annotations.jar hibernate-entitymanager.jar hibernate3.jar
hsqldb-plugin.jar hsqldb.jar javassist.jar jaxen.jar jboss-cache-jdk50.jar
jboss-common-jdbc-wrapper.jar jboss-ejb3x.jar jboss-hibernate.jar
jboss-j2ee.jar jboss-jaxrpc.jar jboss-jaxws.jar jboss-jca.jar
jboss-jsr77.jar jboss-jsr88.jar jboss-management.jar jboss-monitoring.jar
jboss-remoting-int.jar jboss-remoting.jar jboss-saaj.jar
jboss-serialization.jar jboss-srp.jar jboss-transaction.jar jboss-vfs.jar
jboss.jar jbossjta-integration.jar jbossjta.jar jbossmq.jar jbosssx.jar
jbossts-common.jar jbossws-common.jar jbossws-framework.jar
jbossws-jboss42.jar jbossws-spi.jar jmx-adaptor-plugin.jar jnpserver.jar
joesnmp.jar jpl-pattern.jar jpl-util.jar jsp-api.jar log4j-snmp-appender.jar
log4j.jar mail-plugin.jar mail.jar properties-plugin.jar quartz.jar
scheduler-plugin-example.jar scheduler-plugin.jar servlet-api.jar

James Murty

unread,
Aug 14, 2008, 5:46:57 PM8/14/08
to jets3t...@googlegroups.com
Another possibility beside the jar files is the JBoss server's
security configuration files. There should be a java.security file
that lists your security providers, and it should contain some lines
like this to load Sun's crypto libraries:

security.provider.1=sun.security.provider.Sun

policy.url.1=file:${java.home}/lib/security/java.policy

If the security settings aren't quite right, the server may be unable
to load some crypto libraries even when the right jar files are
present.

---
http://www.jamesmurty.com

Rob Staveley (Tom)

unread,
Aug 15, 2008, 3:26:03 AM8/15/08
to jets3t...@googlegroups.com
I can't see any evidence that JBoss overrides the JRE's java.security, but I
confess that other than looking for java.security files, I'm not sure where
to look.

However, it looks to me that the class that can't be loaded in JBoss is
javax.crypto.Mac itself.

Here's what I've found...

If I manually get an instance of a Mac for "HmaxSHA1", with the following
BeanShell script....

--------8<--------
#!/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();
}
--------8<--------

...I see:

Mac: javax.crypto.Mac
Provider: com.sun.crypto.provider.SunJCE - SunJCE Provider (implements RSA,
DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
Algorithm: HmacSHA1

If I run the equivalent in my web application, I see the same in Jetty,
which has been behaving nicely throughout.

In JBoss, however, I see...

008-08-15 07:10:24,475 ERROR [STDERR] Exception in thread "Timer-13"
2008-08-15 07:10:24,475 ERROR [STDERR] java.lang.NoClassDefFoundError
2008-08-15 07:10:24,476 ERROR [STDERR] at
javax.crypto.Mac.getInstance(DashoA12275)

This suggests that javax.crypto.Mac itself is not on the classpath.

Looking at http://javacio.us/subscribers/classes/javax.crypto.Mac tells me
that I should expect to load javax.crypto.Mac from J2SE JRE's jce.jar, which
I can confirm is there on the server in the right J2SE JRE lib directory. In
the JBoss boot.log, I see it on the sun.boot.class.path:

10:08:53,100 DEBUG [ServerInfo] sun.boot.class.path:

/usr/local/jboss/lib/endorsed/serializer.jar:/usr/local/jboss/lib/endorsed/x
alan.jar:/usr/local/jboss/lib/endorsed/xercesImpl.jar:/usr/lib/jvm/java-1.5.
0-sun-1.5.0.10/jre/lib/rt.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/i
18n.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/sunrsasign.jar:/usr/lib
/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/jsse.jar:/usr/lib/jvm/java-1.5.0-sun-1.
5.0.10/jre/lib/jce.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/lib/charsets
.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.10/jre/classes

You can apparently also get it from BouncyCastle.

If I add the BounceCastle .jar from
http://repo1.maven.org/maven2/bouncycastle/bouncycastle-jce-jdk13/112/ to my
project, the code fails in Jetty as follows:

java.lang.ClassCastException: com.sun.crypto.provider.HmacSHA1 cannot be
cast to javax.crypto.MacSpi
at javax.crypto.Mac.getInstance(Mac.java:95)
at
com.xerox.amazonws.common.AWSConnection.encode(AWSConnection.java:145)
at
com.xerox.amazonws.common.AWSQueryConnection.makeRequest(AWSQueryConnection.
java:301)
at
com.xerox.amazonws.sqs2.QueueService.getOrCreateMessageQueue(QueueService.ja
va:122)

JBoss gets no further than the familiar NoClassDefFoundError link error, so
no change there. It still appears to be unable to load javax.crypto.Mac,
assuming that's what it means.

Rob Staveley (Tom)

unread,
Aug 15, 2008, 10:30:37 AM8/15/08
to jets3t...@googlegroups.com
This is a weird JBoss issue, but may impact on other jets3t users, so - for
the record - here's how I worked around this.

I followed the instructions at http://jaitechwriteups.blogspot.com/ and set
up a jboss-web.xml which gets JBoss to load classes in isolation in
deployment. I found that somehow or other this seems to get the JBoss
classloader to load javax.crypto.Mac. My uneducated guess is that JBoss's
super-efficient class-loading got its knickers in a twist and things are
simplified, when the application is not made to share classes. Or something
like that!

It would be good to know for real, because JBoss is important in my world.
Thanks for bearing with me, James; and thanks very much for the great
software!!

James Murty

unread,
Aug 17, 2008, 1:33:00 AM8/17/08
to jets3t...@googlegroups.com
Hi Rob,

I'm glad you found a fix, and thanks for sharing it here on the forum
-- it's sure to affect someone else sooner or later.

App servers often need to do odd things with class paths, especially
for libraries that are required by the server itself. I'm only
guessing, but this issue may be caused by the fact that JBoss uses the
Java security libraries itself while hiding them from deployed
applications, in the expectation that these apps will hook into JBoss'
resources rather than talking to the "outside world" directly. I've
had my share of problems with XML libraries in this kind of
situation...

I hope things will run more smoothly for you from now on.

Cheers,
James

---
http://www.jamesmurty.com


On Sat, Aug 16, 2008 at 12:30 AM, Rob Staveley (Tom)

Reply all
Reply to author
Forward
0 new messages