• Post Reply Bookmark Topic Watch Topic
  • New Topic

NetBeans java .jar main error  RSS feed

 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to make my java program executable with a double-click, but when I make the .jar file when I double-click it, it says "Error could not find or load main class" then it gives the directory to the main class and its right. The manifest file is correct. And I've also tried other programs to make it executable with a double-click, but they give the same response.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you copy paste the exact contents of your manifest file (Please UseCodeTags)
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tryed everything that is why my main class is also called main
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. And which is your main class? How is it packaged?

If you have a main class called Main (notice the capital M as per naming convention) and it is packaged under com.maneesh.application the the manifest entry should read
Main-Class: com.maneesh.application.Main
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all my classes are in one package(the default one). my main class is called: main and my main method is called: main.

I have a project called theGame, and the drop down tabs layout like this: Source Packages --> default package --> then there is all my classes including my main class and main method


I would not prefer we would get into grammar in this discussion, thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I think your problem is caused because of the default package. Solution: Package your classes
Micah Glenz wrote:
I would not prefer we would get into grammar in this discussion, thanks.

If you are referring to me pointing out the capitalized 'M' it is not about grammar (as in the language) but about the naming conventions like I mentioned earlier
http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Then I think your problem is caused because of the default package. Solution: Package your classes
Micah Glenz wrote:
I would not prefer we would get into grammar in this discussion, thanks.

If you are referring to me pointing out the capitalized 'M' it is not about grammar (as in the language) but about the naming conventions like I mentioned earlier
http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java


Yes that is what I meant, when I was trying to fix it I wasn't trying to make it look pretty. Thank you thought.
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My manifest now looks like this:


I have added a package(Game) and my new name for the main class is called Central.
Yet it still is giving me the error:
"Error" Could not find or load main class(then the directory to the jar file)"
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open a terminal (command prompt)
Navigate to the directory your jar file is located
Run the command jar tf jar-file (-file is the jar file name. e.g. MyJar.jar)
The command will print the contents of your jar.
Please copy paste the console output which shows the contents (as always please UseCodeTags)
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry couldn't get back to you right away some other things take precedence.

 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried a different IDE(eclipse) and that still didn't work...must be me and not my code.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Micah Glenz wrote:My manifest now looks like this:

. . .
And has it really got a blank line at the end? It won't work without the blank line.
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that isn't the problem.
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Interesting. Can you try running the jar from the command line java -jar jarFileName.jar and copy paste what you see on the console here
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if i do:

it works perfectly.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thats expected if you are trying to run from outside the jar directory (or if the jar is not on the classpath)
So if you run from the command line, it works, but double clicking does not. Is that correct?
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes completly.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is very strange.
What OS are you running?
What is the file association (open with) for jar type files on your machine? (Should be javaw)
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running Windows 7
and I open with "Java platform SE binary"
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Micah Glenz wrote:
and I open with "Java platform SE binary"

I am not sure what this means. I do not use Windows. Maybe someone who does can help figure this out.
In the meanwhile, try running it with javaw.exe (Located under JAVA_HOME/bin/)
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run it with "javaw.exe" the file turns into a Executable Jar File, but it does absolutely nothing when I double click it, not even a cmd window pops up
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally! Some progress.
Is your code supposed to display some UI or is it a console based application?
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in the console
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! Now it explains everything!

The javaw command intentionally does not display the command. It is designed to be used with GUI applications.
Since your application is console based, you can make it "double clickable" by associating with the java.exe (JAVA_HOME/bin)
Keep in mind though, this association is system wide. In other words once you set the association the OS will attempt to execute all jars with java.exe

 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the Java platform SE binary though
 
Micah Glenz
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't talk till tomorrow so if you give another answer don't expect it soon.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!