带有Maven的Spring-Boot外部lib文件夹

时间:2019-02-12 10:50:00

标签: maven spring-boot maven-assembly-plugin

我需要外部化应用程序的依赖关系。我想为我的Spring Boot应用程序实现以下布局

.
├── *.properties
├── static
├── main.jar
└── lib
     └── *.jar

lib文件夹中包含我的依赖项。

我尝试使用maven-jar-pluginspring-boot-maven-plugin,但出现以下错误:

Could not find or load main class com.Application

我的pom.xml

<profile>
            <id>dist</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.0.2</version>
                        <configuration>
                            <finalName>alfred</finalName>
                            <excludes>
                                <exclude>src/main/resources/*</exclude>
                                <exclude>*.properties</exclude>
                                <exclude>*.html</exclude>
                                <exclude>**/assembly/*</exclude>
                                <exclude>**/lib/*</exclude>
                                <exclude>**/static/*</exclude>
                                <exclude>**/templates/*</exclude>
                            </excludes>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <Main-Class>com.Application</Main-Class>
                                </manifest>
                                <manifestEntries>
                                    <Class-Path>./alfred_lib/**</Class-Path>
                                    <Class-Path>./**</Class-Path>
                                </manifestEntries>
                            </archive>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <version>2.1.2.RELEASE</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>repackage</goal>
                                </goals>
                                <configuration>
                                    <attach>false</attach>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.2-beta-1</version>
                        <configuration>
                            <descriptor>src/main/resources/assembly/dist.xml</descriptor>
                            <finalName>alfred</finalName>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

我的src/main/resources/assembly/dist.xml

<assembly>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/assembly</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>**.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
        <!-- Estáticos -->
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory></outputDirectory>
            <excludes>
                <exclude>lib/**</exclude>
                <exclude>assembly/**</exclude>
            </excludes>
        </fileSet>
        <!-- Aplicación -->
        <fileSet>
            <directory>target</directory>
            <outputDirectory></outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
    <!-- Dependencias -->
    <dependencySets>
        <dependencySet>
            <outputDirectory>alfred_lib</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

我已经阅读了几天,但已经丢弃:

  • 使用spring-boot-thin-layout
  • 创建远端jar:这是项目要求。

0 个答案:

没有答案