开发者

java compiler options i.e. 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_LU62\Runtime

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" e开发者_如何学Cnough 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_LU62\Runtime\*.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_LU62\Runtime\*.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.)


Would have been better if you had actually posted your javac command and stated clearly where your sources are located, but here goes anyway: when you issue javac -d somedir blahblah.java, javac will create the appropriate directory structure (matching package name hierarchy) starting at directory somedir.

So in your case, you simply need to do:

javac -d c:\ your_files.java
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜