This question already has an answer here:
这个问题在这里已有答案:
- What does a “Cannot find symbol” compilation error mean? 10 answers
“无法找到符号”编译错误是什么意思? 10个答案
I have 3 maven projects:
我有3个maven项目:
project-A
project-B
project-C
The second project (B) requires the dependency for the first project (A). The third project (C) requires the dependencies for the first and second project (A, B). I have defined these dependencies in the respective projects pom
files: project-B pom.xml
:
第二个项目(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
:
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>
Everything works OK on SpringToolSuite
. I have tested the second project (which depends on the first project) and also tested the third project (which depends on both first and second project) and everything works OK from STS.
在SpringToolSuite上一切正常。我测试了第二个项目(这取决于第一个项目)并测试了第三个项目(这取决于第一个和第二个项目),一切都可以从STS中运行。
When I try to execute: mvn clean install -U -DskipTests=true
当我尝试执行:mvn clean install -U -DskipTests = true
it works perfectly well for project-A
and project-B
, but for project-C
I get a:
它对项目-A和项目-B非常有效,但对于项目-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
Below there are 3 classes extracted from each of the projects:
下面是从每个项目中提取的3个类:
Project-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;
}
}
Project-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;
}
}
Project-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);
}
}
It seems like everything is OK on my pom.xml files. How can I solve this?
我的pom.xml文件似乎一切正常。我怎么解决这个问题?
1 个解决方案
#1
1
According to your premises, pom.xml
of the project B must be:
根据您的前提,项目B的pom.xml必须是:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
And project C doesn't need the dependency with A because it is defined on B
项目C不需要与A的依赖关系,因为它在B上定义
#1
1
According to your premises, pom.xml
of the project B must be:
根据您的前提,项目B的pom.xml必须是:
<dependency>
<groupId>com.mygroupid</groupId>
<artifactId>project-A</artifactId>
<version>${project.version}</version>
</dependency>
And project C doesn't need the dependency with A because it is defined on B
项目C不需要与A的依赖关系,因为它在B上定义