简体   繁体   English

如何在 Windows 命令行中使用外部库编译 Java 类?

[英]How to compile Java class with external library in Windows command line?

I have an assignment: Write a client program Permutation.java that takes an integer k as a command-line argument;我有一个作业:编写一个客户端程序Permutation.java ,它接受一个整数k作为命令行参数; reads in a sequence of strings from standard input using StdIn.readString() ...使用StdIn.readString()从标准输入读取字符串序列...

Here is my code:这是我的代码:

public class Permutation {
    public static void main(String[] args) {
         int k = Integer.parseInt(args[0]);
         String[] inputStrings = StdIn.readStrings();
    }
}

How to compile it in Windows command line?如何在 Windows 命令行中编译它?

I tried我试过

javac Permutation.java

But got an error但是出错了

error: cannot find symbol String[] inputStrings = StdIn.readStrings();`

I use IntelliJ IDEA, external library StdIn is added to the project.我使用 IntelliJ IDEA,将外部库 StdIn 添加到项目中。

To compile it with the library you have to add it to the classpath.要使用库编译它,您必须将其添加到类路径中。 This is accomplished with the -cp argument followed by the library which contains your referenced class.这是通过 -cp 参数后跟包含您引用的类的库来完成的。

javac -cp StdIn.jar Permutation.java

To run it with command line, similarly use要使用命令行运行它,同样使用

java -cp StdIn.jar Permutation

See also https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html另请参阅https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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