[英]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();但两者都给出了一个错误:错误:找不到符号 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注意:一流的单独编译没有问题。如果我从一流的中删除导入外部 jar,也会编译。外部 jar 文件位于同一目录的 lib 文件夹中
link for .jar I used: https://www-us.apache.org/dist//commons/lang/binaries/commons-lang3-3.9-bin.zip我使用的 .jar 链接: 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我稍微改变了你的 test2.java 文件,这里是更新的代码
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这是命令
javac -cp "lib/common-lang3.jar" test2.java
如果这不起作用,即使javac test.java
也在工作,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.