简体   繁体   English

javac意外扩展在我的类路径中找到的jar

[英]javac unexpectedly expanding jars found in my classpath

I'm running into some curious behavior that I haven't seen before with javac and am wondering what I may be doing differently this time to cause it. 我遇到了一些我以前用javac从未见过的奇怪行为,并且想知道这次可能会做些不同的事情来导致它。

I'm compiling a relatively simple application with javac. 我正在用javac编译一个相对简单的应用程序。 The application depends on a handful of libraries that I refer to in the class path argument. 该应用程序依赖于我在类路径参数中引用的少数库。

The after successfully compiling (albeit with some warnings that I believe are from the libs) I end up with a large amount of .class files that seem to have been extracted from the jar files in my library folder. 成功编译之后(尽管我相信有些警告来自libs),最终我得到了大量的.class文件,这些文件似乎是从我的库文件夹中的jar文件中提取的。

I've never seen javac expand my libraries like this and would like to keep it from doing this. 我从未见过javac会像这样扩展我的库,并希望阻止它执行此操作。 My only hypothesis is that wildcarding in the classpath may behave differently than explicitly referring to each jar separately. 我唯一的假设是,类路径中的通配符的行为可能不同于显式地分别引用每个jar的行为。

Below is the folder structure: 下面是文件夹结构:

/loadtest
/loadtest/lib
/loadtest/lib/selenium
  <some jars here>
/loadtest/lib/selenium/libs
  <some jars here>
/loadtest/src
/loadtest/src/com/example/test
  <my java files here>

Here is the javac command I'm issuing from /loadtest/src 这是我从/ loadtest / src发出的javac命令

javac -classpath .;../lib/*;../lib/selenium/*;../lib/selenium/libs/* com/example/test/AdobeSSOLoadTester.java

Any ideas would be appreciated. 任何想法,将不胜感激。 It's obviously not a show stopper, but it is turning my simple build into an unnecessarily complicated mess. 显然,这不是秀场停止,但它将我的简单构建变成了不必要的复杂混乱。 Thanks! 谢谢!

I don't think is a problem with javac at all, but rather with the build classpath that you have. 我认为javac根本不是问题,而是您拥有的构建类路径。 I suspect that you have some JARs with sources in your classpath, most notably selenium-java-xyz-srcs.jar in your /loadtest/lib/selenium directory. 我怀疑您的类路径中有一些带有源的JAR,尤其是/loadtest/lib/selenium目录中的selenium-java-xyz-srcs.jar

Since you haven't specified a -sourcepath argument in your javac invocation, the Oracle/Sun compiler will also search your user classpath for source files, as noted in the javac technote : 由于您未在javac调用中指定-sourcepath参数,因此,如javac技术说明中所述,Oracle / Sun编译器还将在用户类路径中搜索源文件:

Standard Options 标准选项

... ...

-cp path or -classpath path -cp路径或-classpath路径

Specify where to find user class files, and (optionally) annotation processors and source files. 指定在何处查找用户类文件,以及(可选)注释处理器和源文件。 This classpath overrides the user class path in the CLASSPATH environment variable. 该类路径将覆盖CLASSPATH环境变量中的用户类路径。 If neither CLASSPATH, -cp nor -classpath is specified, the user class path consists of the current directory. 如果未指定CLASSPATH,-cp或-classpath,则用户类路径由当前目录组成。 See Setting the Class Path for more details. 有关更多详细信息,请参见设置类路径。

If the -sourcepath option is not specified, the user class path is also searched for source files. 如果未指定-sourcepath选项,则还将在用户类路径中搜索源文件。

... ...

-sourcepath sourcepath -sourcepath源路径

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 . 与用户类路径一样,源路径条目之间用分号(;)分隔,并且可以是目录,JAR存档或ZIP存档 If packages are used, the local path name within the directory or archive must reflect the package name. 如果使用软件包,则目录或归档文件中的本地路径名必须反映软件包名称。 Note: Classes found through the classpath may be subject to automatic recompilation if their sources are also found. 注意:如果通过类路径找到的类也可以找到它们的源,则它们可能会自动重新编译。 See Searching For Types. 请参阅搜索类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM