Java spring启动包不存在错误
我正在使用Java spring启动包不存在错误,java,spring,maven,spring-boot,jar,Java,Spring,Maven,Spring Boot,Jar,我正在使用mvn clean package编译我的项目,但由于package不存在而失败 “详细信息”命令: 通过在源项目中运行mvncleanpackage获取jar文件target/xxxx.jar 通过运行mvn install:install file-Dfile=lib/xxxx.jar-DgroupId=com.company-DartifactId=source-package-name-Dversion=1.0.0-dpackage=jar安装此jar文件 向目标项目添加代码
mvn clean package
编译我的项目,但由于package不存在而失败
“详细信息”命令:
- 通过在源项目中运行
mvncleanpackage
获取jar文件target/xxxx.jar
- 通过运行
mvn install:install file-Dfile=lib/xxxx.jar-DgroupId=com.company-DartifactId=source-package-name-Dversion=1.0.0-dpackage=jar安装此jar文件
- 向目标项目添加代码,目标项目将使用源项目中的一些函数
- 通过运行
mvn clean package
编译目标项目,但由于package不存在而失败
下面是源项目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.company</groupId>
<artifactId>source-package-name</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>source-package-name</name>
<description>xxxx</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx6144m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
com公司
源包名称
1.0.0
罐子
源包名称
xxxx
org.springframework.boot
spring启动程序父级
1.5.3.1发布
UTF-8
UTF-8
1.8
org.springframework.boot
springbootmaven插件
重新包装
org.apache.maven.plugins
maven surefire插件
-Xmx6144m
以下是目标项目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.company</groupId>
<artifactId>target-package-name</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>target-package-name</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.7</jdk.version>
<smartv-common.version>0.3.5s</smartv-common.version>
<spring.version>3.0.5.RELEASE</spring.version>
</properties>
<dependencies>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!-- Exclude those since they are copied from the profile folder for
the build -->
<exclude>system.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<finalName>xxxxx</finalName>
<!-- Set a compiler level -->
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html
http://stackoverflow.com/questions/12729513/how-to-overwrite-files-in-the-war-file-during-maven-build -->
<webResources>
<!-- Resources from the activated profile folder -->
<resource>
<targetPath>WEB-INF/classes/</targetPath>
<includes>
<include>system.properties</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
com公司
目标包名称
0.0.1-快照
战争
目标包名称
http://maven.apache.org
UTF-8
1.7
0.3.5s
3.0.5.1发布
src/main/resources
系统属性
假的
xxxxx
马文
os maven插件
1.4.1.最终版本
org.apache.maven.plugins
maven编译器插件
3.1
${jdk.version}
${jdk.version}
UTF-8
org.apache.maven.plugins
maven战争插件
2.6
WEB-INF/课程/
系统属性
理想情况下,您不应该使用Spring启动应用程序(已重新打包的应用程序)作为依赖项。发件人:
与war文件一样,Spring引导应用程序不打算用作依赖项。如果您的应用程序包含要与其他项目共享的类,建议将该代码移动到单独的模块中。然后,应用程序和其他项目可以依赖单独的模块
如果建议的解决方案在您的情况下不可行,文档将继续描述替代方案:
如果您不能按照上面的建议重新排列代码,那么必须将SpringBoot的Maven和Gradle插件配置为生成一个适合用作依赖项的单独工件。可执行归档文件不能用作BOOT-INF/classes中可执行jar格式包应用程序类的依赖项。这意味着当可执行jar用作依赖项时,无法找到它们
要生成两个工件,一个可用作依赖项,另一个可执行,必须指定一个分类器。此分类器应用于可执行归档文件的名称,保留默认归档文件作为依赖项使用
要在Maven中配置exec分类器,可以使用以下配置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
org.springframework.boot
springbootmaven插件
执行官
向目标项目添加依赖项。@talex我确实添加了dep,但它仍然不起作用。因此,我认为包的方式是否正确。您可以通过查看本地maven repo(通常是ia=n~/.m2
文件夹)来检查它。找到模块文件夹并检查其pom.file
。然后检查您的依赖项是否正确。它在这里,但仍然失败还有一个问题,我只是发现我的源目标中的所有@Autowired
都为空,是否有问题@安迪·威尔金森这个解释把我引向光明。非常感谢。