首页 > 解决方案 > 无法使用 maven 将类从一个模块导入另一个模块

问题描述

我的项目中有 2 个模块 - http-request-handler 和 orchastrator-mobiperf。两个模块的目录结构如下:

├── 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

两个模块的POM文件如下:

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请求处理程序:

<?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>

我无法将 orchastrator_mobiperf 的 OrchAPI 类导入 http-request-handler 中的任何类。

标签: javaspringmavenpom.xml

解决方案


问题得到解决。我将 orchastrator_mobiperf 中的所有类放在一个新包中并重新编译了项目。


推荐阅读