Подтвердить что ты не робот

Плагин Maven для создания исполняемой банки с зависимостями, которые не распакованы (банка с банками)

Я прочитал много решений для создания исполняемого баннера с зависимостями (плагин maven shade, плагин зависимостей maven, плагин сборки maven), и все эти плагины распаковывают банки зависимостей и переупаковывают их в исполняемом банке. Единственный плагин, который упакован в java файл, который распакован в исполняемом банке, является одним jar-плагином, но этот плагин добавляет свой код бегуна в исполняемый банку.

Есть ли какое-нибудь решение для создания jar:

├─executable.jar
├──lib/
├───dependency1.jar
├───dependency2.jar
.
.
.

и это решение для работы.

4b9b3361

Ответ 1

Наиболее распространенным способом является использование плагина сборки, который позволит вам настроить упаковку так, как вам нужно.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
         <archive>
              <manifest>
                   <mainClass>com.somewhere.Main</mainClass>
              </manifest>
         </archive>
         <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
         </descriptorRefs>
    </configuration>
    <executions>
          <execution>
               <id>make-assembly</id>
               <phase>package</phase>
               <goals>
                    <goal>single</goal>
               </goals>
         </execution>
    </executions>
</plugin>

Также вы можете указать дескриптор сборки для конфигурации

<configuration>
    <appendAssemblyId>false</appendAssemblyId>
    <descriptors>
      <descriptor>src/main/assembly/assembly.xml</descriptor>
    </descriptors>
</configuration>

И сам assembly.xml

<assembly>
    <id>assembly</id>
    <formats>
         <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
             <directory>${project.build.outputDirectory}</directory>
             <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

Дескриптор сборки также может содержать раздел зависимости:

<!-- lib -->
<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>

Насколько я понимаю, вы ищете последнюю. Поскольку он просто включает файлы jar в сборку без каких-либо изменений. Итак, окончательное решение будет выглядеть так:

<assembly>
    <id>assembly</id>
    <formats>
         <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <!-- lib -->
    <dependencySets>
        <dependencySet>
             <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

и часть pom:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
             <descriptor>src/main/assembly/assembly.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
          <execution>
               <id>make-assembly</id>
               <phase>package</phase>
               <goals>
                    <goal>single</goal>
               </goals>
         </execution>
    </executions>
</plugin>

Ответ 2

<plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>