You need to sign in to do that
Don't have an account?
"Could not find the main class" error in my program
Hi all,
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. 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 seethe 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!
EDIT:
more information, if I run with java -jar uploader.jar, I get this error instead:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sforce/ws/Connect ionException 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?
Hi,
Try Export as "Runnable JAR file" instead of just "JAR file" and use: "Package required libraries into generated JAR"
Greetings
Sebastian
All Answers
Hi,
Try Export as "Runnable JAR file" instead of just "JAR file" and use: "Package required libraries into generated JAR"
Greetings
Sebastian
Hi thanks, I'd discovered the answer - for anyone else with similar issues there's a thread here:
http://stackoverflow.com/questions/9888239/could-not-find-the-main-class-in-java-salesforce-application
Regards
Steven