#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0

    Java Application works in Eclipse but not via command line "classnotfound" error.


    Hello All,

    I have a Java Application in an Eclipse project which runs fine in Eclipse but when I try and run it via the command prompt (cmd in windows) I get "classnotfound" error.

    I have tried -cp and -classpath to define where the classes are located but with no luck.

    The PrintInfo.java file and PrintInfo.class file are in different folders. PrintInfo is the main class and I have a .jar file that contains the API. I can run the API via command prompt but not the class file which accesses the API.

    Anyone have any suggestions or advice on how I can resolve this issue.

    Thank you.

    Schuster
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Did you make sure to include the actual jar file in the CLASSPATH?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by bullet
    Did you make sure to include the actual jar file in the CLASSPATH?
    I included the path to the jar file but not the jar file itself.

    Do you have an example I can try ?

    thank you.

    Schuster
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Originally Posted by schuster19uk
    I included the path to the jar file but not the jar file itself.

    Do you have an example I can try ?

    thank you.

    Schuster
    When you have a .jar file, you have to include the .jar file in the CLASSPATH. For example, if you have

    util.jar in c:\temp,

    you would include in the CLASSPATH like this

    javac -cp c:\temp\util.jar;. ...

    or

    java -cp c:\temp\util.jar;. ...

    EDIT: Note the semicolon is used to seperate the directories and jar files on Windows. On UNIX a : is used.
    Last edited by bullet; April 22nd, 2013 at 08:09 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by bullet
    When you have a .jar file, you have to include the .jar file in the CLASSPATH. For example, if you have

    util.jar in c:\temp,

    you would include in the CLASSPATH like this

    javac -cp c:\temp\util.jar;. ...

    or

    java -cp c:\temp\util.jar;. ...

    EDIT: Note the semicolon is used to seperate the directories and jar files on Windows. On UNIX a : is used.

    "I have now tried that and I get could not find or load main class"

    This is what I have:

    C:\Users\Schuster\workspace\TestJava\src>java -cp C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\ZSDK_API.jar;c:\Users\Schuster\workspace\TestJava\src;. PrintB
    itmapImage.java PrintBitmapImage "ZDesigner GK420d" C:\Users\Schuster\Desktop\tm
    p252A.bmp 10 10 750 900 true

    "C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\ZSDK_API.jar" is the location of the jar file

    "c:\Users\Schuster\workspace\TestJava\src" is the location of the .java file

    I also have a PrintBitmapImage.class file in "C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\" which is built when I compile the project.

    All I am trying to do is simulate "Run configurations" and set the required program arguments via command prompt.

    I have this as arguments "ZDesigner GK420d" C:\Users\Schuster\Desktop\tm
    p252A.bmp 10 10 750 900 true

    thank you
  10. #6
  11. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Originally Posted by schuster19uk
    "I have now tried that and I get could not find or load main class"

    This is what I have:

    C:\Users\Schuster\workspace\TestJava\src>java -cp C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\ZSDK_API.jar;c:\Users\Schuster\workspace\TestJava\src;. PrintB
    itmapImage.java PrintBitmapImage "ZDesigner GK420d" C:\Users\Schuster\Desktop\tm
    p252A.bmp 10 10 750 900 true

    "C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\ZSDK_API.jar" is the location of the jar file

    "c:\Users\Schuster\workspace\TestJava\src" is the location of the .java file

    I also have a PrintBitmapImage.class file in "C:\Users\Schuster\Desktop\Test
    Java\TestJava\bin\" which is built when I compile the project.

    All I am trying to do is simulate "Run configurations" and set the required program arguments via command prompt.

    I have this as arguments "ZDesigner GK420d" C:\Users\Schuster\Desktop\tm
    p252A.bmp 10 10 750 900 true

    thank you
    Why are you including PrintBitmapImage.java?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by bullet
    Why are you including PrintBitmapImage.java?
    With or without doesn't work.
  14. #8
  15. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    Originally Posted by schuster19uk
    With or without doesn't work.
    are you sure PrintBitmapImage.class was created?

    Comments on this post

    • schuster19uk agrees : conflict of classes so it helps if you go back to basics
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by bullet
    are you sure PrintBitmapImage.class was created?
    It was created as part of a different project so it was there, I moved that class file elsewhere and its all running fine now.

    Thank you for your help.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Originally Posted by bullet
    are you sure PrintBitmapImage.class was created?
    I tried to give you some points but it somehow didn't work I think. Please accept my apologies, new to this forum
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    7
    Rep Power
    0
    Thankyou Bullet!

IMN logo majestic logo threadwatch logo seochat tools logo