Results 1 to 8 of 8
  1. #1
    gold.dudu is offline Member
    Join Date
    Jul 2010
    Location
    IL
    Posts
    7
    Rep Power
    0

    Unhappy Problem running from CMD line - probably classpath, but i can't figure why

    :confused::confused::confused:
    Hi,
    i have a project named client
    under it i have a package named "bank" contains classes:
    action.java
    account.java
    accountsMgr.java
    accountMgrImpl.java

    i was able to compile them all from cmd line:
    C:\Eclipse_Workspace\client\src>javac \Eclipse_Workspace\client\src\bank\Action.java

    C:\Eclipse_Workspace\client\src>javac \Eclipse_Workspace\client\src\bank\AccountMgrImpl. java

    C:\Eclipse_Workspace\client\src>javac \Eclipse_Workspace\client\src\bank\AccountsMgr.jav a

    C:\Eclipse_Workspace\client\src>javac \Eclipse_Workspace\client\src\bank\Account.java

    My main method is in Action.java
    trying to run it fails for this:

    C:\Eclipse_Workspace\client\src>java \Eclipse_Workspace\client\src\bank\Action

    Exception in thread "main" java.lang.NoClassDefFoundError: \Eclipse_Workspace\cl
    ient\src\bank\Action
    Caused by: java.lang.ClassNotFoundException: \Eclipse_Workspace\client\src\bank\Action
    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: \Eclipse_Workspace\client\src\bank\Action. Program will exit.

    can someone please help ???

  2. #2
    ןǝsɐǝʍ is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    try using a dot (".") between the package name and the class instead of a slash.
    i.e
    "C:\Eclipse_Workspace\client\src>java \Eclipse_Workspace\client\src\bank.Action"

  3. #3
    ןǝsɐǝʍ is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    Question 1. I tried to run the program from the DOS prompt,
    but got java.lang.NoClassDefFoundError exception. What is
    wrong?
    Answer: The class file is not found. There are several
    reasons: 1. the class has been compiled; 2. the classpath
    was not set properly. You need to set classpath to
    .;%classpath%. 3. If the class has a package statement, you
    didn’t invoke it with the full class name including the
    complete package name. For example, if the class path is
    c:\liang and the package for the class is chapter1, you have
    to type java chapter1.ClassName from the c:\liang directory.
    from http://cs.armstrong.edu/liang/intro7...1cJDKonDOS.pdf

    Hope this helps
    Last edited by ןǝsɐǝʍ; 07-17-2010 at 11:17 AM.

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

    Default

    Quote Originally Posted by gold.dudu View Post
    :confused::confused::confused:
    Hi,
    i have a project named client
    under it i have a package named "bank" contains classes:
    action.java
    account.java
    accountsMgr.java
    accountMgrImpl.java

    i was able to compile them all from cmd line:
    C:\Eclipse_Workspace\client\src>javac \Eclipse_Workspace\client\src\bank\Action.java
    [ ... ]
    C:\Eclipse_Workspace\client\src>java \Eclipse_Workspace\client\src\bank\Action

    Exception in thread "main" java.lang.NoClassDefFoundError: \Eclipse_Workspace\client\src\bank\Action
    Caused by: java.lang.ClassNotFoundException:
    The rule is: you compile files with javac and you run classes with java. The name of your class is bank.Action and your classpath should point to a directory which has a subdirectory named 'bank' (your package name) which stores a file (containing your class) named Action.class. You were trying to run a class named \Eclipse_Workspace\client\src\bank\Action and it doesn't exist of cource.

    kind regards,

    Jos

  5. #5
    gold.dudu is offline Member
    Join Date
    Jul 2010
    Location
    IL
    Posts
    7
    Rep Power
    0

    Unhappy tried the bank.action --> did not help

    also the Pdf did not help.
    thanks anyway.

  6. #6
    gold.dudu is offline Member
    Join Date
    Jul 2010
    Location
    IL
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    The rule is: you compile files with javac and you run classes with java. The name of your class is bank.Action and your classpath should point to a directory which has a subdirectory named 'bank' (your package name) which stores a file (containing your class) named Action.class. You were trying to run a class named \Eclipse_Workspace\client\src\bank\Action and it doesn't exist of cource.

    kind regards,

    Jos
    ok, i tried this and still nothing.

    C:\Eclipse_Workspace\client\src>java -cp \Eclipse_Workspace\client\src /bank\Action

    Exception in thread "main" java.lang.NoClassDefFoundError: /bank\Action
    Caused by: java.lang.ClassNotFoundException: .bank\Action
    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: /bank\Action. Program will exit.

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

    Default

    Quote Originally Posted by gold.dudu View Post
    ok, i tried this and still nothing.

    C:\Eclipse_Workspace\client\src>java -cp \Eclipse_Workspace\client\src /bank\Action

    Exception in thread "main" java.lang.NoClassDefFoundError: /bank\Action
    Caused by: java.lang.ClassNotFoundException: .bank\Action
    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: /bank\Action. Program will exit.
    As I wrote: the name of your class is bank.Action, not /bank\Action. Check if your directory contains a subdirectory 'bank' that stores a file named 'Action.class'. Make sure your classpath points to that first directory.

    kind regards,

    Jos

  8. #8
    gold.dudu is offline Member
    Join Date
    Jul 2010
    Location
    IL
    Posts
    7
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    As I wrote: the name of your class is bank.Action, not /bank\Action. Check if your directory contains a subdirectory 'bank' that stores a file named 'Action.class'. Make sure your classpath points to that first directory.

    kind regards,

    Jos
    thanks josAH, this helped a lot.
    C:\Eclipse_Workspace\client\src>java -cp . bank.Action

Similar Threads

  1. classpath problem
    By Nifras in forum New To Java
    Replies: 6
    Last Post: 11-28-2009, 04:49 PM
  2. Replies: 0
    Last Post: 08-26-2009, 01:03 PM
  3. classpath problem
    By shwein in forum New To Java
    Replies: 4
    Last Post: 04-01-2009, 12:32 PM
  4. Unable to figure out this problem! jndi lookup exception.....
    By vrk in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-19-2009, 11:38 AM
  5. [SOLVED] Can't figure out my thread/awt problem
    By Zosden in forum Advanced Java
    Replies: 7
    Last Post: 07-29-2008, 05:13 PM

Posting Permissions

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