仅在 Maven 中编译选定的文件 [英] Compiling only selected files in Maven

查看:32
本文介绍了仅在 Maven 中编译选定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想编译源目录中选定的文件或目录(包括子目录).我很确定我可以使用 <includes>maven-compiler-plugin 的配置来做到这一点,但它似乎不像我期望的那样工作,因为它仍然可以编译将所有类放入 target/classes.真正奇怪的是,Maven 输出表明该设置实际上起作用了,因为:

I want to compile only selected files or directories (including subdirectories) within source directory. I was pretty sure I can do this using <includes> of maven-compiler-plugin's configuration, but it seems to not work as I expect since it still compiles all classes into target/classes. What is really strange, Maven output suggest that the setting actually does its work, because with:

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
      <includes>
        <include>com/example/dao/bean/*.java</include>
      </includes>
    </configuration>
  </plugin>

我有:

[INFO] Compiling 1 source file to c:Projects	est	argetclasses

但我没有编译器的配置:

but with no compiler's configuration I have:

[INFO] Compiling 14 source file to c:Projects	est	argetclasses

然而,在这两种情况下,所有 14 个类都被编译为我提到的 target/classes.您能否解释一下或建议另一种仅编译选定文件的解决方案?

In both cases however, all 14 classes are compiled into target/classes as I mentioned. Can you explain that or suggest another solution to compile only selected files?

推荐答案

具有 3 个类的简单应用程序.

Simple app with 3 classes.

com/company/Obj1.java
com/company/Obj2.java
com/company/inner/Obj3.java  

buildpom.xml

<build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>2.0.2</version>
               <configuration>
                  <source>1.6</source>
                  <target>1.6</target>
                  <includes>
                     <include>com/company/inner/*.java</include>
                  </includes>
               </configuration>
            </plugin>
          </plugins>

   </build>  

结果:编译了 1 个类.
并且包含的​​任何组合都运行良好
或者你的意思是别的?

result: 1 class is compiled.
And any combination of includes is working well
or you mean something else?

这篇关于仅在 Maven 中编译选定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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