【问题标题】:Spring Boot2.1.7 Dependencies not copied into jar fileSpring Boot2.1.7 依赖没有复制到jar文件中
【发布时间】:2020-01-30 14:51:58
【问题描述】:

我正在将现有的 spring 应用程序迁移到 spring boot。我无法将它作为 spring boot 应用程序运行。当我通过命令提示符运行 jar 文件时,它显示“no main manifest attribute”。现在正在添加以下插件我的 pom.xml 文件。之前的错误已解决。

pom.xml

  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.services.api.ServiceMain</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

现在显示另一个错误

清单.mf

Manifest-Version: 1.0
Implementation-Title: Service
Implementation-Version: 7.0.0.0
Archiver-Version: Plexus Archiver
Built-By: Administrator
Implementation-Vendor-Id: MainProject
Class-Path: lib/abc-1.0.jar lib/abc1-1.0.jar

Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_202
Implementation-URL: http://maven.apache.org
Main-Class: com.services.api.ServiceMain

lib 文件夹不存在于我的目标或 jar 文件中,我的 jar 文件大小仅为 64 kb。

使用以下逗号构建我的应用程序

clean install

我该如何解决这个问题。已经通过一些堆栈溢出链接,没有解决我的问题

【问题讨论】:

    标签: maven spring-boot maven-plugin


    【解决方案1】:

    下面试试

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <start-class>org.springframework.boot.loader.JarLauncher</start-class>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    【讨论】:

    • 能不能把完整的pom.xml放好
    • 我刚刚用你给的pom创建了一个项目,你的pom好像没有问题,尝试新建一个干净的项目
    • 你能用 java -jar service.jar 运行 jar 文件吗
    • 是的,没有任何问题
    • 如果你能在 GitHub 上提供你的项目,我可以试试
    猜你喜欢
    • 2015-05-12
    • 2016-02-09
    • 2011-07-19
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多