簡體   English   中英

Pom 文件配置到 package 外部/自定義 jar 文件中的胖 spring 啟動可執行文件 Z68904480F43A29DAC41

[英]Pom file configuration to package external/custom jar file in the fat spring boot executable jar file

我的要求:

我正在嘗試創建一個 spring 啟動 web 項目,該項目依賴於外部/自定義 jar 文件。 我在 pom.xml 文件中添加了這個依賴項,如下所示:

<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>customjar</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/customjar.jar</systemPath>
  </dependency>
</dependencies>

在編譯期間我沒有看到任何錯誤。 但是當我構建項目並且它正在生成一個可執行的胖 jar 文件時。 此 jar 文件具有其他依賴項,但不是作為“系統范圍”添加的依賴項,並且運行時拋出 ClassNotFoundException。

Can anyone please tell me what configuration we have to add in pom.xml file so that system scope jar file will also added in the executable jar file.

system scope 已被棄用,並像provided的那樣運行:jar 將在您執行時provided

閱讀spring-boot-maven-plugin的文檔可能會有所幫助:您似乎可以將<includeSystemScope>true</includeSystemScope>添加到插件的配置中以包含所述 scope。

或者,您可以嘗試先安裝 jar install:install-file目標:

  • 最好在您的 spring-boot 項目之前在 pom 中完成。
  • 如果您的構建在同一個反應器中,最好provided從 spring-boot 項目到執行install-file的項目的依賴項。

sanjeevRm的答案可能有效,但您必須確保布局正確: install-file 目標可以通過提供localRepositoryPath為您做到這一點。

<repositories>
    <repository>
        <id>local-project-repo</id>
        <url>file:${project.basedir}/lib/repository</url>
    </repository>
</repositories>

您的文件必須放在: ${project.basedir}/lib/repository/com/example/customjar/1.0/customjar-1.0.jar中。

您可以在 pom 中添加以下內容並將工件放置在此存儲庫中

<repositories>
    <repository>
        <id>local-project-repo</id>
        <url>file:${basedir}/lib/repository</url>
    </repository>
</repositories>

您還可以查看導入 scope 文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM