0

I'm trying run an jar file from command prompt. I am continually get the above error for all the below combinations i tried.

java -jar Mater.jar
java -cp ".:log4j-1.2.16.jar" -jar Mater.jar
java -cp log4j-1.2.16.jar -jar Mater.jar

I extracted log4j-1.2.16.jar to see if Layout was in the jar I'm referencing and it is there.

I have created the jar by using eclipse IDE "Export jar Option" and here is my manifest file.

Manifest-Version: 1.0
Main-Class: TestController

Class-Path: apache-mime4j-0.6.jar bsh-1.3.0.jar cglib-nodep-2.1_3.jar commons-beanutils-1.8.0.jar commons-codec-1.6.jar 

Class-Path: commons-collections-3.2.1.jar commons-exec-1.1.jar commons-io-2.0.1.jar commons-jxpath-1.3.jar commons-logging-1.1.1.jar 

Class-Path: cssparser-0.9.5.jar derbyclient.jar dom4j-1.1.jar eclipselink-2.0.0.jar flash-selenium.jar guava-12.0.jar hamcrest-core-1.1.jar 

Class-Path: htmlunit-2.9.jar htmlunit-core-js-2.9.jar httpclient-4.1.3.jar httpcore-4.1.3.jar httpmime-4.1.3.jar ini4j-0.5.2.jar 

Class-Path: javax.persistence-2.0.0.jar jcommander-1.13.jar jna-3.4.0.jar jna-platform-3.4.0.jar 

Class-Path: json-20080701.jar junit-dep-4.10.jar logging-selenium-1.2.jar mail.jar mysql-connector-java-5.0.7-bin(2).jar 

Class-Path: nekohtml-1.9.15.jar netty-3.2.7.Final.jar operadriver-0.14.jar 
poi-3.6-20091214.jar poi-ooxml-3.6-20091214.jar poi-ooxml-schemas-3.6-20091214.jar 

Class-Path: protobuf-java-2.4.1.jar sac-1.3.jar saxon-8.7.jar SaxonLiaison.jar selenium-java-2.25.0.jar selenium-java-2.25.0-srcs.jar 

Class-Path: selenium-java-client-driver.jar selenium-java-client-driver-sources.jar selenium-java-client-driver-tests.jar 

Class-Path: selenium-java-client-driver-test-sources.jar selenium-server.jar selenium-server-coreless.jar 

Class-Path: selenium-server-sources.jar serializer-2.7.1.jar testng.jar testng-6.0.1-nobsh-noguice.jar testng-xslt-maven-plugin-test-0.0.jar 

Class-Path: validation-api-1.0.0.GA.jar webbit-0.4.8-SNAPSHOT.jar xalan-2.7.1.jar xercesImpl-2.9.1.jar xml-apis-1.3.04.jar xmlbeans-2.3.0.jar log4j-1.2.8.jar

I have cross checked if the classpath is set correctly in the jar using

jar tf Mater.jar

and it is displaying all the files inside jar on the command prompt correctly..

Can anyone shed some light on this?

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
user1660325
  • 747
  • 4
  • 20
  • 35
  • I'm not sure but IIRC using `-jar` option ignores `-cp`. You probably need to set your classpath in jar's manifest file. – Adam Dyga Oct 19 '12 at 14:44
  • @Adam i have set the classpath in manifest file as i mentioned above and more over when i view the jar contents on command prompt all the jars,classfiles e.t.c are displayed correctly... – user1660325 Oct 19 '12 at 14:47
  • are you sure all the referenced jars are in the same directory as Mater.jar? – Adam Dyga Oct 19 '12 at 14:53
  • yes all are in the lib folder of project Mater – user1660325 Oct 19 '12 at 15:12
  • the paths in manifest are relative to the main jar (Mater.jar), so you need to change it so that they have correct relative path (eg. Class-Path: lib/protobuf-java-2.4.1.jar) – Adam Dyga Oct 22 '12 at 08:15

1 Answers1

0

I had a similar problem, with the same NoClassDefFoundError, in here : NoClassDefFoundError after updating to Java 7

I can't explain why, but the only working solution I found was to export as a runnable JAR with Eclipse

Community
  • 1
  • 1
Nils De Winter
  • 1,370
  • 3
  • 11
  • 20