简体   繁体   English

Eclipse Java Project和Maven的多个源文件夹

[英]Multiple Source Folders for Eclipse Java Project & Maven

Question/Problem: 问题/问题:

How to add an additional source folder to a standard java console Maven project using Eclipse (Luna) so that Maven sees the path for jar build. 如何使用Eclipse(Luna)将其他源文件夹添加到标准Java控制台Maven项目中,以便Maven看到jar构建的路径。

The expected result is to somehow configure pom.xml so that Maven plugins in Eclipse can be executed cleanly. 预期的结果是以某种方式配置pom.xml,以便可以干净地执行Eclipse中的Maven插件。

Assumptions - a successful add of an additional source folder via project (right click) -> new -> source folder. 假设-通过项目成功添加了另一个源文件夹(右键单击)->新建->源文件夹。

To let Maven know about the new source folder for building a jar I had to add the following to my pom.xml: 为了让Maven知道用于构建jar的新源文件夹,我必须在pom.xml中添加以下内容:

  <build>
   <pluginManagement>
    <plugins>
     <plugin>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>2.5.1</version>
          <configuration>
            <includes>
              <include>[your source folder goes here]/**/*.java</include>
            </includes>
          </configuration>          
     </plugin>                
     <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>build-helper-maven-plugin</artifactId>
       <version>1.9.1</version>
       <executions>
         <execution>
           <id>add-source</id>
           <phase>generate-sources</phase>
           <goals>
             <goal>add-source</goal>
           </goals>
           <configuration>
             <sources>
                <source>[your source folder goes here]</source>
             </sources>
           </configuration>
         </execution>
       </executions>
     </plugin>
    </plugins>      
   </pluginManagement>
  </build>

Be sure to add the pluginManagement tags around plugins as omitting this tag prevented the mojo plugin to recognize the executions tag. 确保在插件周围添加pluginManagement标签,因为省略该标签会阻止mojo插件识别执行标签。

Perhaps more later on the success of the actual jar construction... 也许以后会更成功地进行罐子的建造...

Add generated sources into configuration of maven-compiler-plugin: 将生成的源添加到maven-compiler-plugin的配置中:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <generatedSourcesDirectory>[additional directory]</generatedSourcesDirectory>
    </configuration>
</plugin>

or provide additional execution: 或提供其他执行:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
        <execution>
            <id>compile-additional-sources</id>
            <goals><goal>compile</goal></goals>
            <configuration>
                <source>[additional sources]</source>
            </configuration>
        </execution>
    </executions>
</plugin>

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

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