I try to make an exe file of a jar file. I get a error like this:
"classpath does not contain main classes"
This error is from the program Excelsior.
Your manifest file should be like-
Manifest-Version: 1.0
Created-By: 1.7.0_67 (Oracle Corporation)
Main-Class: MyMainClass
Class-Path: .
You must have missed "Main-Class" or "Class-Path" attribute.
You can manually add these entries by editing manifest file.
Also, if you are looking for other alternatives, this will help you-
How can I convert my Java program to an .exe file?
Related
I have jar file with manifest in it
Manifest-Version: 1.0
Build-Jdk: 1.7.0_67
Created-By: Apache Maven 3.2.3
Main-Class: com.company.main.Main
Archiver-Version: Plexus Archiver
And the jar has compile dependency to external library
compile 'org.apache.commons:commons-lang3:3.3.2'
So I want to execute it comandLine I wrote:
java -cp C:\commons-lang3-3.3.2.jar -jar myJar-1.0.0.jar
But
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
at ...
How to add this file on the class path?
PS. If I use the "bad way" and copy-paste commons-lang3-3.3.2.jar in the ...jre7\lib\ext folder. Everything is working.
If you're not using the -jar option then you need to specify the main class to run, as the manifest will not be interrogated:
java -cp C:\commons-lang3-3.3.2.jar;.\myJar-1.0.0.jar com.company.main.Main
The classpath (-cp) option is ignored if using the -jar option (in that case the manifest should reference any other required jars via its classpath directive).
"Bad Way"..? You should never include your jar files inside the java directories.. How do you expect the users of your application to use your jar when they are using the standard java..?
either you can use the command suggested by #tombola82 or you can include the commons-lang jar in your project itself so that you can refer it.
I want to reference a jar file in fixed location for use by multiple executable jars rather than include that jar in each of the executables. I have the following setup which works fine
commons-math3-3.6.1.jar exists in directory testgradle. TestGradle.jar contains the main method and exists in directory testgradle/build/libs
from testgradle/build/libs I run:
java -jar TestGradle.jar
And things work fine. The manifest in TestGradle.jar contains:
Manifest-Version: 1.0
Class-Path: ../../commons-math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg
But I want to address commons-math3-3.6.1.jar with an absolute path so that executable jars such as TestGradle.jar can use it from whichever directory they reside in. However, if I change TestGradle.jar manifest to include the full path:
Manifest-Version: 1.0
Class-Path: C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.ja
r
Main-Class: com.spgxyz.test.testg
Then the command:
java -jar TestGradle.jar
run from testgradle/build/libs produces:
Error: Could not find or load main class com.spgxyz.test.testg
Caused by: java.lang.ClassNotFoundException: com.spgxyz.test.testg
I tried various edits to the manifest to try to cure this such as:
Manifest-Version: 1.0
Class-Path: . C:\Users\Admin\workspace\TestGradle\commons-math3-3.6.1.
jar
Main-Class: com.spgxyz.test.testg
Manifest-Version: 1.0
Class-Path: TestGradle.jar C:\Users\Admin\workspace\TestGradle\commons
-math3-3.6.1.jar
Main-Class: com.spgxyz.test.testg
These both produce the same error. If someone could shed some light on what's going on here I'd be very grateful. Running on windows.
Class-Path attribute is interpreted as a list of URLs, so, to use an absolute path (represented with a URL here), it should start with schema and use forward slashes.
Try the following:
Class-Path: file:///C:/Users/Admin/workspace/TestGradle/commons-math3-3.6.1.jar
I've been struggling with this common error and just can't resolve it. This application is composed of multiple packages and runs fine within JCreator (at the moment I need to use this IDE rather than Eclipse).
My manifest file is here (there are 2 blank lines at the end):
Manifest-Version: 1.0
Created-By: 1.6.0_45 (Sun Microsystems Inc.)
Main-Class: C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main\DPMain
I wrote a bat file to create the jar:
jar -cvfm DPlus.jar C:\COMPILE\MyProjects\douwe\classes\MANIFEST.MF
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\library*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\command*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file\display*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\command*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\file\display*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\gui*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\gui*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\job*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\job*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\types*.class
C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\util*.class
When I try to execute with the command
C:\COMPILE\MyProjects\douwe\classes>java -jar DPlus.jar
I always get the error:
Error: Could not find or load main class C:\COMPILE\MyProjects\douwe\classes\dykstra\dplus\main\DPMain
Can anyone see what I'm doing wrong here?
Usually this error is due to MANIFEST.MF if the'res no application's entry point has been set.
Your manifest file should have this line of code
Main-Class: YourPackage.DPMain
Alternatively, you can do the following.
java -cp .;app.jar YourPackage.DPMain
In my implementation, there are something different from yours, you can refer:
(1) The folder(before compressed) structure
you need to add a META-INF folder and put your MANIFEST.MF in it
(2) The content in your MANIFEST.MF
I think your should use the package format instead of a folder tree format:
Manifest-Version: 1.0
Main-Class: com.loadtest.mgr.LoadTestStarter
A jar file I had created in the very past (xl-importer.jar) stopped loading. The MANIFEST.MF file is the following:
Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: class/Client
Although there is the Client class inside folder /class/ inside the .jar file, I always get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: class/Client (wrong name: Client)
However when I run java Client inside the /class/ folder, application runs fine.
Jar was created some years ago with a 32 bit compiler. My customer moved to Windows 2003 Server some time ago. Is that the reason? Jar file was loading before that.
In the java tutorials it specifies that Main-Class is specified with :
Main-Class: MyPackage.MyClass
So it could be that you need to replace the "/" with a "."
If the class is in a directory called "class" they need to be put in the class package. "class" is a keyword in java so you can't use it for a package name. If you change the folder name to somehting else, for instance "classes", and add a package statement to your java file, then reference the class using a "." rather than a "/" it should work. It did with mine anyway :) e.g.
Manifest:
Manifest-Version: 1.0
Created-By: 1.5.0 (Sun Microsystems Inc.)
Main-Class: classes.Client
Client.java:
package classes;
public class Client{
//do code...
}
this is what a newer Manifest looks like (java 6)
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: MyPackage.MyClass
My guess is that java 5 used a different protocol.
Try changing the main class as shown above.
I am getting following error while executing compiled jar file. I have re installed my java but my problem is not solved yet.
Failed to load Main-class Manifest Attribute from
D:\Tools\Lodable_Creation\dist\Lodable_Creation.jar
Currently by MANIFEST.MF file looks like.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0-b105 (Sun Microsystems Inc.)
Main-Class: main
X-COMMENT: Main-Class will be added automatically by build
I am using Netbeans 6.9.1 IDE.
Use a package for your class. Make sure your class looks something like this (notice the package and the public class):
package com.foo;
public class Main {
public static void main(String[] args) {
}
}
After which you can specify Main-Class as so:
Main-Class: com.foo.Main
As adarshr suggested, JVM is not able to find the class because it requires the fully-qualified name in the Main-Class attribute of Manifest file.
Actually, it is not really necessary to specify the main file. You can just give your JAR file as your classpath, and give the fully-qualified name of the class to run it using java.
Say your JAR is myJar.jar and the fully-qualified main file is com.user.Main. Then from the command line, go to the directory which has your JAR File and give :-
java -classpath myJar.jar com.user.Main
And this will run the Main class. You would also need to give the classes (or JARs) in the classpath which are used (imported) in your Main class.
See this link for the details.
I have encountered this error when I have developed projects with a JDK(1.7 in my case) and the installed JRE was an older version(1.6). Try to update your JRE or change the JDK used, if possible, to match your JRE version.