Auf dieser Website werden Cookies gesetzt, die für den sicheren Betrieb technisch erforderlich sind. Siehe: Datenschutz

Java: Option -jar ignores classpath

by Bernd,
assono GmbH, Standort Hamburg,


java_logo.gif This one costs me some headaches. wink.gif To prevent others from suffering here are the details.

Let's start with an explanation of the option -jar calling java.exe. If in a project there are several classes needed, those classes could be packaged together with the ZIP file format. Normally the resulting file gets the extension JAR. To let the Java interpreter know which class to execute this JAR file contains a text file called Manifest with the main class specified. So with
java.exe -jar MyProject.jar
Java searches for the Manifest to execute the specified main class.


In Notes version prior to Notes 8 every time I couldn't realize a customer request with the built-in design elements I use Java. Normally I package the classes in a JAR file and put in the directory [Notes program path]\jvm\lib\ext. (In our framework we have a mechanism for deploying it to the users machine on opening a Notes database.) If the JAR file is in this directory I don't have to worry about the class path because this directory is automatically added to the class path.

At a customer site the user could not write to the directory [Notes program path]\jvm\lib\ext. So we had to store the JAR file in another directory. To start the Java application as a stand alone application instead of as an agent we called [Notes program path]\jvm\bin\java.exe directly. Which led to the nice error message
Exception in thread "main" java.lang.NoClassDefFoundError: de/assono/demo/AnotherPackage
So the Java interpreter could not found a class from another JAR file within the same directory.

Our first guess was that we missed to specify the class path. So we changed the call to
java.exe -jar -classpath ".;c:\temp\MyProject.jar; c:\temp\AnotherPackage.jar;" MyProject.jar
But that didn't worked neither. I tried some different sequences of the options but nothing worked.

After some search in Google I found the problem in the Java documentation.

-jar
...
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

The solution was quite simple. Just
add the line

Class-Path: AnotherPackage.jar

to the Manifest to specify the class
path. The details for the writing a Manifest file could be found in a Sun Tutorial.

Technical article JavaScript Java Development

You have questions about this article? Contact us: blog@assono.de

Sie wollen eine individuelle Beratung oder einen Workshop? Read more

More interesting entries

Any questions? Contact us.

If you want to know more about our offers, you can contact us at any time. There are several ways to contact us for a non-binding first consultation.

assono GmbH

Location Kiel (headquarters)
assono GmbH
Lise-Meitner-Straße 1–7
24223 Schwentinental

Location Hamburg
assono GmbH
Bornkampsweg 58
22761 Hamburg

Phone numbers:
Human resources department: +49 4307 900 407
Marketing department: +49 4307 900 402

E-Mail adresses:
contact@assono.de
bewerbung@assono.de