Results 1 to 12 of 12
  1. #1
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Unhappy Eclipse and creating .jar file

    Hi everyone,

    I'm really new to java, so if i ask a stupid question, please forgive me.

    I created a .jar file by using export function in Eclipse (yes, I include manifest).
    When I executed the .jar file on my computer by opening it with java.exe, a error window popped up "couldn't find main class" ; however, I sent this .jar to my gf and she was able to execute the jar file without error by using java.exe

    I'm not sure what's wrong this my computer. Have anyone faced this problem before? Please help me out. I would be nice if you guys download the file and run it to see that I was the only person who encountered this problem or not.

    I compressed my .jar file into .zip file.
    Thx in advance.
    PV
    Attached Files Attached Files

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by wantakill View Post
    Hi everyone,

    I'm really new to java, so if i ask a stupid question, please forgive me.

    I created a .jar file by using export function in Eclipse (yes, I include manifest).
    When I executed the .jar file on my computer by opening it with java.exe, a error window popped up "couldn't find main class" ; however, I sent this .jar to my gf and she was able to execute the jar file without error by using java.exe

    I'm not sure what's wrong this my computer. Have anyone faced this problem before? Please help me out. I would be nice if you guys download the file and run it to see that I was the only person who encountered this problem or not.

    I compressed my .jar file into .zip file.
    Thx in advance.
    PV
    You probably haven't set the correct file extension association on your system because when I run your .jar as:

    Java Code:
    java -jar ATMBankAccount.jar
    ... it works fine. So your manifest is ok.

    kind regards,

    Jos

  3. #3
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    hi JoSAH,

    Is the OS that runs my .jar file 32 bit?

    There is nothing wrong with my associate file. Somehow the .jar file can be executed on 32bit system ( my gf's wins 7 32 bit, wins 7 32 bit on my laptop, and Virtual machine wins 7 32 bit on my 64 bit OS). Only my wins 7 64 bit can't run this .jar file.

    Does this mean we can't run .jar on Wins 7 64 bit ???:confused:

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,402
    Rep Power
    25

    Default

    There is nothing wrong with my associate file
    How did you verify that? On WinXP you can look at the OS's file association table by:
    Open Windows Explorer
    Click on Tools menu
    Click on Folder Options
    Select File Types tab
    Scroll down in the "Registered file types:" list until you see an entry for JAR.
    Select the JAR entry.
    Click the Advanced button
    In the Edit File Type window scroll down the list of Actions until you see the one in bold.
    Select the bold one
    Click the Edit button
    Select, Copy and paste here what is in the "Application used to perform action:" window.

    Be careful not to change anything and Cancel your way out of the open windows.

    If you copy the commandline from above, open a commandprompt window, change tothe folder with the jar file, paste the commandline to the command prompt, change the %1 to your jar file name and press enter, What happens?

  5. #5
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Hi Norm,

    I did verify the file associate. On Wins 7, right click > properties > under General tab, click the Change button to select a program> select java or javaw or the fullpath C:\Program Files\Java\jre6\bin\java.exe

    In command line: error for both cases: Could not find the main class: blablabla. Program will exit.

    So I think I will use my virtual machine to create and test .jar files then. :)

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,402
    Rep Power
    25

    Default

    Copy and paste here what is in the "Application used to perform action:" window.
    What is the contents of that window? Does it have a -jar in the command line???

    error for both cases: Could not find the main class: blablabla.
    It would help if you copied and pasted here THE EXACT contents of the error message.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    There could be a problem with the manifest file: misspelled classname, wrong package, ??

    Look in the jar file at its manifest file. Copy and paste here the contents of the manifest file from the jar file.

    Here's one way to get the error message. The full text of which shows the error.
    D:\JavaDevelopment\Testing\ForumQuestions3>java asdfas <<<<<<<<<<< NOTE class name is invalid
    Exception in thread "main" java.lang.NoClassDefFoundError: asdfas
    Caused by: java.lang.ClassNotFoundException: asdfas
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: asdfas. Program will exit. <<<<<<<<<<< Here is some of what you gave us

    D:\JavaDevelopment\Testing\ForumQuestions3>
    Last edited by Norm; 09-04-2010 at 05:29 PM.

  7. #7
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Here is the content of the error. I didn't put -jar in the command line

    C:\Program Files\Java\jre6\bin>java.exe Users/phatvi/Desktop/sharefolder/ATMBank
    Account.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: Users/phatvi/Desktop/
    sharefolder/ATMBankAccount/jar
    Caused by: java.lang.ClassNotFoundException: Users.phatvi.Desktop.sharefolder.AT
    MBankAccount.jar
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: Users/phatvi/Desktop/sharefolder/ATMBankAccount.j
    ar. Program will exit.

    For manifest content
    Manifest-Version: 1.0
    Main-Class: ATMBankAccount

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,402
    Rep Power
    25

    Default

    I didn't put -jar in the command line
    why not? Read the API doc for how to use the java command. Its necessary.

    NoClassDefFoundError: Users/phatvi/Desktop/sharefolder/ATMBankAccount/jar
    Does the name of the class not found look familiar?
    The java command takes the name of a class as an arg.
    you passed the command a path to a file which the java command assumed was the name of a class file.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by wantakill View Post
    Here is the content of the error. I didn't put -jar in the command line

    Java Code:
    C:\Program Files\Java\jre6\bin>java.exe Users/phatvi/Desktop/sharefolder/ATMBankAccount.jar
    Great, now the jvm 'thinks' that it has to run the main( ... ) method from a class called Users/phatvi/Desktop/sharefolder/ATMBankAccount.jar

    kind regards,

    Jos

  10. #10
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Norm and JosAH,

    Thx for the help. I just figured out what's wrong with my command line.

    This command line works for me
    cd [filepath]
    [filepath] > java - jar ATMBankAccount.jar
    All I wonder now is why I can't execute the .jar file with just with a double click as other computers?

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,402
    Rep Power
    25

    Default

    That problem was discussed in post#4.
    There needs to be a correct entry in the OSs filetype association table.

    Selecting a program is NOT the same as creating a command line. You need the -jar option.

  12. #12
    wantakill is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Thank you for clearing all my confusions. I learned a lot from this topic

Similar Threads

  1. creating war file in eclipse
    By pelegk1 in forum Eclipse
    Replies: 3
    Last Post: 05-24-2010, 04:28 AM
  2. Creating .xml files in eclipse
    By lheebhee in forum Eclipse
    Replies: 1
    Last Post: 11-17-2009, 06:48 AM
  3. Replies: 0
    Last Post: 05-28-2008, 10:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •