This discussion is archived
3 Replies Latest reply: Apr 17, 2013 5:18 AM by gimbal2 RSS

How to install a library

1003483 Newbie
Currently Being Moderated
Hello, I have a question.
I want to install a library. I downloaded the library (http://jcommander.org/#Download) and compiled it. Now I ended up with a directory with classes and jar files.
I hear I need to move the folder to /usr/lib/jvm/java-6-openjdk-i386/jre/lib/ext ... And when I tried to compile a .java file requiring the jcommander, the compiler says the module cannot be found. .... I spend an hour to find ways to install it but, I couldn't... Could you give me a hint/answers/ideas..

Thank you!
  • 1. Re: How to install a library
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!
    >
    I want to install a library. I downloaded the library (http://jcommander.org/#Download) and compiled it. Now I ended up with a directory with classes and jar files.
    I hear I need to move the folder to /usr/lib/jvm/java-6-openjdk-i386/jre/lib/ext ... And when I tried to compile a .java file requiring the jcommander, the compiler says the module cannot be found. .... I spend an hour to find ways to install it but, I couldn't... Could you give me a hint/answers/ideas..
    >
    If the classes/jars cannot be found then they are not on the classpath and/or your 'java' source does not import the required classes.

    Even classes from modules that are part of Java need to be imported in order to be used.

    Have you written Java applications before? Are you using a GUI development environment?

    If not I suggest you download NetBeans and start working your way through the Java Tutorials
    http://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html

    https://netbeans.org/downloads/
  • 2. Re: How to install a library
    939520 Explorer
    Currently Being Moderated
    I'm not familiar with the jar file you mentioned, but I suspect it should be installed in your project and not as part of the jvm (/usr/lib/jvm/java-6-openjdk-i386/jre/lib/ext).

    If your project is netbeans, you add this to your pom.xm, the right click on the project icon and select 'build with dependencies'. The jar will be downloaded by maven (you don't have to manually download it), and installed in the classpath. Similarly for Eclipse.
     
            <dependency> 
                <groupId>org.apache.cxf;/groupId> 
                <artifactId>cxf-rt-frontend-jaxrs</artifactId> 
                <version>2.4.1;/version> 
            </dependency> 
    If your project is not maven, you have a folder in your project typically called 'lib' with your jar files there.
    Then for netbeans, right click on the project icon and select 'properties'. The select the 'library' link, then click the 'Add Library' button, then navigate to the location of your jar files and add all them. Recompile and all should work.
    For Eclipse, right click on the project icon, then properties->Java Build Path->Libraries->Add Jars
  • 3. Re: How to install a library
    gimbal2 Guru
    Currently Being Moderated
    1000480 wrote:
    I hear I need to move the folder to /usr/lib/jvm/java-6-openjdk-i386/jre/lib/ext ...
    HELL - NO.

    The usage of the word "install" in this thread is highly confusing and utterly wrong. You - do - not - install - jars. You don't. There is no installation to be done. The only thing that needs to happen is that the java runtime is made aware of its existence by including the jar in the classpath. The classpath is a thoroughly documented concept which you can easily google and find in any book (even Java for Dummies I reckon), and your IDE's manual or online documentation should be able to tell you how to manage the classpath of a project properly.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points