programing

maven jar-with-dependencies의 이름을 변경할 수 있습니까?

randomtip 2022. 9. 1. 22:43
반응형

maven jar-with-dependencies의 이름을 변경할 수 있습니까?

현재 의존성이 있는 항아리를 사용해서 그런 항아리를 만들고 있습니다.하지만 제 항아리 이름이 좀 길어요.

AS400의 RPG 프로그램에서 사용하고 있기 때문에, 그 개발자의 생활을 조금 더 편하게 할 수 있도록 단축하고 싶습니다.손으로 것 을 통상적인 으로 바꿀 project-name-version-classifier-jar-with-dependencies.jar★★★★★★와 같은 것을 project-name-version-classifier-full.jar

기본적으로 jar-with-dependencies 어셈블리 기술자를 복사하여 full이라고 부르지 않고 이 작업을 수행할 수 있는 방법이 있습니까?

또한 classpath를 조립하지 않고 저장소에 저장하여 jar를 계속 유지하고 싶습니다.

나는 두 개의 유물이 필요하다.내 분류기가 있는 항아리에 건설할 지역을 담았어지역도 포함한 모든 종속성을 포함하는 항아리.

project-name-version-region-full.jar ★★★★★★★★★★★★★★★★★」project-name-version-region.jar저장소에 저장해야 합니다.첫 번째 예에서는 분류자가 지역 전체이고 두 번째 예에서는 해당 지역입니다.후자는 효과가 있다.

finalName 속성을 지정하여 jar에 원하는 이름을 붙이고 append AssemblyId를 false로 지정하여 jar-with-dependencies를 피할 수 있습니다.

다음 구성에서는 "test.jar"라는 이름의 jar가 출력됩니다.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <finalName>test</finalName>
        <appendAssemblyId>false</appendAssemblyId>
      </configuration>
    </execution>
  </executions>
</plugin>

업데이트: 코멘트에 의하면, 임베디드 디스크립터를 사용하는 것은 동작하지 않습니다.어셈블리 플러그인의 최신 버전에 있는 버그 때문인 것 같습니다.분류자 지원은 삭제되어 있습니다만, 임베디드 디스크립터를 사용하는 경우는 ID가 수정되어 있기 때문에, 큰 daft 이름이 됩니다.

이 문제를 해결하려면 종속성이 있는 jar 기술자가 사용하는 어셈블리 기술자를 복사하고 ID를 수정할 수 있습니다.

이 예에서는 어셈블리 ID가 finalName에 추가되므로 region-full.jar의 이름을 지정해야 할 경우 finalName을 region으로, 어셈블리 ID를 full로 지정할 수 있습니다.이렇게 하면 region-full.jar라는 이름의 파일이 타겟에 포함되지만, 여전히 Maven 저장소에 연결된 아티팩트로 설치되고 분류자로 full이 사용됩니다.이 ID가 다른 어셈블리와 다른 경우 충돌은 발생하지 않습니다.

폼 구성은 다음과 같습니다.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
          <descriptor>src/main/assembly/jar-assembly.xml</descriptor>
        </descriptors>
        <finalName>region</finalName>
      </configuration>
    </execution>
  </executions>
</plugin>

src/main/assembly의 jar-assembly.xml은 다음과 같습니다.

<assembly>
  <id>full</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
    </fileSet>
  </fileSets>
</assembly>

별도의 jar-assembly.xml을 사용하지 않고 직접 pom으로 설정할 수 있는 방법을 찾은 것 같습니다.

finalName이 attactId 및 버전으로 지정된다는 점을 제외하면 기본적으로 Rich의 답변과 동일합니다.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <finalName>${project.artifactId}-${project.version}-full</finalName>
        <appendAssemblyId>false</appendAssemblyId>
        <archive>
            <manifest>
                <mainClass>com.mycompany.MyMainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <id>make-my-jar-with-dependenciess</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

여기에 있는 투고와 maven documents를 파헤친 덕분에 커스텀 이름을 가진 일반적인 일회성 재포장 실행 가능 jar 어셈블리를 위한 다음과 같은 구성을 생각해냈습니다.

pom.xml의 경우:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>exe</id>
            <phase>package</phase>
            <goals><goal>single</goal></goals>
            <configuration>
                <finalName>MyJarName</finalName>
                <attach>false</attach>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>assembly.xml</descriptor>
                </descriptors>
                <archive>
                    <manifest>
                        <mainClass>karlthepagain.MyMain</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

assembly.xml의 경우:

<assembly>
    <id>exe</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

이렇게 하면MyJarName.jar모든 의존성을 동일한 항아리와 지정된 항아리에 재접속하여Main-Class: karlthepagain.MyMain.

를 사용하여 원본 jar 파일을 덮어쓸 수도 있습니다.${project.build.finalName}이름:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
   <executions>
      <execution>
          <phase>package</phase>
          <goals>
             <goal>single</goal>
          </goals>
      </execution>
   </executions>
   <configuration>
     <descriptorRefs>
       <descriptorRef>jar-with-dependencies</descriptorRef>
     </descriptorRefs>
     <finalName>${project.build.finalName}</finalName>
     <appendAssemblyId>false</appendAssemblyId>
   </configuration>
 </plugin>

저는 Rich가 저를 올바른 방향으로 인도해 준 것을 인정하지만, Rich의 솔루션이 약간 빗나갔기 때문에 저에게 도움이 되는 솔루션을 게시하고 싶었습니다.

jar-assembly.xml은 다음과 같이 되어 있어 프로파일에 속성으로 저장된 영역의 어셈블리 ID를 변경할 수 있습니다.

<assembly>
  <id>${env}-full</id>
    <formats>
      <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
      <dependencySet>
        <unpack>true</unpack>
        <scope>runtime</scope>
      </dependencySet>
    </dependencySets>
    <fileSets>
      <fileSet>
        <directory>${project.build.outputDirectory}</directory>
      </fileSet>
    </fileSets>
</assembly>

maven-assembly-plugin 설정에서 finalName 파라미터를 사용하지 않았습니다.이는 project-name-version-env-full.jar 이름을 사용하여 프로젝트를 빌드하기 때문입니다.여기서 env-full은 분류자입니다.

어셈블리의 xml이 빌드 내의 항목에 따라 파라미터화 될 수 있다는 것을 알았을 때의 놀라움을 상상해 보십시오.이게 바로 내가 찾던 거야.

이건 내게 효과가 있었다.

<build>
    <finalName>anynameyoulike</finalName>
    <plugins>           
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>                   
                <appendAssemblyId>false</appendAssemblyId>
                <archive>
                    <manifest>
                        <mainClass>com.mycompany.MyMainClass</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

언급URL : https://stackoverflow.com/questions/1334999/is-it-possible-to-rename-a-maven-jar-with-dependencies

반응형