2014-01-14 1 views
0

maven-dependency-plugin의 사용을 Eclipse가 인식하도록하고 을 실행하여을 WTP를 통해 Tomcat에 배포하기 전에 어떻게해야합니까?이클립스 Respect Maven-Dependency-Plugin

a previous question에서 일부 아티팩트를 war 응용 프로그램에 복사하도록 Maven을 구성 했으므로 웹 클라이언트에 제공 할 수있었습니다. target/${project.artifactId}-${project.version}에 복사하는 방법은 Maven 명령 줄을 통해 패키징 할 때 작동합니다. 안타깝게도 Eclipse의 Tomcat 통합을 사용할 때 그러한 행운은 없습니다.

Maven 플러그인 구성 :

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-dependency-plugin</artifactId> 
<version>2.8</version> 
<executions> 
    <execution> 
     <id>copy</id> 
     <phase>compile</phase> 
     <goals> 
      <goal>copy</goal> 
     </goals> 
     <configuration> 
      <artifactItems> 
       <artifactItem> 
        <groupId>junit</groupId> 
        <artifactId>junit</artifactId> 
        <version>3.8.1</version> 
        <type>jar</type> 
        <overWrite>false</overWrite> 
        <destFileName>optional-new-name.jar</destFileName> 
       </artifactItem> 
      </artifactItems> 
      <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/</outputDirectory> 
      <overWriteReleases>false</overWriteReleases> 
      <overWriteSnapshots>true</overWriteSnapshots> 
     </configuration> 
    </execution> 
</executions> 

답변

1

이 대답은 당신이 메이븐 통합 플러그인 (m2e 및 m2e-WTP)와 함께 제공 이클립스 자바 EE 케플러 SR1 (또는 최근)를 사용하는 가정합니다.

m2e-wtp의 경우 Maven Integration for WTP 플러그인은 maven CLI 빌드를 무시하고 WTP가 알려진 위치의 리소스를 게시하도록 구성합니다.

  • 구성 종속성 일식 동안 알려진 m2e-WTP 위치에 항아리를 복사하는 플러그인
  • 실제로 프로젝트 구성 갱신 중에 종속 플러그인을 실행 m2e에게 빌드 :

    그래서 당신은이 일을 할 필요가 . 메이븐 의존성 - 플러그인 구성, 사용에

    <jars.directory>${project.build.directory}/${project.artifactId}-${project.version}/</jars.directory> 
    

    을 :

먼저 속성 섹션에서 새로운 받는다는 속성을 정의

<outputDirectory>${jars.directory}</outputDirectory> 

은 이제 당신에게 동일을 주어야한다 Maven CLI로 결과를 빌드하십시오. 그런 다음 특정 m2e 프로필을 사용하는 데 필요한 모든 다른 상황에서 이클립스에서 실행 무시하면, 그이 자동으로 활성화됩니다 :

<profiles> 
    <profile> 
     <id>m2e</id> 
     <!-- This profile is only activated when building in Eclipse with m2e --> 
     <activation> 
      <property> 
       <name>m2e.version</name> 
      </property> 
     </activation> 
     <properties> 
      <jars.directory>${project.build.directory}/m2e-wtp/web-resources/</jars.directory> 
     </properties> 
    </profile> 
</profiles> 

마지막으로, 우리는 m2e가 실행 괜찮은지 알려 필요 받는다는-dependency- 플러그인 : 프로젝트 구성 중에 복사하십시오. 업데이트 메이븐 구성 대화 상자를 불러 히트 Alt + F5를하고 확인을 클릭합니다 :

<pluginManagement> 
    <plugins> 
     <!--This plugin's configuration is used to store Eclipse m2e settings 
      only. It has no influence on the Maven build itself. --> 
     <plugin> 
      <groupId>org.eclipse.m2e</groupId> 
      <artifactId>lifecycle-mapping</artifactId> 
      <version>1.0.0</version> 
      <configuration> 
       <lifecycleMappingMetadata> 
        <pluginExecutions> 
         <pluginExecution> 
          <pluginExecutionFilter> 
           <groupId>org.apache.maven.plugins</groupId> 
           <artifactId>maven-dependency-plugin</artifactId> 
           <versionRange>[2.8,)</versionRange> 
           <goals> 
            <goal>copy</goal> 
           </goals> 
          </pluginExecutionFilter> 
          <action> 
           <execute> 
            <runOnConfiguration>true</runOnConfiguration> 
            <runOnIncremental>false</runOnIncremental> 
           </execute> 
          </action> 
         </pluginExecution> 
        </pluginExecutions> 
       </lifecycleMappingMetadata> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

지금, 확인 m2e에 대한 모든 구성 변경 사항을 알고합니다 당신의 pluginManagement 섹션에 다음 코드를 추가합니다. 빌드가 완료되면 Deployed Resources> web-resources의 jar 파일을 프로젝트 탐색기 뷰에 표시해야한다.

이제 Tomcat에 대한 배포는 webapp의 루트에 optional-new-name.jar을 포함해야합니다.

+0

감사합니다. 자세한 내용과 유망 해 보입니다. 나는 그것을 시험해 볼 기회가 있었을 때 알려주지! –