Maven 将实际 jar 生成为 .jar.original 而不是 .jar 文件 [英] Maven generating actual jar as .jar.original instead of .jar file
问题描述
基本上我有一个 Maven 项目,我正在尝试使用 mvn clean compile package
通过 spring 工具套件使用下面的 pom.xml 生成我的项目的 jar.
Basically I have a Maven Project and I am trying to generate a jar of my project using mvn clean compile package
through spring tool suite using below pom.xml.
命令执行后,我在我的 target
文件夹中生成了 2 个 jar 文件 - {project-name}.jar &{project-name}.jar.original
After the command is executed, I get 2 jar files generated in my target
folder - {project-name}.jar & {project-name}.jar.original
.jar
文件包含Spring boot 框架类文件具有此contents 而 .jar.original
文件包含我的应用程序的实际类文件.
The .jar
file contains
Spring boot framework class files having this contents while the .jar.original
file contains actual class files of my application.
我也尝试过使用 mvn clean install
但没有成功.而且,只安装了 1 个对我来说没用的文件,因为它不包含我的应用程序的任何 class
文件,但包含 spring 框架类.
I also tried using mvn clean install
but no luck with it. Moreover, the only 1 file is installed which is useless for me, because it does not contain any class
files of my application but contains spring framework classes.
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.commonporject</groupId>
<artifactId>commonporject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>commonporject</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>10.1</version>
</dependency>
<!-- other dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
控制台
:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< com.commonporject:commonporject >----------------------
[INFO] Building commonporject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ commonporject ---
[INFO] Deleting C:\Users\Aadil\Documents\workspace-spring-tool-suite-4-4.0.0.RELEASE\commonporject\target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ commonporject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ commonporject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\Users\Aadil\Documents\workspace-spring-tool-suite-4-4.0.0.RELEASE\commonporject\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ commonporject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ commonporject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ commonporject ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ commonporject ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ commonporject ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.0:jar (default-jar) @ commonporject ---
[INFO] Building jar: C:\Users\Aadil\Documents\workspace-spring-tool-suite-4-4.0.0.RELEASE\commonporject\target\commonporject-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.0.RELEASE:repackage (repackage) @ commonporject ---
[INFO] Replacing main artifact C:\Users\Aadil\Documents\workspace-spring-tool-suite-4-4.0.0.RELEASE\commonporject\target\commonporject-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.706 s
[INFO] Finished at: 2018-11-04T12:28:37+05:30
[INFO] ------------------------------------------------------------------------
推荐答案
spring-boot-maven 插件默认使用 repackage 目标,它打包 pom 文件中提到的所有依赖项.发生这种情况时,您项目的类和资源 jar 将重命名为原始".
spring-boot-maven plugin by default uses the repackage goal which packages all dependencies mentioned in the pom file. When this happens, your project's classes and resources jar is renamed to "original".
有关此插件的更多详细信息,请参阅以下文档.
Please refer the below documentation for more details about this plugin.
https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html
这篇关于Maven 将实际 jar 生成为 .jar.original 而不是 .jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!