-1
我有3個項目行家:如何解決maven編譯錯誤:包X不存在?
project-A
project-B
project-C
第二個項目(B)需要的第一個項目(A)的依賴性。 第三個項目(C)需要第一個和第二個項目(A,B)的依賴關係。 我已經在各自的項目中定義這些依賴pom
文件: project-B pom.xml
:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
project-C pom.xml
:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-B</artifactId>
<version>${project.version}</version>
</dependency>
一切正常OK上SpringToolSuite
。我已經測試了第二個項目(取決於第一個項目),並測試了第三個項目(這取決於第一個和第二個項目),並且STS的一切正常。
當我嘗試執行: MVN全新安裝-U -DskipTests =真
它工作得很好了project-A
和project-B
,但project-C
我得到一個:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] MyClassOnProjectC.java:[12,38] package XXX does not exist
[ERROR] MyClassOnProjectC.java:[22,17] cannot find symbol
symbol: class MyClassOnProjectB
location: class MyClassOnProjectC
下面有從每個項目中提取3個類:
項目-A: User.java
package com.neweraed.datamodel;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserType", propOrder = {
"name",
"description",
})
public class User implements Serializable {
private static final long serialVersionUID = -876063526825526098L;
private String name;
private String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
項目-B: UserOperations.java
package com.neweraed.services.midpoint;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestOperations;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.utils.Constants;
import com.neweraed.services.midpoint.utils.Utils;
@Component
public class UserOperations {
private static final Logger logger = LoggerFactory.getLogger(UserOperations.class);
public User getUser(User user) {
RestOperations restOperations = Utils.createGenericRestTemplate();
ResponseEntity<User> response = null;
try {
response = restOperations.exchange(Constants.ENDPOIT_SEARCH_USER, HttpMethod.GET, new HttpEntity<Object>(Utils.createHeaders()), User.class);
logger.info("=== RESPONSE ===" + response + " === ");
} catch (Exception e) {
logger.error("=== ERROR === " + e.getMessage() + " === ");
}
return user;
}
}
項目-C: UserService.java
package com.neweraed.rest;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.neweraed.datamodel.User;
import com.neweraed.services.midpoint.UserOperations;
@RestController
@RequestMapping(value="/api/v1/users")
public class UserService {
@RequestMapping(value="/", method=RequestMethod.POST)
public User addUser(@RequestBody User user) {
UserOperations userOperations = new UserOperations();
return userOperations.addUser(user);
}
}
好像一切都在我的pom.xml文件確定。我該如何解決這個問題?
是正確定義的一個依賴。我試圖從project-C的pom.xml中刪除項目-A的依賴項,然後重新執行了命令,但我得到了相同的錯誤 –
A和B的打包類型是pom? –
不,包裝類型的A和B是罐子 –