gpt4 book ai didi

java - spring boot包不存在错误

转载 作者:行者123 更新时间:2023-12-03 08:46:20 28 4
gpt4 key购买 nike

我正在用 mvn clean package 编译我的项目,并以 package does not exist 失败.

详细命令:

  • 获取jar文件target/xxxx.jar通过运行 mvn clean package在源项目中。
  • 通过运行 mvn install:install-file -Dfile=lib/xxxx.jar -DgroupId=com.company -DartifactId=source-package-name -Dversion=1.0.0 -Dpackaging=jar 安装此 jar 文件
  • 将代码添加到目标项目中,这将使用源项目中的一些功能
  • 通过运行 mvn clean package 编译目标项目,它只是失败了 package does not exist

  • 这是源项目 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>

    这是目标项目 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>

    最佳答案

    理想情况下,您不应使用 Spring Boot 应用程序(已重新打包的应用程序)作为依赖项。来自 the documentation :

    Like a war file, a Spring Boot application is not intended to be used as a dependency. If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.



    如果建议的解决方案在您的情况下是不可能的,文档会继续描述替代方案:

    If you cannot rearrange your code as recommended above, Spring Boot’s Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency. The executable archive cannot be used as a dependency as the executable jar format packages application classes in BOOT-INF/classes. This means that they cannot be found when the executable jar is used as a dependency.

    To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as dependency.

    To configure a classifier of exec in Maven, the following configuration can be used:

    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <classifier>exec</classifier>
    </configuration>
    </plugin>
    </plugins>
    </build>

    关于java - spring boot包不存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45479060/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com