如何使用maven程序集插件打包Spring Boot Web应用程序

时间:2018-03-28 02:33:47

标签: java maven spring-boot

my web application structure

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
    <artifactId>tally</artifactId>
    <groupId>win.bestyyt</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>web</artifactId>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-redis</artifactId>
    </dependency>
    <dependency>
        <groupId>win.bestyyt</groupId>
        <artifactId>service</artifactId>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
    </dependency>
    <dependency>
        <groupId>nz.net.ultraq.thymeleaf</groupId>
        <artifactId>thymeleaf-layout-dialect</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>appassembler-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>

            <configuration>
                <repositoryLayout>flat</repositoryLayout>
                <configurationDirectory>conf</configurationDirectory>
                <configurationSourceDirectory>src/main/resources</configurationSourceDirectory>
                <copyConfigurationDirectory>true</copyConfigurationDirectory>
                <includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
                <assembleDirectory>${project.build.directory}/tally</assembleDirectory>
                <extraJvmArguments>-Xms256m</extraJvmArguments>
                <binFileExtensions>
                    <unix>.sh</unix>
                </binFileExtensions>
                <platforms>
                    <platform>windows</platform>
                    <platform>unix</platform>
                </platforms>
                <repositoryName>lib</repositoryName>
                <programs>
                    <program>
                        <mainClass>win.bestyyt.web.Application</mainClass>
                        <name>start</name>
                    </program>
                </programs>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

运行package命令后,我得到了如下所示的目录结构,它是平的。

structure after package

我发现所有资源仍在“web-1.0-SNAPSHOT.jar”中 jar structure(sorry for the resolution)

当我执行start.bat时,它会继续重启。

restarting

我的问题是:

1,如何获取分层资源目录?

2,如何让程序正常运行? (不要继续重启)

1 个答案:

答案 0 :(得分:0)

您是否尝试过spring boot maven plugin? Spring制作了自己的插件,以避免使用程序集或其他相关插件。

看起来Spring也试图关闭你的数据源两次。尝试将此添加到您的java配置:

@Bean(destroyMethod = "")
public DataSource dataSource()