I've been building an application in Eclipse which extracts data from salesforce and using an imported CSV file, updates and inserts records. It works fine from within Eclipse and I'm happy it's ready for deployment, but I cannot get the application working if I try and run it from cmd or double click the Jar. I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: uploader/jar
Caused by: java.lang.ClassNotFoundException: uploader.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: uploader.jar. Program will exit.
I've been all over google and tried every solution out there, but can't find why it won't work. Here's the steps I'm using to build the jar and run it, please if anyone can show me where I'm going wrong, I'd be delighted! I'm not a java programmer...
The project is called uploader as is the package, by the way
Right click on project and click Export. Choose "Jar file" and
Next.
Select my project as the resource and ensure .classpath and .project
files are selected. Choose to Export generated class files and
resources, to Compress the contents of the JAR file, and choose the
location for the Jar file to go, then hit Next.
Choose to Export class files with compile errors, and warnings.
Choose to Save the description of this JAR in the workspace, and
give the location as /uploader/jardesc.jardesc. Hit Next.
Choose to Generate the manifest file, Save the manifest in the
workspace and Use the saved manifest in the generated JAR
description file.
Point the Main Class to the correct place by clicking Browse and
choosing the only option that I'm given, which is uploader.Main,
then click Finish.
If I now open the manifest file, I see the following:
Manifest-Version: 1.0
Main-Class: uploader.Main
So that looks correct to me.
However, if I open a command prompt, cd to the directory containing the jar file then say java uploader.jar, that's when I get the error above.
Can anyone see anything that looks wrong? I can't get past this point!
If I run with java -jar uploader.jar, I get this error instead:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sforce/ws/ConnectionException
Caused by: java.lang.ClassNotFoundException: com.sforce.ws.ConnectionException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: uploader.Main. Program will exit.
Perhaps that can help pinpoint the problem?
*EDIT*
I've edited the manifest.mf file to this, but I'm still getting the error:
Manifest-Version: 1.0
Main-Class: uploader.Main
Class-Path: lib/enterprise.jar lib/wsc-22.jar
The problem seems to be a missing classpath setting, i.e. a definition of the classes and libraries that are needed in addtion. In your case it seems like at least some salesforce jar has to be added to the classpath.
Either put the classpath into the manifest file or add it at the command line: java -cp <classpath here> -jar uploader.jar
Related
I referenced one external library (Opencsv) in my project.
I added the Manifest file into the 'src' folder as:
Manifest-Version: 1.0
Main-Class: DataClean.DataPreprocess
Class-path: jars/opencsv.jar
The 'jars' is a folder contains the opencsv jar file in 'src' folder.
The complied main class is in 'DataClean' folder in 'src'.
When I create the jar, I use:
jar cfm PromoPrice_CN.jar Manifest.txt *
This command was run within 'src' folder.
Then, the JAR I created can only run within this 'src' directory. Otherwise, it gives the exceptions:
Exception in thread "main" java.lang.NoClassDefFoundError: com/opencsv/CSVReader
at DataClean.DataPreprocess.dataClean(DataPreprocess.java:154)
at DataClean.DataPreprocess.main(DataPreprocess.java:229)
Caused by: java.lang.ClassNotFoundException: com.opencsv.CSVReader
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
The command I used to run the jar is:
java -jar C:\...\src\PromoPrice_CN.jar X Y Z
X, Y and Z are three input parameter for the jar.
Please help where did I do wrong?
FYI, the creation of the JAR has to be in command line for other reasons.
Thx
I am using IntelliJ to create a variant of the Java WorldWind application. When I build the JAR artifact in IntelliJ I can see my DLLs and SOs in the top-level directory of the JAR. However, when I try to execute it, it complains it can't see these libraries that are inside the JAR (tried both Windows and Linux, thus being why I include SOs and DLLs).
What do I need to do to get it to see these libraries?
This is my first time creating an executable JAR, so sorry for the vagueness, I'm not quite sure what information is important. Please ask me any questions necessary to better understand this problem, and I will answer them.
Edit:
Catched FileNotFoundException: D:\code\Animator\animator\out\artifacts\Animator_jar\Animator-natives-windows-i586.jar (The system cannot find the file specified),
while addNativeJarLibsImpl(
classFromJavaJar class com.jogamp.common.os.Platform,
classJarURI jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar!/com/jogamp/common/os/Platform.class,
nativeJarBaseName Animator-natives-windows-i586.jar):
[ file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator.jar ->
file:/D:/code/Animator/animator/out/artifacts/Animator_jar/ ] +
Animator-natives-windows-i586.jar ->
slim: jar:file:/D:/code/Animator/animator/out/artifacts/Animator_jar/Animator-natives-windows-i586.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: D:\code\Animator\animator\out\artifacts\Animator_jar\gluegen-rt.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:551)
at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64)
at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:96)
at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:414)
at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:388)
at com.jogamp.common.os.Platform$1.run(Platform.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:179)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
at au.gov.ga.worldwind.animator.application.AnimatorConfiguration.<clinit>(AnimatorConfiguration.java:46)
at au.gov.ga.worldwind.animator.application.Animator.<clinit>(Animator.java:205)
As far as the structure of the JAR, I don't know how to show other than a screenshot of the JAR in 7-Zip:
In the image we can see that the name of the jar is: Animator.jar, but intelliJ is searching for: Animator-natives-windows-i586.jar. You must go to Module Settings - Artifacts and change the OutputDirectory to: D:\code\Animator\animator\out\artifacts\Animator_jar
Then check the name of the artifact to match the path and the name of the file.
The image added by me is an example.
I am trying to run bat file which should start my restCRUD server written in java. Project contains only one main method so my bath file looks like this:
java -jar TaxAppWebserver.jar
pause
The problem is that when I run bat file I get java.lang.NoClassDefFoundError.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Persistence
at facade.FacadeLogic.<init>(FacadeLogic.java:17)
at restCRUD.HandlerLogger.<init>(HandlerLogger.java:14)
at restCRUD.RestFileServer.run(RestFileServer.java:22)
at restCRUD.RestFileServer.main(RestFileServer.java:36)
Caused by: java.lang.ClassNotFoundException: javax.persistence.Persistence
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Line 17 from the FacadeLogic.java:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("TaxAppWebserverPU");
Can anyone give me a clue of what is wrong?
Rebuild your jar file with the missing jar added to the classpath in the MANIFEST.MF file. IDE's such as Eclipse can add these automatically when creating executable jar files
Class-Path: javax.persistence.jar
I solved the problem by creating lib folder in the project directory and copying all the external libraries to this folder. Also, I had to change my bat file for
java -cp TaxAppWebserver.jar restCRUD.RestFileServer
so that it knows where the main method is.
I have project called test in Eclipse which I want to export into Runnable JAR file. During the process of exporting the project, when I choose as a location of JAR file the subfolder of test folder in file system, such as C:/.../test/App.jar, it will work. However, when I want to put it for example on my desktop, it will run but in a very limited look (some GUI components missing) and it throws a lot of exceptions saying something like that:
at java.awt.EventDispatchThread.run(Unknown Source) xception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Could not initialize class com.sun.opengl.impl.windows.WindowsGLDrawableFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at javax.media.opengl.GLDrawableFactory.getFactory(GLDrawableFactory.java}
What can be the problem? I assume it is not good that I have to specify my JAR file concretely into one folder in file system, it would become unuseful for any other potentional user.
Looks like the jar needs other jars to execute. In this case you would have to set the classpath before you execute the jar
This might help you with your problem.
I have tried to create Jar file using Command Line.
My Manifest file:
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class:Home
My Files and Location of that files:
Location : D:\Application
Files :
images
add.png
home.png
minus.png
Database.java
Home.java
UiDesign.java
Database.class
Home.class// This is my main class
UiDesign.class
Manifest.txt
mysql-connector-java-5.1.15-bin.jar
To create jar file i tried:
D:\Application>jar cmf Manifest.txt MyApp.jar *.class mysql-connector-java-5.1.15-bin.jar images
But the jar file is created. If i click that jar file, Error message shows like below,
Failed to Load Main-Class manifest attribute from
D:\Application\MyApp.jar
Thank for all....My problem solved by adding new line in Manifest File....Thank you all...
But now i have another problem.....
D:\JavaApplication-13-8-2011\Application>jar cfm MyApp.jar Manifest.txt *.class
mysql-connector-java-5.1.15-bin.jar images
D:\JavaApplication-13-8-2011\Application>java -jar MyApp.jar
Connect to MySQl
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Database.getDBConnection(Database.java:14)
at UiDesign.<init>(UiDesign.java:58)
at Home.main(Home.java:6)
java.lang.NullPointerException
at Database.getBrand(Database.java:31)
at UiDesign.<init>(UiDesign.java:59)
at Home.main(Home.java:6)
Exception in thread "main" java.lang.NullPointerException
at UiDesign.<init>(UiDesign.java:64)
at Home.main(Home.java:6)
D:\JavaApplication-13-8-2011\Application>
I think this problem occurs due to to class path not set to mysql-connector....I have added this jar file in my Application.....How to setclass path and run my Application jar file successfully.....
please help me....
Thank you...I cleared..this problem also...As Trisstan said, I added classpath in Manifest file...Now My Application Jar file Run Succesfully.....
Thank You all for your Quick Response......
Add a newline at the end of your manifest file.
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
From: http://download.oracle.com/javase/tutorial/deployment/jar/appman.html
It may be an error about classpath, because your jar depends on mysql-connector-java-5.1.15-bin.jar
make sure there is a carriage return in your manifest file and I am also guessing your jar file name should precede the manifest file as your option says cfm.
Failed to Load Main-Class manifest attribute from D:\Application\MyApp.jar
From the error it looks like it thinks that the jar file is your manifest file. That should be the problem.
update the argument or change the option parameter to mcf I guess..
For your second problem:
Your jar probably contains a copy of the mysql jar. That does not work because jars are supposed to contain classes. The simplest way to fix this is to indicate in your manifest that your code depends on the mysql jar. Basically add the following:
Class-Path: mysql-connector-java-5.1.15-bin.jar
In your jar creation command, do not include the mysql jar. Finally, make sure that your jar and the mysql one are distributed together (in the same directory).
If you really want a single jar, extract the mysql jar and include its contents in the jar you are going to distribute.