简体   繁体   中英

reference a class that uses a third-party library in Java

I have a class which uses a import from third-party library

import org.apache.commons.lang3.*;        
public  class test2 {
    public void printing() {
        System.out.println(StringUtils.capitalize("hello test2"));
    }
    public static void main(String[] args) {}
}

I have a second class in the same directory

public class test {
    public static void main(String[] args) {
        System.out.println("hello test1");
        test2 t = new test2();
        t.printing();
    }
}

I have tried compiling using these commands

cmd> javac -cp "./lib/commons.jar" test.java
cmd> javac test.java

but both gives an error : error: cannot find symbol test2 t = new test2();

How will I be able to reference a class that uses a third-party library

Note: the first-class compiles separate on its own without problems.also compiles if i remove importing external jar from first class .the external jar file is in lib folder in the same directory

link for .jar I used: https://www-us.apache.org/dist//commons/lang/binaries/commons-lang3-3.9-bin.zip

在此处输入图片说明 Above is my folder structure and compiled classes.

I have slightly Change your test2.java file here is the updated code

import org.apache.commons.lang3.*;        
public class test2 {
    public void printing() {
        System.out.println(StringUtils.capitalize("hello test2"));
    }
}

and here is the command javac -cp "lib/common-lang3.jar" test2.java let me know if this doesn't work even javac test.java is also working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM