function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ministe_2003ministe_2003 

"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

 

  1. Right click on project and click Export.  Choose "Jar file" and Next.
  2. 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.
  3. 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.
  4. Choose to Generate the manifest file, Save the manifest in the workspace and Use the saved manifest in the generated JAR description file.
  5. 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?

Best Answer chosen by Admin (Salesforce Developers) 
SebastianBraunSebastianBraun

Hi,

 

Try Export as "Runnable JAR file" instead of just "JAR file" and use: "Package required libraries into generated JAR"

 

Greetings

 

Sebastian

All Answers

SebastianBraunSebastianBraun

Hi,

 

Try Export as "Runnable JAR file" instead of just "JAR file" and use: "Package required libraries into generated JAR"

 

Greetings

 

Sebastian

This was selected as the best answer
ministe_2003ministe_2003

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