简体   繁体   中英

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; reads in a sequence of strings from standard input using 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?

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.

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.

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

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