[英]Local Maven Repo have no Symbols
我創建了一個本地Maven Repo,並在其中部署了自己的庫:
mvn clean package install deploy
上:
http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0
<groupId>de.example</groupId>
<artifactId>example-lib</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>example-lib</name>
<description>Demo project for Spring Boot</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>example.repo</id>
<name>example internal mvn repository</name>
<url>file://${project.basedir}/../mvn-repo</url>
</repository>
</distributionManagement>
現在另一個項目使用它:
<repositories>
<repository>
<id>example.repo</id>
<url>file://${project.basedir}/../mvn-repo</url>
</repository>
</repositories>
...
<dependency>
<groupId>de.example</groupId>
<artifactId>example-lib</artifactId>
<version>0.0.1</version>
</dependency>
...
但是在編譯項目時,lib中缺少所有符號(但是依賴項已解決,並且存在.jar文件)
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/CoreApplication.java:[11,31] package de.example.examplelib does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[11,42] package de.example.examplelib.db.example does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[12,42] package de.example.examplelib.db.example does not exist
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[19,17] cannot find symbol
symbol: class UserRepository
location: class de.example.core.DbExampleService
[ERROR] /C:/Users/gregor/Documents/dev/repo/example/core/src/main/java/de/example/core/DbExampleService.java:[35,39] cannot find symbol
symbol: class User
location: class de.example.core.DbExampleService
我搜索了最近4個小時,也許我只是想念一些基本的東西?? 打開提示。 提前致謝。
當Maven找不到依賴項時,它會明確表示。 您的問題具有不同的性質; 看來您的jar可能實際上是空的(即您具有正確的依賴關系;只是包裝不正確)。
Maven存儲庫只是一個簡單的文件集合; 你可以進去打開罐子; 我建議檢查您的mvn-repo以查看您要包含的jar是否包含您希望包含的類。
如果我是正確的(即您的jar未正確包裝),請查看默認的maven目錄結構,等等(默認情況下,Maven用於從src/main/java
拾取java
文件;也許您使用其他源文件夾,你不是在告訴Maven嗎?)
編輯1總結評論和其他答案中的討論:
到目前為止,我們知道您的罐子包裝不正確。 好吧,它包裝不正確是為了供其他項目使用。 因此,您看到的錯誤是正常的。 准時地,該錯誤是因為您de/example/examplelib/db/example/User.class
引用類de/example/examplelib/db/example/User.class
,但是此類位於錯誤的位置( de
軟件包應位於jar的根目錄中而不是在BOOT-INF/classes
文件夾中)。
發生這種情況的可能性最大,因為用於打包庫的pom.xml
文件是從spring-boot父級繼承的(或者其中有一些未顯示的配置)。 因此,鑒於這些事情,您需要重新陳述您的問題:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.