954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Jar File Problem, Could not find the main class....

Hello friends,
You have been of great help to me till now. I got a new problem , I am unable to run the JAR file.

When i click on the Jar file, I got the following error :

"Could not find the main class: socketprog.Main. Program will exit."

Thanks in advance for your answers.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

you are trying to run the jar file

do you have this in there?

public static void main(String [] args)


i'm assuming you don't, but for a jar file to be run, just like any other code, it needs to start with a main method

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Executable jar files need a Main-Class: entry in the manifest file.
More info here: http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Thanks for the answer, yeah of course I have the main method. The program run normally when I compiled it with the compiler. But I just want it to run like an exe file, without the need to compile it again and again.

Thanks.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

Thanks ezzaral, but I know it has something to do with manifest file. Can you help me to do it with Netbeans please. I got some tutorial but its not working.
Thanks again.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

You should be able to set the main class in the project properties in the "Run" section.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Hello Ezzaral,
Wow ... its working now. Yuppie .. you are too good. Its have nothing to do with "manifest" file then.

Can you please explain to me, what does the manifest file do ?? I am just curious.

Thanks guys, thanks a lot.

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

The manifest file specifies where the main class is, that way the program can run as you want it to. And netbeans generates the manifest file for you, so you don't see the details of it, but I'm sure that it happens. The manifest file can also do other things, I think, but I'm not sure what they are. See here for more info:

http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

Thanks for the answer BJSJC. ;)

neutralfox
Junior Poster
124 posts since Mar 2009
Reputation Points: 6
Solved Threads: 0
 

Hello Ezzaral,
i m doing the same thing... i have Table.jar which contain manifest file...

Manifest-Version: 1.0
Main-Class: org.lan.Table

Can you please explain me what i am doing wrong....

sa86
Newbie Poster
1 post since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

Thank you so much Ezzaral :)))
I did what you said about the properties under the project and everything seems fine now:)
The only problem I have is that the icons of the buttons I have in the interface are not shown or recognized:( What can I do? Please answer me;)

Marin88
Newbie Poster
1 post since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You