[java] Could not find the main class, program will exit

I made an executable jar with the command prompt in Windows 7 using the

jar cvfm MyJarName.jar manifest.txt *.class

which created the .jar file. But when I attempt to open it, I get a pop-up window that says

Could not find the main class: <ClassName>. Program will exit.

Yet, when I use

java -jar jarName.jar

in the command prompt, it works fine. What's the deal? I want to be able to just double-click it.

This question is related to java jar

The answer is


I had this problem when I "upgraded" to Windows 7, which is 64-bit. My go to Java JRE is a 64-bit JVM. I had a 32-bit JRE on my machine for my browser, so I set up a system variable:

JRE32=C:\Program Files\Java\jre7

When I run:

"%JRE32\bin\java" -version

I get:

java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)

Which is a 32-bit JVM. It would say "Java HotSpot(TM) 64-Bit" otherwise.

I edited the "squirrel-sql.bat" file, REMarking out line 4 and adding line 5 as follows:

(4) rem set "IZPACK_JAVA=%JAVA_HOME%"
(5) set IZPACK_JAVA=%JRE32%

And now everything works, fine and dandy.


Tweaking MB's answer for windows, will get rid of the console window:

start javaw -jar squirrel-sql.jar

  1. JAVA_HOME variable must be set, to point to the prog files/java/version???/bin
  2. open squirrel-sql.bat file with some text editor and see if the JAVA_HOME variable there is the same as the one in your enviroment variable
  3. change it if it doesn't match....and than run bat file again

Have you followed these instructions:

http://www.squirrelsql.org/#installation

If so, are you running the batch file or the shell script to run it?


I had the same issue with a different application (BI Publisher) because I installed a 32 bit version of this application on a 64 bit version of Windows.

Java Virtual Machine Launcher - could not find the main class

enter image description here

The solution for my case was to tell BI Publisher where to find the x86 version of JRE:

enter image description here


Check out doing this way (works on my machine):

let the file be x.java

  1. compile the file javac x.java
  2. jar cfe k.jar x x.class //k.jar is jar file
  3. java -jar k.jar

You can place .; in classpath in environmental variables to overcome this problem.


The .bat file does not seem to work.

Just double-click on:

squirrel-sql.jar

or type:

java -jar squirrel-sql.jar

in the command-line.


I got this issue in opening JMeter 4.0. I fixed as below.

I have JRE 7 installed in Program Files (x86) folder and JDK 8 installed in Program files folder. So I just uninstalled JRE7 from machine. I just kept latest version of JDK. It fixed the problem.


The classpath is the path that the system will follow when trying to find the classes that you're trying to run. In the batch file you're trying to execute it probably has a variable like CLASSPATH=blah;blah;etc or a java command that looks similar to

java -classpath "c:\directory\lib\squirrel-sql.jar" com.some.squirrel.package.file

If you can find or add that classpath setting, make sure that it includes a path to the squirrel-sql.jar and any other jar files that it may depend on separated by semicolons (or the root /lib directory that may be included with the installation).

Basically you just need to tell java where to find the class files that you're trying to execute. Wikipedia has a more indepth discussion about classpath and can offer you more insight. http://en.wikipedia.org/wiki/Classpath_(Java)


The Manifest 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.


Is Java installed on your computer? Is the path to its bin directory set properly (in other words if you type 'java' from the command line do you get back a list of instructions or do you get something like "java is not recognized as a .....")?

You could try try running squirrel-sql.jar from the command line (from the squirrel sql directory), using:

java -jar squirrel-sql.jar

If you are using JDK 1.6 or higher then you can override the manifest attribute via e flag of Jar tool. (Read - Setting an Entry Point with the JAR Tool):

Example:

package pack;

public class Test
{
  public static void main(String []args)  
   {
     System.out.println("Hello World");
    }
}

Compile and run Jar tool,

c:\>jar cfe app.jar pack.Test pack/Test.class

Invoke app

c:>java -jar app.jar

I was facing the same problem. What I did is I right clicked the project->properties and from "Select/Binary Format" combo box, I selected JDK 6. Then I did clean and built and now when I click the Jar, It works just fine.


I tried to start SQUirrel 3.1 but I received a message stating "Could not find the main class Files\Rational\ClearQuest\cqjni.jar" I noticed that C:\Program Files\Rational\ClearQuest\cqjni.jar is in my existing classpath as defined by the Windows environment variable, CLASSPATH.

SQUirrel doesn't need my existing classpath, so I updated the SQUirrel bat file, squirrel-sql.bat.

REM SET SQUIRREL_CP=%TMP_CP%;%CLASSPATH%

SET SQUIRREL_CP=%TMP_CP%

It no longer appends my existing classpath to its classpath and runs fine.


if you build the source files with lower version of Java (example Java1.5) and trying to run that program/application with higher version of Java (example java 1.6) you will get this problem. for better explanation see this link. click here


Extract the jar and compare the contents of the manifest inside the jar with your external manifest.txt. It is quite possible that you will locate the problem.