Jar file error: could not find main class.

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 2689 Views - Last Post: 05 March 2012 - 09:42 PM Rate Topic: -----

#1 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Jar file error: could not find main class.

Posted 01 March 2012 - 04:11 PM

I tried to make a jar file of my program using Netbeans IDE 7.0, but after I build the project and run the jar file I got this message : "Could not find the main class, Program will exit"

And so I decided to run it in cmd to see what's the problem:

<code>
C:\Users\user>java -jar "C:\Users\user\Documents\NetBeansProjects\PictureSliderG
ame\dist\PictureSliderGame.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: pictureslidergame/Pic
tureSliderGame
Caused by: java.lang.ClassNotFoundException: pictureslidergame.PictureSliderGame

at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: pictureslidergame.PictureSliderGame. Program will
exit.</code>

could somebody please explain to me where I gone wrong? thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Jar file error: could not find main class.

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 04:30 PM

Looks like the jar has not been built properly. Are you sure there are no compilation errors before you try to build it?
Was This Post Helpful? 0
  • +
  • -

#3 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 04:35 PM

View Postg00se, on 01 March 2012 - 04:30 PM, said:

Looks like the jar has not been built properly. Are you sure there are no compilation errors before you try to build it?


here's what I got when I build the project:

init:
deps-clean:
Updating property file: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\built-clean.properties
Deleting directory C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build
clean:
init:
deps-jar:
Created dir: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build
Updating property file: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\built-jar.properties
Created dir: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\classes
Created dir: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\empty
Created dir: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\generated-sources\ap-source-output
Compiling 9 source files to C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\classes
Copying 52 files to C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build\classes
compile:
Created dir: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\dist
Copying 1 file to C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\build
Nothing to copy.
Building jar: C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\dist\PictureSliderGame.jar
To run this application from the command line without Ant, try:
java -jar "C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\dist\PictureSliderGame.jar"
jar:
BUILD SUCCESSFUL (total time: 2 seconds)


I'm not sure if it's a successful one..
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 04:58 PM

Looks good. Did you try what's suggested here?

Quote

To run this application from the command line without Ant, try:
java -jar "C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\dist\PictureSliderGame.jar"

Was This Post Helpful? 0
  • +
  • -

#5 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 05:02 PM

View Postg00se, on 01 March 2012 - 04:58 PM, said:

Looks good. Did you try what's suggested here?

Quote

To run this application from the command line without Ant, try:
java -jar "C:\Users\user\Documents\NetBeansProjects\PictureSliderGame\dist\PictureSliderGame.jar"


Yes sir I've tried to run it in command prompt to see then i got these errors:

C:\Users\user>java -jar "C:\Users\user\Documents\NetBeansProjects\PictureSliderG
ame\dist\PictureSliderGame.jar"
Exception in thread "main" java.lang.NoClassDefFoundError: pictureslidergame/Pic
tureSliderGame
Caused by: java.lang.ClassNotFoundException: pictureslidergame.PictureSliderGame

at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: pictureslidergame.PictureSliderGame. Program will
exit.
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 05:10 PM

Strange. I've never seen anything building properly and then running wrongly. Can you open a command prompt, run the command below and attach the file PictureSliderGame.zip to this question


jar cfM PictureSliderGame.zip -C C:\Users\user\Documents\NetBeansProjects PictureSliderGame

This post has been edited by g00se: 01 March 2012 - 05:11 PM

Was This Post Helpful? 0
  • +
  • -

#7 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 01 March 2012 - 10:28 PM

View Postg00se, on 01 March 2012 - 05:10 PM, said:

Strange. I've never seen anything building properly and then running wrongly. Can you open a command prompt, run the command below and attach the file PictureSliderGame.zip to this question


jar cfM PictureSliderGame.zip -C C:\Users\user\Documents\NetBeansProjects PictureSliderGame


I tried it sir and it prompted options...sir what do you mean by attach the PictureSliderGame.zip file?
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 02 March 2012 - 02:41 AM

Quote

I tried it sir and it prompted options


That's strange - there should be little or no output

Quote

what do you mean by attach the PictureSliderGame.zip file?


That file is created by the command i gave you
Was This Post Helpful? 0
  • +
  • -

#9 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 03 March 2012 - 04:33 AM

View Postg00se, on 02 March 2012 - 02:41 AM, said:

Quote

I tried it sir and it prompted options


That's strange - there should be little or no output

Quote

what do you mean by attach the PictureSliderGame.zip file?


That file is created by the command i gave you


I tried it already sir but it didn't produce a zip file.. instead, could i email you the rar file that i made so maybe you could check it...

View Postg00se, on 02 March 2012 - 02:41 AM, said:

Quote

I tried it sir and it prompted options


That's strange - there should be little or no output

Quote

what do you mean by attach the PictureSliderGame.zip file?


That file is created by the command i gave you


I tried it already sir but it didn't produce a zip file.. instead, could i email you the rar file that i made so maybe you could check it?
Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 03 March 2012 - 06:08 AM

Attach the rar file to a post here but rename the extension to .zip
Was This Post Helpful? 0
  • +
  • -

#11 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 03 March 2012 - 08:50 PM

sir,can't attach it here... the file size not allowed for upload..
Was This Post Helpful? 0
  • +
  • -

#12 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2640
  • View blog
  • Posts: 11,155
  • Joined: 20-September 08

Re: Jar file error: could not find main class.

Posted 04 March 2012 - 03:59 AM

How large is it?
Was This Post Helpful? 0
  • +
  • -

#13 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 04 March 2012 - 09:27 PM

View Postg00se, on 04 March 2012 - 03:59 AM, said:

How large is it?


10mb sir.
Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Jar file error: could not find main class.

Posted 04 March 2012 - 09:50 PM

Never rely on an IDE to generate .jar
They might have pecky reaction based on the ast main() run
put that one in you Favorites

http://docs.oracle.c...asicsindex.html
and use it !!!
Was This Post Helpful? 1
  • +
  • -

#15 kimuchii7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-December 11

Re: Jar file error: could not find main class.

Posted 04 March 2012 - 10:01 PM

View Postkimuchii7, on 04 March 2012 - 09:27 PM, said:

View Postg00se, on 04 March 2012 - 03:59 AM, said:

How large is it?


10mb sir.



here sir, you can download the package:
http://www.mediafire...p619pypd5t3trxb
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3