javac的classpath和sourcepath选项之间的差异 [英] Differences between classpath and sourcepath options of javac

查看:464
本文介绍了javac的classpath和sourcepath选项之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了Sun文档和Stack Overflow上的很多帖子,但我仍然困惑于Java编译器选项之间的区别 -cp -sourcepath

I read the Sun documentation and a lot of posts on Stack Overflow, but I'm still confused about the differences between the Java compiler options -cp and -sourcepath.

假设我有这个目录结构:

Let say I have this directory structure:

c:\Java\project1\src (where the Java source files are)  
c:\Java\project1\bin (where the Java class files will be or already are)  

让我们说一个包中有一个源文件 MainClass.java c $ c> com.mypackage ,并且目录结构在源文件夹中确定。

Let's also say I have a source file MainClass.java in a package com.mypackage, and that the directory structure is ok in the source folder.

我在 project1 目录并运行:

javac -d bin -sourcepath src src/com/mypackage/MainClass.java  

javac -d bin -classpath src src/com/mypackage/MainClass.java  

获得相同的结果。在详细模式下,源文件的搜索路径在这两种情况下都是 src

and I obtain the same result. In verbose mode, the search path for source files is src in both cases.

如果任何人可以帮助我找出这些选项的细节,这将是巨大的。

It would be great if anybody could help me figure out the specifics of these options.

推荐答案

 -classpath classpath

用户类路径,覆盖CLASSPATH环境变量中的用户类路径。如果未指定CLASSPATH或-classpath,则用户类路径由当前目录组成。

Set the user class path, overriding the user class path in the CLASSPATH environment variable. If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory.

如果未指定-sourcepath选项,则将搜索用户类路径以查找源文件和类文件。

If the -sourcepath option is not specified, the user class path is searched for source files as well as class files.


-sourcepath sourcepath


指定搜索类或接口定义的源代码路径。与用户类路径一样,源路径条目由分号(;)分隔,并且可以是目录,JAR归档或ZIP归档。如果使用软件包,目录或归档中的本地路径名必须反映软件包名称。

Specify the source code path to search for class or interface definitions. As with the user class path, source path entries are separated by semicolons (;) and can be directories, JAR archives, or ZIP archives. If packages are used, the local path name within the directory or archive must reflect the package name.

请注意,通过类路径找到的类,被发现。

Note that classes found through the classpath are subject to automatic recompilation if their sources are found.

这篇关于javac的classpath和sourcepath选项之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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