program story

Maven이 컴파일하고 빌드 jar에 포함 할 추가 소스 디렉토리를 추가하는 방법은 무엇입니까?

inputbox 2020. 9. 1. 07:30
반응형

Maven이 컴파일하고 빌드 jar에 포함 할 추가 소스 디렉토리를 추가하는 방법은 무엇입니까?


src / main / java 외에도 빌드 프로세스에 포함하려는 src / bootstrap 디렉토리를 추가합니다. 즉, maven이 소스를 컴파일하고 빌드에 포함하기를 원합니다. 어떻게!?


Build Helper Plugin을 사용할 수 있습니다 . 예 :

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

참고 :이 솔루션은 Java 소스 파일을 target / classes 디렉토리로 이동하고 소스를 컴파일하지 않습니다.

다음으로 업데이트 pom.xml-

<project>   
 ....
    <build>
      <resources>
        <resource>
          <directory>src/main/config</directory>
        </resource>
      </resources>
     ...
    </build>
...
</project>

http://maven.apache.org/guides/mini/guide-using-one-source-directory.html

<build>
<sourceDirectory>../src/main/java</sourceDirectory>

또한 참조

여러 src 디렉토리로 Maven 컴파일


With recent Maven versions (3) and recent version of the maven compiler plugin (3.7.0), I notice that adding a source folder with the build-helper-maven-plugin is not required if the folder that contains the source code to add in the build is located in the target folder or a subfolder of it.
It seems that the compiler maven plugin compiles any java source code located inside this folder whatever the directory that contains them.
For example having some (generated or no) source code in target/a, target/generated-source/foo will be compiled and added in the outputDirectory : target/classes.


You can add the directories for your build process like:

    ...
   <resources>
     <resource>
       <directory>src/bootstrap</directory>
     </resource>
   </resources>
   ...

The src/main/java is the default path which is not needed to be mentioned in the pom.xml

참고URL : https://stackoverflow.com/questions/9752972/how-to-add-an-extra-source-directory-for-maven-to-compile-and-include-in-the-bui

반응형