Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could not find Main class problem

Status
Not open for further replies.

sonname

Programmer
May 18, 2001
115
0
0
US
I've seen questions regarding this problem posted in many places, but no solution that works for me. I have the problem simplified so maybe we can get a solution:

The error ("could not find the main class") ocurrs only on machines with just
a jre (no jdk installed) from the following command when using Start->Run:
javaw -jar c:/trunk/dev/java/test/jartest.jar

BUT,
The error does not occur when using java instead of javaw.

ALSO,
BOTH ways of running work fine on a machine with the jdk installed.

I have the following simple code:
//----------
import javax.swing.JOptionPane;
public class jartest
{
public jartest()
{
JOptionPane.showMessageDialog(null, "hey", "jartest", JOptionPane.INFORMATION_MESSAGE);
}

public static void main( String args[] )
{
jartest jt = new jartest();
}
}
//---------- end of file

--------------------
my environment is WindowsXP Pro

$ java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)

javac -version
javac 1.5.0_02
javac: no source files
....

--------------------
I build my jar file as follows:
javac -d . jartest.java
jar cfm jartest.jar mainFile *.class
--------------------
My mainFile is simple:
Main-Class: jartest
--------------------
the client environment is WindowsXp Pro
$ java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
--------------------

Why does this happen and what is the solution?
 
I think I see this error before. If I remember correctly, it's due to the jartest class is not under any package. Try put the jartest class in a package say "myPakage". then in the manifest file:

Main-Class: myPackage.jartest

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top