java - 如何使用 Maven 组件插件打包 Spring Boot Web 应用程序

标签 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、如何让程序正确运行? (不要一直重启)

最佳答案

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

看起来 Spring 正在尝试关闭您的数据源两次。尝试将其添加到您的 java 配置中:

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

关于java - 如何使用 Maven 组件插件打包 Spring Boot Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49525183/

相关文章:

java - 统计数据分析中的分散数据集

java - 我怎样才能用给定的实例变量创建一个可调整大小的条,并为其设置两种不同的颜色,红色代表 (a) 绿色代表 (b)?

java - 异步任务 : pass two or more values from doInBackground to onPostExecute

java - 如何覆盖默认的 swagger-code-gen 服务实现?

spring - 为什么首页无法访问/spring boot应用

spring-boot - Spring Cloud Consul和Consul客户端 docker 化

java - 如何添加到以前的 JLabel

maven - 使用 Snapshot 策略部署在 nexus Artifact 上,但版本中没有 SNAPSHOT 字符串

android - 使用 Maven surefire 插件运行 Robolectric 测试时获取 ClassNotFoundException

java - Spring Boot 无法检测我输入的值