Discussion:
Could not find the main class
kmzimmer
2013-04-29 21:58:17 UTC
Permalink
All,
I have a new java executable jar file that I run and get the following message. " Java Virtual Mahcine "Could not find the main class: program_name will exit. When I navigate to the dist folder and try to run the jar, I get "Exception in thread "main" noClassDEfFoundError:prc_cl7.prc_cl7. I have my libraries added and all works fine from within the IDE. There are 2 programs under my package with the java extension and runs fine. Your suggestions are greatly appreciated.
Thanks,
Ken
kmzimmer
2013-04-30 15:34:35 UTC
Permalink
Here is another one. I have a program that runs fine from the IDE but when I run the jar file I get "Could not find the main class prc_cl7.Main. Program will exit. Is there an easy way of fixing these in order to run the jar file?
kmzimmer
2013-05-01 22:47:11 UTC
Permalink
If I posted this question in the wrong area please advise. Thanks,
Mack06
2013-05-02 01:36:13 UTC
Permalink
Check the manifest.mf file in the Jar and see if it reflects the class your main method is in. If it doesn't check the "project properties>>run>>main class" to see if the right class is set for the main class. If you are using utf-8 chars that do not work in Windows 1252 (cp1252) encoding in the class name your main method resides, it may not work unless you set -J-Dfile.encoding=UTF-8 to netbeans_default_options in the netbeans.conf file.
Mack06
2013-05-02 02:08:19 UTC
Permalink
Oh and check and see if a CLASSPATH is set in your environmental variables, it should have a "." in the path to indicate that the current directory is in the CLASSPATH.

If it exists, it should e something like:

CLASSPATH=.;C:\Program Files\Java\jre1.7.0_21\lib\ext\QTJava.zip;<some other path>

You can also remove the CLASSPATH if you don't use it and JARS will run from their own directory just fine. NetBeans will work fine too.
kmzimmer
2013-05-02 15:58:40 UTC
Permalink
Mack,
I have no environment variable set on my Windows 7 machine. My manifest file contains.

Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

I did find on the machine that I"m not working on has a CLASSPATH set to


.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

So Should I add an environment variabe named CLASSPATH with the same as above, reboot and try again?

Thanks for your response.

Ken
Mack06
2013-05-02 16:31:41 UTC
Permalink
Mack,
I have no environment variable set on my Windows 7 machine. My manifest file contains.
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Look at the MANIFEST.MF in the JAR file, not the one in the project directory. It is in the META-INF folder in the JAR file.
I did find on the machine that I"m not working on has a CLASSPATH set to
.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
That is fine, it has a leading dot that tells java to use the current directory from the command line.
So Should I add an environment variabe named CLASSPATH with the same as above, reboot and try again?
You shouldn't need a CLASSPATH if you don't already have one, it's just that if you do have one, it should have the dot directory like shown above.

Do you have the right JDK bin in your path? It should be set to something like C:\Program Files\Java\jdk1.7.0_17\bin and pointed to the right Java version. You normally make a JAVA_HOME variable and then put like %JAVA_HOME%\bin\ in your path so you can just change JAVA_HOME to point to another JDK without editing the bath. Just don't put the \bin\ part in the JAVA_HOME variable.

\>java -version tells you what version you are seeing from the command line.
kmzimmer
2013-05-02 17:22:36 UTC
Permalink
Mack,
My path does contain 'C:\Program Files (x86)\Java\jdk1.6.0_24\bin;'

These are the contents from my MANIFEST.MF FILE

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: prc_cl7.Main
X-COMMENT: Main-Class will be added automatically by build

Source Package is prc_cl7, Under that is Main.java. Here is a code sample.

package prc_cl7;

/** Used to output messages to a file. */
private static PrintWriter out;

public class Main {

public static void main(String[] args) throws SQLException, ClassNotFoundException {

// TO DO HERE
Mack06
2013-05-02 20:46:18 UTC
Permalink
Is that the only JDK on the system? In Help>>About what version dose it say NetBeans is running on and what does it say the version of NetBeans is? What version in Project Properties>>Libraries>>JDK version does it say? What does it say for Project Properites>>Sources>>Source/Binary format?

Did you try compiling and creating a JAR from the command line and then see if it will run?
Mack,
My path does contain 'C:\Program Files (x86)\Java\jdk1.6.0_24\bin;'
These are the contents from my MANIFEST.MF FILE
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_24-b07 (Sun Microsystems Inc.)
Main-Class: prc_cl7.Main
X-COMMENT: Main-Class will be added automatically by build
Source Package is prc_cl7, Under that is Main.java. Here is a code sample.
package prc_cl7;
/** Used to output messages to a file. */
private static PrintWriter out;
public class Main {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// TO DO HERE
Mack06
2013-05-02 20:57:15 UTC
Permalink
See the error message is saying it can't find prc_cl7.prc_cl7 so somewhere, something is messed up and it should be looking for prc-cl7.Main

I think I would try and build the jar from command line and see if it works, then try Ant from the command line. Maybe you need to get the latest jdk1.6.0_45 version, maybe Ant 1.8.1, which NetBeans is using.
Mack06
2013-05-02 21:01:33 UTC
Permalink
Maybe the underscore in the package name messes up things.
kmzimmer
2013-05-02 21:25:57 UTC
Permalink
Mack,

JAVA 1.6.0_24; Java Hotspot™ Client VM 19.1-bo2 running Netbeans 6.9.1.

JDK 1.6 Default

Source / Binary / Format JDK 5

// The line above may be an issue.

Endcoding UTF-8

I haven’t tried creating a jar from the command line. It’s been a while since I’ve did that.

You may be correct that the ‘_’ is causing problems as well.

Ken
kmzimmer
2013-05-02 21:34:21 UTC
Permalink
Mack,
I changed the source/binary/format to JDK 6 and the jar did not work. Do I need to change the netbeans config file? If so, how do I change it?

Thanks,
Ken
kmzimmer
2013-05-02 21:59:16 UTC
Permalink
Mack,

I do have my files under c:\users\myname\my documents\netbeansprojects\prccl7.

Does this folder need to under the application?

Ken
kmzimmer
2013-05-02 22:00:29 UTC
Permalink
I created a new package with no '_' and got the same resullts.
Mack06
2013-05-03 00:57:03 UTC
Permalink
Why are you using such an old version of NetBeans? Are you using Windows? You probably ought to install v7.3.
kmzimmer
2013-05-06 16:54:06 UTC
Permalink
Mack,

I have old code running with older libraries etc.

The jar's were created fine a while back.

Ken
kmzimmer
2013-05-06 17:01:31 UTC
Permalink
Mack,

I had 7.2 on and had problems with some of my older code. I'll try 7.3.

Ken
kmzimmer
2013-05-06 22:54:12 UTC
Permalink
Mack,
It worked. I don't have any idea why. Now I can run from my machine the executable. I'm gong to transport to different machines etc.
Thans,
Ken
kmzimmer
2013-05-08 15:28:10 UTC
Permalink
This can be closed. All is working fine for me in the new version.
Loading...