2013-07-09 2 views
3

동일한 pom 파일에서 두 개의 jar 파일을 만들려고합니다 (예 : this Sonotype blog post은 읽지 않았습니다). 왜냐하면 우리가 모든 자원을 필요로하고 내부적 인 이유없이 하나를 필요로하기 때문입니다. 이 작동해야한다고 생각하는 구성으로 maven-jar-plugin을 구성했지만 리소스는 항상 포함됩니다. 우리가 만들 때maven-jar-plugin 제외 실패

<plugins> 
    <plugin> 
     <artifactId>maven-jar-plugin</artifactId> 
     <executions> 
      <execution> 
       <id>package-consumer</id> 
       <phase>package</phase> 
       <configuration> 
        <classifier>consumer</classifier> 
        <resources> 
         <resource> 
          <directory>src/main/resources</directory> 
          <filtering>true</filtering> 
          <excludes> 
           <exclude>**/*.bmp</exclude> 
           <exclude>**/*.jpg</exclude> 
           <exclude>**/*.jpeg</exclude> 
           <exclude>**/*.gif</exclude> 
           <exclude>**/*.xml</exclude> 
           <exclude>**/*.sql</exclude> 
           <exclude>**/*.log4j</exclude> 
           <exclude>**/*.properties</exclude> 
           <exclude>**/*.sh</exclude> 
          </excludes> 
         </resource> 
        </resources> 
       </configuration> 
       <goals> 
        <goal>jar</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 
</plugins> 

, 우리는 OurProject.Jar 및 OurProject - consumer.jar 한 기대로 얻을 수 있지만, 모두 같은 자원을 각 jar 파일에 있습니다 여기에 우리의 POM 파일의 관련 부분이다.

목록이나 특정 확장자 대신 <exclude>**/*</exclude><exclude>**/resources/*.*</exclude>을 시도했습니다. 기쁨이 없습니다. 나는 우리가 뭔가를 놓치기를 바라고 있습니다.

답변

4

소비자 용기에 maven-assembly-plugin을 사용하는 것이 좋지만 maven-jar-plugin을 사용하기로 결정 했으므로 빌드를 수정합시다.

여기서 문제는 being filtered의 리소스가 실제로 jar의 리소스를 제외하는 설정 (모두 <exclude /> 태그 사용)을 방해한다는 설정입니다.

다음 구성 (<plugins />)은 패키지 단계에서 jar:jar에 대한 두 번째 호출을 트리거합니다. 그것은 (효과적으로 당신이 원하는 일을) 소비자 항아리에서 원하는 자원을 제외됩니다 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.4</version> 
    <executions> 
     <execution> 
     <id>package-consumer</id> 
     <phase>package</phase> 
     <goals> 
      <goal>jar</goal> 
     </goals> 
     <configuration> 
      <classifier>consumer</classifier> 
      <excludes> 
      <exclude>**/*.bmp</exclude> 
      <exclude>**/*.jpg</exclude> 
      <exclude>**/*.jpeg</exclude> 
      <exclude>**/*.gif</exclude> 
      <exclude>**/*.xml</exclude> 
      <exclude>**/*.sql</exclude> 
      <exclude>**/*.log4j</exclude> 
      <exclude>**/*.properties</exclude> 
      <exclude>**/*.sh</exclude> 
      </excludes> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

(<resources /> 내부)이 구성 필터링 XML에 대한 (즉, 속성은 프로세스 자원 단계에서 resource:resource를 사용하여 교체) 및 수 있지만 특성 파일; 이미지와 다른 바이너리 파일은 변경되지 않고 복사됩니다.

<resource> 
    <directory>src/main/resources</directory> 
    <filtering>true</filtering> 
    <includes> 
     <include>**/*.xml</include> 
     <include>**/*.properties</include> 
    </includes> 
    </resource> 
    <resource> 
    <directory>src/main/resources</directory> 
    <filtering>false</filtering> 
    <excludes> 
     <exclude>**/*.xml</exclude> 
     <exclude>**/*.properties</exclude> 
    </excludes> 
    </resource> 

두 구성을 모두 사용하면 실제로 두 개의 병이 만들어집니다. 모든 자원 (필터링 된 xml 및 특성 파일 포함) 및 자원이없는 2 차 소비자 jar의 기본값.

+0

감사합니다. 태그를 밖으로 이동하면 문제가 해결됩니다. 우리 항아리가 없으므로 태그 블록의 필요성을 이해하지 못합니다. – cneff

+0

우리가 만난 또 다른 경고 : 우리가 프리스트 (frist)가 변경을 가했을 때, 소비자 용 병에서 POM 파일을 제외 시켰기 때문에 consuer jar의 내용이 변경되지 않았으므로 다시 작성하지 않았습니다! 말할 필요도없이 두 개의 jar 파일에서 다른 타임 스탬프를 발견 할 때까지 혼란과 좌절감이 생겼습니다. – cneff

+0

두 번째 설정은 파일 확장자 집합에 대해 [필터링] (http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html)을 활성화하는 것입니다 (다른 자원은 변경하지 않고 복사) . 원래 ' true'때문에 필터링이 필요하다고 가정했습니다. pom.xml에 관해서는 다시 원하면 ' **/*. xml'패턴을 다시 생각해 볼 필요가 있습니다. –

2

나는이처럼 만들기 위해 제안 : 안토니 - Acioly @

<build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <executions> 
      <execution> 
      <id>second-jar</id> 
      <goals> 
       <goal>jar</goal> 
      </goals> 
      <configuration> 
       <classifier>without</classifier> 
       <excludes> 
       <exclude>**/*</exclude> 
       </excludes> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 
+0

물론 제외 섹션을 교체하십시오 (그렇지 않으면 빈 항아리가 생성됩니다). –

+0

@khmarbaise 빠른 답변 감사합니다! Anthony의 편집을 염두에두고, 그 해결책이 효과가있었습니다. – cneff