java编译器选项,即javac -d [英] java compiler options i.e. javac -d

查看:571
本文介绍了java编译器选项,即javac -d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编译一个包含语句的程序。
例如。

I'm compiling a program that has a package statement. e.g.

package APPC_LU62.Runtime ;

我还有一个与package语句匹配的预先存在的目录结构。

I also have a pre-existing directory structure that matches the package statement.

C:\APPC_LU62\Runtime

如何让javac编译器在预先存在的目录结构中保持相同的目录结构? ie

How do I keep the javac compiler from creating the same directory structure within the pre-existing one ? i.e.

C:\APPC_LU62\Runtime\APPC_LU62\Runtime   

在我看来,编译器应该足够智能,以便在创建现有目录结构之前首先检查它。

It seems to me the compiler ought to be "smart" enough to check first for an existing directory structure before creating one.

谢谢

推荐答案

一般情况下,编译器需要源文件并输出类文件。包结构。

In general, the compiler expects the source files and outputs the class files according to the package structure.

如果你不提供任何 -sourcepath (或 - classpath 如果没有给出sourcepath选项,则相对于当前目录搜索源文件。如果给出了源路径,则相对于此路径搜索源文件(除了在命令行上直接指定的任何文件)。

If you don't give any -sourcepath (or -classpath if no sourcepath is given) options, the source files are searched relative to the current directory. If a source path is given, the source files are searched relative to this path (in addition to any file directly specified on the command line).

同样,如果你没有不指定任何 -d 选项,类文件将根据包结构放入目录中,相对于当前目录。如果您提供 -d 选项,则类文件将相对于该选项指定的目录放置。这里将创建不存在的目录。

Similarly, if you don't specify any -d options, the class files will be put into directories according to the package structure, relative to the current directory. If you give an -d option, the class files will be put relative to the directory given by the option. Non-existing directories will be created here.

因此,如果要在与源文件相同的目录树中创建输出,通常的方法是要改为这棵树的根(在你的情况下是 C:\ ),然后从那里调用javac:

Thus, if you want to create the output in the same directory tree as your source files are, the usual way to go would be to change into the root of this tree (C:\ in your case), and from there call javac:

javac -classpath ... -sourcepath . APPC_LU62\Runtime\*.java

(或仅列出您实际想要编译的java文件)。或者,您可以添加 -d C:\ -sourcepath C:\ 选项,然后调用来自你想要的命令:

(or list only the java files you actually want to compile). Alternatively, you could add the -d C:\ and -sourcepath C:\ options, and then call the command from whereever you want:

javac -classpath ... -sourcepath C:\ -d C:\  C:\APPC_LU62\Runtime\*.java

以后执行类时有效使用 java 命令:这还要求根据包结构在目录中的类,其中root是类路径中提到的目录或jar文件。因此,您必须将 C:\ 添加到 -class路径中,以获取 java call。

The same is valid later for executing the classes with the java command: This also expects the classes in directories according to the package structure, with the root being a directory or jar file mentioned in the class path. Thus you will have to add C:\ to the -classpath for your java call.

(顺便说一句,我不会使用某个驱动器的根作为包层次结构的根目录 - 更好地移动一个目录的所有内容下来。)

(By the way, I would not use the root of some drive as the root of the package hierarchy - better move everything one directory down.)

这篇关于java编译器选项,即javac -d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆