我是靠谱客的博主 拼搏小笼包,最近开发中收集的这篇文章主要介绍java 编译选项,java编译器选项,即javac -d,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

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.

Thanks

解决方案

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

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).

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.

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

(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

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 编译选项,java编译器选项,即javac -d的全部内容,希望文章能够帮你解决java 编译选项,java编译器选项,即javac -d所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部