英文:
Unable to import class from one module to another using maven
问题
import com.bugbusters.orchastrator_mobiperf.OrchAPI;
Make sure you have the correct dependencies set up in your http-request-handler
module's pom.xml
file to include the orchastrator_mobiperf
module as a dependency:
<dependency>
<groupId>com.bugbusters</groupId>
<artifactId>orchastrator_mobiperf</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
With the correct import and dependency configuration, you should be able to use the OrchAPI
class from the orchastrator_mobiperf
module in your http-request-handler
module.
英文:
I have 2 modules inside my project - http-request-handler and orchastrator-mobiperf. The directory structure of both the modules is as under:
├── orchastrator_mobiperf
│   ├── orchastrator_mobiperf.iml
│   ├── pom.xml
│   ├── README.md
│   ├── src
│   │   └── main
│   │   └── java
│   │   ├── Job.java
│   │   ├── JobTracker.java
│   │   ├── Main.java
│   │   ├── Measurement.java
│   │   ├── OrchAPI.java
│   │   ├── OrchServer.java
│   │   └── Utils.java
│   └── target
│   ├── classes
│   │   ├── Job.class
│   │   ├── JobTracker$1.class
│   │   ├── JobTracker.class
│   │   ├── Main.class
│   │   ├── Measurement.class
│   │   ├── OrchAPI.class
│   │   ├── OrchServer.class
│   │   └── Utils.class
│   ├── generated-sources
│   │   └── annotations
│   ├── maven-archiver
│   │   └── pom.properties
│   ├── maven-status
│   │   └── maven-compiler-plugin
│   │   └── compile
│   │   └── default-compile
│   │   ├── createdFiles.lst
│   │   └── inputFiles.lst
│   └── orchastrator_mobiperf-1.0-SNAPSHOT.jar
├── http-request-handler
│   ├── HELP.md
│   ├── http-request-handler.iml
│   ├── mvnw
│   ├── mvnw.cmd
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │   └── taveeshsharma
│   │   │   │   └── httprequesthandler
│   │   │   │   ├── ApiErrorCode.java
│   │   │   │   ├── ApiError.java
│   │   │   │   ├── Constants.java
│   │   │   │   ├── controllers
│   │   │   │   │   └── RequestHandler.java
│   │   │   │   ├── dto
│   │   │   │   │   ├── JobDescription.java
│   │   │   │   │   ├── MeasurementDescription.java
│   │   │   │   │   ├── Parameters.java
│   │   │   │   │   └── ScheduleRequest.java
│   │   │   │   ├── HttpRequestHandlerApplication.java
│   │   │   │   ├── model
│   │   │   │   │   └── User.java
│   │   │   │   └── repository
│   │   │   │   ├── ScheduleRequestRepository.java
│   │   │   │   └── UsersRepository.java
│   │   │   └── resources
│   │   │   └── application.properties
│   │   └── test
│   │   └── java
│   │   └── com
│   │   └── taveeshsharma
│   │   └── httprequesthandler
│   │   └── HttpRequestHandlerApplicationTests.java
│   └── target
│   ├── classes
│   │   ├── application.properties
│   │   └── com
│   │   └── taveeshsharma
│   │   └── httprequesthandler
│   │   ├── ApiError.class
│   │   ├── ApiErrorCode.class
│   │   ├── Constants.class
│   │   ├── controllers
│   │   │   └── RequestHandler.class
│   │   ├── dto
│   │   │   ├── JobDescription.class
│   │   │   ├── MeasurementDescription.class
│   │   │   ├── Parameters.class
│   │   │   └── ScheduleRequest.class
│   │   ├── HttpRequestHandlerApplication.class
│   │   ├── model
│   │   │   └── User.class
│   │   └── repository
│   │   ├── ScheduleRequestRepository.class
│   │   └── UsersRepository.class
│   ├── generated-sources
│   │   └── annotations
│   ├── generated-test-sources
│   │   └── test-annotations
│   └── test-classes
│   └── com
│   └── taveeshsharma
│   └── httprequesthandler
│   └── HttpRequestHandlerApplicationTests.class
The POM files of both modules are as under:
orchastrator_mobiperf:
<?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.bugbusters</groupId>
<artifactId>orchastrator_mobiperf</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
</dependencies>
</project>
http-request-handler:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.taveeshsharma</groupId>
<artifactId>http-request-handler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>http-request-handler</name>
<description>HTTP request handler</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.bugbusters</groupId>
<artifactId>orchastrator_mobiperf</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I'm not able to import the OrchAPI class of orchastrator_mobiperf into any class in http-request-handler.
答案1
得分: 0
问题得到解决。我将所有的类都放在了一个名为"orchastrator_mobiperf"的新包中,并重新编译了项目。
英文:
Problem got resolved. I put all the classes in orchastrator_mobiperf inside a new package and recompiled the project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论