从命令行编译 [英] Compiling from the command line
问题描述
我试图了解从命令行编译时 -classpath
选项的工作方式.
I'm trying to understand how works the option -classpath
when compiling from command line.
我从 mydirectory
的父级尝试:
javac -cp mydirectory/subdir Hello.java
javac -cp mydirectory/subdir Hello.java
但是编译器说:
javac:没有源文件
javac: no sources files
-cp
( -classpath
)如何工作?我在做什么错了?
How does -cp
(-classpath
) work?? What am I doing wrong?
如果我是从 subdir
目录创建的,则为:
If I make it from subdir
directory:
javac Hello.java
javac Hello.java
然后正确编译.
推荐答案
javac TestProgram1.java TestProgram2.java TestProgram3.java
您可以使用通配符来编译文件夹中的所有文件,如下所示:
You can use a wildcard to compile all the files in a folder, like this:
javac *.java
如果您需要同时编译大量文件,但又不想使用通配符(也许您希望编译大量文件,但不是文件夹中的所有文件),则可以创建一个参数文件,列出要编译的文件.在参数文件中,您可以根据需要键入任意多个文件名,并使用空格或换行符将它们分开.这是一个名为TestPrograms的参数文件,其中列出了三个要编译的文件:
If you need to compile a lot of files at the same time but don’t want to use a wildcard (perhaps you want to compile a large number of files but not all the files in a folder), you can create an argument file, which lists the files to compile. In the argument file, you can type as many filenames as you want, using spaces or line breaks to separate them. Here’s an argument file named TestPrograms that lists three files to compile:
TestProgram1.java
TestProgram2.java
TestProgram3.java
您可以使用@字符编译该文件中的所有程序,然后在javac命令行上使用自变量文件的名称进行编译,如下所示:
You can compile all the programs in this file by using an @ character, followed by the name of the argument file on the javac command line, like this:
javac @TestPrograms
-cp和-classpath
指定在哪里可以找到用户类文件.如果您的程序使用了存储在单独文件夹中的类文件,请使用此选项.
Specifies where to find user class files. Use this option if your program makes use of class files that you’ve stored in a separate folder.
这篇关于从命令行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!