无法使用Maven从一个模块导入到另一个模块的类。

huangapple go评论75阅读模式
英文:

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
│&#160;&#160; ├── orchastrator_mobiperf.iml
│&#160;&#160; ├── pom.xml
│&#160;&#160; ├── README.md
│&#160;&#160; ├── src
│&#160;&#160; │&#160;&#160; └── main
│&#160;&#160; │&#160;&#160;     └── java
│&#160;&#160; │&#160;&#160;         ├── Job.java
│&#160;&#160; │&#160;&#160;         ├── JobTracker.java
│&#160;&#160; │&#160;&#160;         ├── Main.java
│&#160;&#160; │&#160;&#160;         ├── Measurement.java
│&#160;&#160; │&#160;&#160;         ├── OrchAPI.java
│&#160;&#160; │&#160;&#160;         ├── OrchServer.java
│&#160;&#160; │&#160;&#160;         └── Utils.java
│&#160;&#160; └── target
│&#160;&#160;     ├── classes
│&#160;&#160;     │&#160;&#160; ├── Job.class
│&#160;&#160;     │&#160;&#160; ├── JobTracker$1.class
│&#160;&#160;     │&#160;&#160; ├── JobTracker.class
│&#160;&#160;     │&#160;&#160; ├── Main.class
│&#160;&#160;     │&#160;&#160; ├── Measurement.class
│&#160;&#160;     │&#160;&#160; ├── OrchAPI.class
│&#160;&#160;     │&#160;&#160; ├── OrchServer.class
│&#160;&#160;     │&#160;&#160; └── Utils.class
│&#160;&#160;     ├── generated-sources
│&#160;&#160;     │&#160;&#160; └── annotations
│&#160;&#160;     ├── maven-archiver
│&#160;&#160;     │&#160;&#160; └── pom.properties
│&#160;&#160;     ├── maven-status
│&#160;&#160;     │&#160;&#160; └── maven-compiler-plugin
│&#160;&#160;     │&#160;&#160;     └── compile
│&#160;&#160;     │&#160;&#160;         └── default-compile
│&#160;&#160;     │&#160;&#160;             ├── createdFiles.lst
│&#160;&#160;     │&#160;&#160;             └── inputFiles.lst
│&#160;&#160;     └── orchastrator_mobiperf-1.0-SNAPSHOT.jar

├── http-request-handler
│&#160;&#160; ├── HELP.md
│&#160;&#160; ├── http-request-handler.iml
│&#160;&#160; ├── mvnw
│&#160;&#160; ├── mvnw.cmd
│&#160;&#160; ├── pom.xml
│&#160;&#160; ├── src
│&#160;&#160; │&#160;&#160; ├── main
│&#160;&#160; │&#160;&#160; │&#160;&#160; ├── java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160; └── com
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;     └── taveeshsharma
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;         └── httprequesthandler
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── ApiErrorCode.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── ApiError.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── Constants.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── controllers
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; └── RequestHandler.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── dto
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; ├── JobDescription.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; ├── MeasurementDescription.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; ├── Parameters.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; └── ScheduleRequest.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── HttpRequestHandlerApplication.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             ├── model
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             │&#160;&#160; └── User.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;             └── repository
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;                 ├── ScheduleRequestRepository.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; │&#160;&#160;                 └── UsersRepository.java
│&#160;&#160; │&#160;&#160; │&#160;&#160; └── resources
│&#160;&#160; │&#160;&#160; │&#160;&#160;     └── application.properties
│&#160;&#160; │&#160;&#160; └── test
│&#160;&#160; │&#160;&#160;     └── java
│&#160;&#160; │&#160;&#160;         └── com
│&#160;&#160; │&#160;&#160;             └── taveeshsharma
│&#160;&#160; │&#160;&#160;                 └── httprequesthandler
│&#160;&#160; │&#160;&#160;                     └── HttpRequestHandlerApplicationTests.java
│&#160;&#160; └── target
│&#160;&#160;     ├── classes
│&#160;&#160;     │&#160;&#160; ├── application.properties
│&#160;&#160;     │&#160;&#160; └── com
│&#160;&#160;     │&#160;&#160;     └── taveeshsharma
│&#160;&#160;     │&#160;&#160;         └── httprequesthandler
│&#160;&#160;     │&#160;&#160;             ├── ApiError.class
│&#160;&#160;     │&#160;&#160;             ├── ApiErrorCode.class
│&#160;&#160;     │&#160;&#160;             ├── Constants.class
│&#160;&#160;     │&#160;&#160;             ├── controllers
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; └── RequestHandler.class
│&#160;&#160;     │&#160;&#160;             ├── dto
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; ├── JobDescription.class
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; ├── MeasurementDescription.class
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; ├── Parameters.class
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; └── ScheduleRequest.class
│&#160;&#160;     │&#160;&#160;             ├── HttpRequestHandlerApplication.class
│&#160;&#160;     │&#160;&#160;             ├── model
│&#160;&#160;     │&#160;&#160;             │&#160;&#160; └── User.class
│&#160;&#160;     │&#160;&#160;             └── repository
│&#160;&#160;     │&#160;&#160;                 ├── ScheduleRequestRepository.class
│&#160;&#160;     │&#160;&#160;                 └── UsersRepository.class
│&#160;&#160;     ├── generated-sources
│&#160;&#160;     │&#160;&#160; └── annotations
│&#160;&#160;     ├── generated-test-sources
│&#160;&#160;     │&#160;&#160; └── test-annotations
│&#160;&#160;     └── test-classes
│&#160;&#160;         └── com
│&#160;&#160;             └── taveeshsharma
│&#160;&#160;                 └── httprequesthandler
│&#160;&#160;                     └── HttpRequestHandlerApplicationTests.class

The POM files of both modules are as under:

orchastrator_mobiperf:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;com.bugbusters&lt;/groupId&gt;
    &lt;artifactId&gt;orchastrator_mobiperf&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;properties&gt;
        &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
    &lt;/properties&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.json&lt;/groupId&gt;
            &lt;artifactId&gt;json&lt;/artifactId&gt;
            &lt;version&gt;20180130&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/project&gt;

http-request-handler:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
		&lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;
	&lt;groupId&gt;com.taveeshsharma&lt;/groupId&gt;
	&lt;artifactId&gt;http-request-handler&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
	&lt;name&gt;http-request-handler&lt;/name&gt;
	&lt;description&gt;HTTP request handler&lt;/description&gt;

	&lt;properties&gt;
		&lt;java.version&gt;1.8&lt;/java.version&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-mongodb&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.bugbusters&lt;/groupId&gt;
			&lt;artifactId&gt;orchastrator_mobiperf&lt;/artifactId&gt;
			&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
					&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

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.

huangapple
  • 本文由 发表于 2020年7月26日 17:57:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63098623.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定