Results 1 to 9 of 9
  1. #1
    kelvinsmj is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default Command Prompt Java

    Hi I have project in eclipse with packages

    com.mypackage.abc.java
    com.mypackage.def.java

    I can run both programs in eclipse fine, but i want to run it from command prompt.

    The root of my source file is c:\project\src
    Classes for these are at c:\project\target
    so I change directory to
    c:\project\target
    java -classpath . com.mypacakage.abc

    but it returns NoClassDefFoundError

    can someone please help.

  2. #2
    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 kelvinsmj View Post
    Hi I have project in eclipse with packages

    com.mypackage.abc.java
    com.mypackage.def.java

    I can run both programs in eclipse fine, but i want to run it from command prompt.

    The root of my source file is c:\project\src
    Classes for these are at c:\project\target
    so I change directory to
    c:\project\target
    java -classpath . com.mypacakage.abc

    but it returns NoClassDefFoundError

    can someone please help.
    Can you find your .class files in your target (sub)directory? e.g. c:\project\target\com\mypackage\abc.class

    kind regards,

    Jos

  3. #3
    kelvinsmj is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    Hi Jos, thanks for your reply. Yes I can find those classes in there.

  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 kelvinsmj View Post
    Hi Jos, thanks for your reply. Yes I can find those classes in there.
    Well, then the following should work (note the typo in your original post: pacakage != package)

    c:\project\target
    java -classpath . com.mypackage.abc

    kind regards,

    Jos

  5. #5
    kelvinsmj is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    sorry about my typo, i've read it onthe web that this is how i am suppose to do it like what you are saying, but for some strange reason, it doesn't work for me, really weird.
    if i package it into a jar file then it works

  6. #6
    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 kelvinsmj View Post
    sorry about my typo, i've read it onthe web that this is how i am suppose to do it like what you are saying, but for some strange reason, it doesn't work for me, really weird.
    if i package it into a jar file then it works
    Did you do "cd c:\project\target" before you run your java.exe command? i.e. it has to be the current directory for "-classpath ." flag to work.

    kind regards,

    Jos

  7. #7
    kelvinsmj is offline Member
    Join Date
    Jul 2009
    Posts
    4
    Rep Power
    0

    Default

    yes I did. I changed directory to the directory where the com directory is located (ie c:\project\target" before I run the command.

  8. #8
    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 kelvinsmj View Post
    yes I did. I changed directory to the directory where the com directory is located (ie c:\project\target" before I run the command.
    Well, last question then: are all the class files there in their correct (sub)directory? (you should be able to check all this yourself when things don't work as you expected).

    kind regards,

    Jos

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,846
    Rep Power
    19

Similar Threads

  1. Replies: 6
    Last Post: 04-20-2009, 04:34 AM
  2. how to run windows command prompt in java parogram ?
    By indikasampath2000 in forum AWT / Swing
    Replies: 4
    Last Post: 12-16-2008, 06:51 AM
  3. Replies: 2
    Last Post: 12-03-2008, 01:24 PM
  4. Running eclipse java project on command prompt
    By hnmapara in forum New To Java
    Replies: 1
    Last Post: 07-09-2008, 08:29 AM
  5. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 03:01 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
  •