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

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

问题描述

我正在编译一个带有 package 语句的程序.例如

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

package APPC_LU62.Runtime ;

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

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

C:APPC_LU62Runtime

如何防止 javac 编译器在预先存在的目录结构中创建相同的目录结构?即

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

C:APPC_LU62RuntimeAPPC_LU62Runtime   

在我看来,编译器应该足够聪明",可以在创建之前先检查现有目录结构.

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: in你的情况),然后从那里调用 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_LU62Runtime*.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_LU62Runtime*.java

同样适用于后面使用java命令执行类:这也需要根据包结构目录中的类,根是类中提到的目录或jar文件小路.因此,您必须为 java 调用将 C: 添加到 -classpath.

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天全站免登陆