如何从第三方jar中排除Java源代码? [英] how to exclude java sources from a third party jar?

查看:348
本文介绍了如何从第三方jar中排除Java源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java项目中也有一个jar依赖项,其中也包含源代码,当我运行mvn compile时,这些java源代码在我的已编译maven输出中显示为类文件:(... 如何排除这些文件..(我只希望将自己的已编译文件显示在已编译的输出中)

I have one jar dependency in my java project that contains sources as well and when I run mvn compile, these java sources appear as class files in my compiled maven output :(... How can I exclude these files.. (I only want my own compiled files in the compiled output)

我尝试过类似的事情:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-compiler-plugin</artifactId>
 <version>2.1-SNAPSHOT</version>
 <configuration>
  <excludes>
    <exclude>**/bv/**/*.java</exclude>
   </excludes>
 </configuration>
</plugin>

玩过它,但是它们一直出现在我的Maven编译输出中:( ..

Played with it but they keep appearing in my maven compiled output :( ..

任何主意吗?

推荐答案

我的理解是,这是

My understanding is that this is a normal behavior of javac that searches the whole classpath for source files to compile unless the -sourcepath option is given (and this would be the solution here).

不幸的是,存在一个有关Maven编译器插件未将-sourcepath传递给javac的Jira问题(请参见 MCOMPILER-98 ),但是有一种解决方法.所以,请您尝试一下:

Unfortunately, there is a Jira issue about -sourcepath not being passed to javac by the Maven Compiler Plugin (see MCOMPILER-98) but there is a workaround. So, could you please try this:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <compilerArguments>
      <sourcepath>${project.basedir}/src/main/java</sourcepath>
    </compilerArguments>
  </configuration>
</plugin>

这篇关于如何从第三方jar中排除Java源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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