This content has been marked as final. Show 39 replies
if you are running the jar file using
java -jar <jar-file>
you need to have the Main-Class attribute in the Manifest file
have a look at
I have a similar problem. Let me explain the steps I took:
- I've downloaded Netbeans 4.0 Beta 2.
- I've created a standard application project called: Maintest
- The project is the default project, creating a main class called: Main
- I've compiled and ran the "do-nothing" application.
So far so good.
- The Manifest.mf file is created automatically and placed inside the jar file.
So far so goo.
- I've tried to run the jar outside the ide (Win XP environment).
The error occurs.
- I've unpacked the jar file and checked out the included Manifest:
Manifest-Version: 1.0Ant-Version: Apache Ant 1.6.2
Created-By: 1.5.0-b64 (Sun Microsystems Inc.)
X-COMMENT: Main-Class will be added automatically by build
So far so good.
Yet the error remains. What could possibly be wrong?
Shall I upload this minimalistic jar file for you guys to download and check out? No problem if you would like to see.
Please send it to me, email@example.com
I am expecting a problem while jaring the file. I believe that the files Jarred are jarred using absulote file paths which would create such a problem, try to jar it using relative file paths.
I have the exactly the same problem, please someone post a solution
I am also having this exact same error! please help!
I'm facing the same prob too.. it has been so long.. someone please help....
I'm facing the same prob too... could it be an Ant problem?
It also puts an error symbol on the jar file, and does not provide informations about this error.
I had the same problem (i.e. Message-Box with "Could not find the main class. Program will exit.")
After insuring that the manifest contained a Main-Class: argument and that the argument pointed to the right class, I started the jar via
and read the stacktrace, which is much better than the popup-window.
java -jar myjar.jar
In my case the error was, that the Main-Class could not be loaded due to another referenced class, which was not on the classpath. (i.e. it was not in the same jar-File and the manifest didn't include a Class-Path: argument.)
After adding the correct Class-Path: argument in the manifest, the problem went away.
I now have the following setup:
myjar.jar and somethirdparty.jar in the same directory.
myjar.jar contains a manifest which includes the lines
after the normal Manifest-header.
Class-Path: somethirdparty.jar Main-Class: my.package.and.MainClass
And I have the very same problem
Actually I had this archive working with version 1.01 of my program. After that I made a lot of changes and the version 1.02 jar file can't find it's main class! I Have all depencies, manifest and classes in JBuilder2005 generated jar file.
I did work, it doesn't work now, when I'd changed the code!
I use JBuilder2005, WinXP what can be the problem??
have created the jar file in jbuilder.
the excutable jar will be excuted iff if it can find jre/lib and jre\bin
for instance place the jar file at jre folder exist in jdk.
u cant run it even if u have all dependencies and all class files
do this , write a bat file with this command
"jre\bin\javaw.exe" -jar "yourfile.jar" .
place your bat file and jar file in jre directory.
or place jar in jre dir and excute it.
I've had a similar problem.
A simple hello world form would run fine in the IDE but not from a JAR file. It turned out that I used the AbsoluteLayout manager which is a Netbeans component and not native Java. As I had not included these files in the Jar build they could not be found. To fix this problem you can add them to your project files so they will be added in the JAr build. To do this:
Copy these files:
From this location:
to your project directory.
build the project (F5)
then build the Jar
double clicking the Jar file now runs the app.
Does this help anybody?
copied those files into the source directory, compiled etc. like you said, but it didn't do anything for me... i'm having the same problem as everyone else. for some of them i got it to work by specifying the manifest file using
jar mcf mainClass file.jar *.class
where file.jar is the jar you want to create and of course the class files you want to jar are in the current directory.
and then the followin text in the mainClass file:
this might help some of you but but this doesn't work for some of the GUI projects i'm doing when exporting over to other operating systems, diff versions of java environment etc for some reason.
works fine on the machine. However, if i try toyProwler - I think I figured it out.. i had the same problem as you did originally. worked fine on my computer but nothing on any other.. It's because we're running the latest version of Java! (duh). I finally installed an older JDK (1.3) and then compiled etc. by changing the target in Netbeans (right click on the project node in the projects window and go to properties to choose which JDK you want to compile with). Of course I got errors because some of the functions are different etc. finally got it to compile and run, ran it on some other windows machines and it worked! GUI and all... of course the GUI looks different because it's the older version, but the functionality is there.
execute this same file on any other windows computer,
it gives an error "Could not find the main class.
Program will exit."
Okay, so are you saying that they could update their java version to run the program? If so, what's the link for the correct download (for clients, not developers)? Is there a way to check their computers for the correct version and, if they don't have it, to give them a link?
Thanks for the help. (That has been really annoying.)