Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Program Works on NetBeans, but Jar file doesn't work correctly.

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Program Works on NetBeans, but Jar file doesn't work correctly.

    Hello everybody,

    I created a Form Application in Java to communicate via USB to a Microcontroller board. For that I need a library called libusbJava. My program is working just fine on NetBeans, but when I try to run the Jar file I receive the following error:

    ...
    Caused by: java.lang.ClassNotFoundException: ch.ntb.usb.LibusbJava
    ...



    When I build the jar file I receive the following notes:

    Note: C:\Users\Home\Desktop\Thesis\Java UDP\USBDriver\src\ZTex.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    Not copying library C:\Users\Home\Documents\NetBeansProjects\UCEcho\li busbJava , it's a directory.


    I am not very familiar with java. Does anybody knows what I have to do?

    Thanks very much,

    Leandro.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    Make sure any 3rd party libraries your application requires are on the classpath when you run your jar

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    You mean: Project Properties -> Libraries -> Compile tab -> Add Library?

    That I have already done, but it still doesn't work.

    Do I have to do anything else?

    Thanks for the answer.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    The libraries must on the classpath to both compile and run. If you are getting an exception at runtime, as the exception above indicates, then the problem is with the classpath when running (JVM) not when compiling. Make sure you set the classpath properly when you run the jar

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    Ok, I found the tab Run: Project Properties -> Libraries -> Compile tab -> Add Library /

    But it still makes no difference at all. I still receive the same errors.

    Am I trying to set the classpath in the wrong place?

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    Read post #4: the classpath must be properly set to compile and to run. I do not use Netbeans, but adding libraries under a "Compile Tab" indicates you are doing the former, but not the latter. Either a) Export your jar in such a way that any necessary libraries are packaged and accessible in the deployed jar or b) set the classpath of the jar when you run it so that it knows where the required libraries are.

  7. The Following User Says Thank You to copeg For This Useful Post:

    LeandroRodirgues (October 16th, 2013)

  8. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Program Works on NetBeans, but Jar file doesn't work correctly.

    Hi,

    Sorry, I meant above that I added the library to the Compile and to the Run Tab, but it still did not work. Is there anything else I had to do?

    Or how can be packaged the libraries?

    --- Update ---

    ps. I can work with Eclipse too, if it is easier to help me there...

Similar Threads

  1. Replies: 9
    Last Post: September 15th, 2013, 03:48 PM
  2. Replies: 29
    Last Post: May 18th, 2012, 03:16 PM
  3. Program works fine but with friend it doesn't work
    By Rizza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 1st, 2011, 01:20 PM
  4. JLabel and set Location doesn't work correctly
    By Fantasy in forum AWT / Java Swing
    Replies: 6
    Last Post: November 15th, 2011, 12:02 PM
  5. Code is working in Eclipse but when exported to Runnable Jar doesn't work
    By jjain.jitendra@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 24th, 2011, 08:12 AM

Tags for this Thread