0

I am trying to run a jar file, which references some external JAR files that I am bundling up with the package. I am not able to download any dependency tools onto the system, so I am trying to do this using a manifest file.

The jar I am running is called attachmentUploader.jar, and in the same directory is a libraries folder containing the external jar files.

This is my MANIFEST.txt file:

Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: com.custom.test.postClient
Class-Path: attachmentLoader.jar libraries/java-json.jar libraries/org.apache.commons.httpclient_3.1.0.v20100508.jar libraries/org.apache.commons.logging_1.0.4.v3920100508.jar

Then I run this from the command line using:

java -jar "C:/Users/My Documents/attachmentUploader.jar"

but get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity 
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.methods.RequestEntity
    at ......

Could not find the main class: com.tririga.custom.test.Tririga_postClient. Program will exit

There's a stack trace in there as well but unfortunately I am not able to copy across - if this turns out to be absolutely necessary to solve the problem I will laboriously type it!

The error message seems strange to me as there seem to be two errors - not being able to find a class within the httpclient jar and not being able to find the main class. I have checked and these are both there in the locations I have stated.

Have I missed something simple? Are the relative paths correct?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MDalt
  • 1,681
  • 2
  • 24
  • 46

2 Answers2

0

Have you tried this:

Class-Path: . ./attachmentLoader.jar ./libraries/java-json.jar ./libraries/org.apache.commons.httpclient_3.1.0.v20100508.jar ./libraries/org.apache.commons.logging_1.0.4.v3920100508.jar
Sahid
  • 100
  • 1
  • 1
  • 11
  • 1
    According to the [documentation](http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html) you should be able to do it the way I've done it, no? I tried your way as well and still get exactly the same message. Is the first dot intentional? – MDalt Sep 15 '15 at 12:12
  • Ok. I think what you are saying is correct. Some more research tells me you are probably looking for this: (http://stackoverflow.com/questions/183292/classpath-including-jar-within-a-jar) – Sahid Sep 15 '15 at 12:29
  • My JAR files are not within the original JAR file though...I have included them in a folder in the same directory. I think I'm right in saying that means it should be included in the Classpath as I have done. Very strange. – MDalt Sep 15 '15 at 13:05
0

Specifying attachmentloader.jar in its own Class-path is meaningless.

user207421
  • 305,947
  • 44
  • 307
  • 483