2010-11-22 4 views
8

나는 ant을 사용하는 프로젝트를 진행하고 있습니다. 기본적으로 jar을 먼저 수행 한 다음 대상을 디렉터리에 설치하는 대상이 dist입니다.'dist'와 비슷한 목표가 있습니까?

즉, 설치 디렉토리에 bin/, lib/config/과 같은 디렉토리를 만든 다음 관련 파일을 각 디렉토리에 복사합니다.

내 질문은 두 가지 :

  1. 이런 종류의 일을 않는 받는다는 목표는 있습니까?
  2. 그렇지 않은 경우 maven dist을 수행하고 싶습니다. Maven을 사용하여이 작업을 수행하는 방법을 제안 하시겠습니까?
  3. 내가 "목표"(dist와 같은)를 가질 수 없다면, 가장 좋은 방법은 무엇일까요?

결론 : 나는 모든이 작업을 수행 할 수 있지만, 등 컴파일 및 패키지처럼

감사합니다, 기본 "대상"의 동작을 변경하지 않으 JRH

PS : 나는 config에 갈 것 모르는 받는다는 버전 2.2.21

답변

6

를 사용하고 있지만, libbin가 쉽습니다. copy all dependencies to a folder으로

바로이 작업을 수행 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>copy-dependencies</id> 
      <phase>package</phase> 
      <goals> 
       <goal>copy-dependencies</goal> 
      </goals> 
      <configuration> 
       <outputDirectory> 
       ${project.build.directory}/dist/lib 
       </outputDirectory> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

를 출력하려면 당신의 항아리 빈 (bin) 폴더로 할이 (reference page) :

:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <configuration> 
     <finalName>${project.artifactId}</finalName> 
     <outputDirectory>${project.build.directory}/dist/bin</outputDirectory> 
    </configuration> 
</plugin> 

아, 추가 요구 사항이 있습니다

결론 : 나는이 모든 것을하고 싶지만 c와 같은 기본 "목표"의 동작을 변경하고 싶지는 않습니다. 당신은 추가하지 않는 경우 DIST 디렉토리를 얻을 이제 mvn clean package -Pdist 할 것

<profile> 
    <id>dist</profile> 
    <build> 
     <plugins> 
      <!-- insert stuff from above here --> 
     </plugins> 
    </build> 
</profile> 

과 : ompile이 경우 패키지 등

내가 이걸 설정하는 프로파일을 사용하십시오 프로필을 사용하면 기본 동작을 얻습니다.

기본적으로 상황은 개미에서와는 다르게 작동합니다. 타겟이 없으며 라이프 사이클 단계와 플러그인 목표 만 있습니다. 당신이 mvn compile을 할 경우

당신이이 일에 모든 단계에 바인딩 된 모든 Maven 플러그인 목표를 호출 라이프 사이클 단계를 실행할 수 있습니다 (예는 다음과 같은 단계가 실행됩니다 validate, initialize, generate-sources, process-sources , generate-resources, process-resources, compile). 그러나 dist이라는 수명주기 단계를 정의하는 (쉬운) 방법은 없습니다.

또는 특정 플러그인 목표를 실행할 수 있습니다 (실제로 여러 단계 및/또는 플러그인 목표를 실행할 수 있음). 예 : 당신은 자신의 dist 플러그인을 작성하여 mvn dist:dist을 사용하여 호출 할 수 있지만 기존 기능을 사용하고 있으며 프로파일 솔루션이 꽤 적합해야하기 때문에 필자는 권장하지 않습니다.

+0

괜찮습니까? 그렇다면이 행동은 어떻게 시작될까요? 'mvn 패키지'를 실행합니까? 나는 'maven dist'와 같은 것을하고 싶고 이것을 (문제를 해결하기 위해) 업데이트하려고합니다. 가능한가? – jrharshath

+0

+1 흠, 도움이됩니다. 질문 : 패키지 수명주기 또는 배포에서 수행해야하는 작업을해야합니까? 그리고 왜? – jrharshath

+0

@simpatico이 질문에 대한 의견이 아닌 것 같아요, 제 대답은 아닙니다, 맞습니까? –

0

당신은 (숀에 의해 제안, 또는 mvn clean package -Pdist) 당신이 mvn install -Pdist으로 실행하는 custom actiondist를 만들 수 있습니다 (I 믿고 다른 IDE) 넷빈즈와 maven dist을 가질 수 없습니다.

1

assembly plugin에 대해 assembly descriptor (또는 적합한 google을 검색하십시오.)을 써보세요. 이

<assembly 
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation= 
    "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 
     http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 

    <id>dist</id> 
    <formats><format>zip</format></formats> 

    <fileSets> 
    <fileSet> 
     <directory>src/main/config</directory> 
     <outputDirectory>config</outputDirectory> 
     <useDefaultExcludes>true</useDefaultExcludes> 
    </fileSet> 
    </fileSets> 

    <files> 
    <file> 
     <source>${project.build.directory}/${project.artifactId}.jar</source> 
    </file> 
    </files> 

    <dependencySets> 
    <dependencySet> 
     <useProjectArtifact>false</useProjectArtifact> 
     <outputDirectory>lib</outputDirectory> 
    </dependencySet> 
    </dependencySets> 
</assembly> 

같은

무언가가 당신의 target 디렉토리 안에 ${project.artifactId}-dist.zip를 생성합니다. zip 파일이

어셈블리 플러그인은 압축 파일을 만들 것처럼 보이는
yourProjectName/ 
yourProjectName/config/... 
yourProjectName/lib/... 
yourProjectName/${project.artifactId}.jar 

처럼 배치됩니다, 그냥 dist 폴더에 복사하지 않습니다.

1

숀 대답은 좋았고, 나는 appassembler 플러그인 http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/에 대해 알기 전까지 거의 그것을 찾았다.

는 예를 https://github.com/khmarbaise/maven-training/tree/master/502-assembly-plugin

그것은 패키지 라이프 사이클의 일부로이라고 여기를 참조하십시오.

<build> 
<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>2.3.2</version> 
    <configuration> 
     <source>1.6</source> 
     <target>1.6</target> 
    </configuration> 
    </plugin> 
    <plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>appassembler-maven-plugin</artifactId> 
    <version>1.1</version> 
    <executions> 
     <execution> 
     <phase>prepare-package</phase> 
     <goals> 
      <goal>assemble</goal> 
     </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <binPrefix>utility</binPrefix> 
     <assembleDirectory>${project.build.directory}/appassembler</assembleDirectory> 
     <extraJvmArguments>-Xms512m -Xmx1024m</extraJvmArguments> 
     <generateRepository>false</generateRepository> 
     <repositoryName>lib</repositoryName> 
     <repositoryLayout>flat</repositoryLayout> 
     <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath> 
     <platforms> 
     <platform>windows</platform> 
     <platform>unix</platform> 
     </platforms> 
     <programs> 
     <program> 
      <mainClass>com.soebes.tools.cli.UtilityCLI</mainClass> 
      <name>utility</name> 
     </program> 
     </programs> 
    </configuration> 
    </plugin> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.2</version> 
    <configuration> 
     <descriptors> 
     <descriptor>src/main/assembly/bin.xml</descriptor> 
     <descriptor>src/main/assembly/bin-unix.xml</descriptor> 
     <descriptor>src/main/assembly/src.xml</descriptor> 
     </descriptors> 
     <tarLongFileMode>gnu</tarLongFileMode> 
    </configuration> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 
</plugins> 

디스크립터 그것을 참조는 상당히 straigtforward이며, 그것은 또한 당신이 당신의 응용 프로그램을 실행하기위한 배치와 쉘 스크립트를 생성합니다!

관련 문제