Problem with jar files

I'm having running a program in my jar. It seems to be a problem with my class path as when I run my jar with this Command line

java -jar ClientTest.jar -h

I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger

at com.company.sub.prototype.mq.services.GenericMQ.<clinit>(GenericMQ.java:23)

at com.company.sub.prototype.mq.services.HeartbeatMessage.<init>(HeartbeatMessage.java:19)

at com.company.sub.prototype.testharness.clientTestHarness.sendHeartbeatMessage(clientTestHarness.java:1263)

at com.company.sub.prototype.testharness.clientTestHarness.runTest(clientTestHarness.java:1195)

at com.company.sub.prototype.testharness.clientTestHarness.main(clientTestHarness.java:1164)

But I know that the log4j-1.2.jar is on my classpath, because if I unpack the jar and run it ,with the same class path, with the following command

java com.company.sub.prototype.testharness.clientTestHarness -h

It works fine. So why wont it run from the jar?

Thanks

Torb

[1109 byte] By [stonest] at [2007-9-30 4:54:41]
# 1

Hi,

You need to specify the classpath in manifest file of your jar.

The content of your manifest.mf file would be for example where log4j-1.2.jar is in the same directory as the jar file:

Manifest-Version: 1.0

Created-By: 1.4.0 (Sun Microsystems Inc.)

Main-Class: myclass

Class-Path: log4j-1.2.jar

-Amol

ad136217 at 2007-7-1 15:26:13 > top of Java-index,Administration Tools,Sun Connection...
# 2

> I'm having running a program in my jar. It seems to

> be a problem with my class path as when I run my jar

> with this Command line

>

> java -jar ClientTest.jar -h

"java -jar" explicitly ignores CLASSPATH. You have to specify ClientTest.jar's dependencies in its Manifest file, and make those jars available in the same directory as ClientTest.jar. Or specify absolute paths to the dependent jar files in the Manifest file (a distasteful idea..)

shankar.unni at 2007-7-1 15:26:13 > top of Java-index,Administration Tools,Sun Connection...
# 3

Thanks Shankar,

I have now got it working. Is there a way that you can put an Enviroment variable in the manifest file?

i.e.

Class-Path: $MY_CLASS_PATH/log4j-.1.2.jar

That would be mutch nicer than having to make sure that all the jars are in the dir I'm running from.

Torb

stonest at 2007-7-1 15:26:13 > top of Java-index,Administration Tools,Sun Connection...
# 4
is there a way to get the executible jar to reference jars directly inside of the jar? rather than the "working directory"
Zach16 at 2007-7-1 15:26:13 > top of Java-index,Administration Tools,Sun Connection...