Java 无法从 maven 依赖项目中找到类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9754597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't find class from maven dependency project
提问by user8363
[CLOSED - I had to move classes from test/java to main/java and update the maven repository via the IDE "maven options"]
[关闭 - 我必须将类从 test/java 移动到 main/java 并通过 IDE 的“maven 选项”更新 maven 存储库]
I'm new to maven and inexperienced with java development. I'm using IntelliJ Idea as IDE. I'm using Maven 3.0.4.
我是 maven 新手,对 java 开发没有经验。我使用 IntelliJ Idea 作为 IDE。我正在使用 Maven 3.0.4。
I created a "project A" and a "project B", each with some classes. Now when I try to create a dependency in project Ato a class in project BI can't seem to find any classes that are part of project B. When I check the maven repository I can see that a .jar file is created based on project B.
我创建了一个“项目 A”和一个“项目 B”,每个项目都有一些类。现在,当我尝试在项目 A 中创建对项目 B 中类的依赖项时,我似乎找不到属于项目 B 的任何类。当我检查 maven 存储库时,我可以看到基于项目 B创建了一个 .jar 文件。
To clarify: when adding a dependency to project BI dofind an artifact called "project B" but I cannotfind any classes that are part of project B.
为了澄清:添加依赖于当B项目我做的发现被称为“项目B”的假象,但我无法找到是一部分的任何类别B项目。
It doesn't seem like I can access and use any of the classes that are part of project Binside project Awhich would make this installation worthless.
它似乎并不像我可以访问和使用的任何已部分类的B项目内部项目中的这将使此安装毫无价值。
--
——
Please tell me what information I should include for you to help me solve this problem.
请告诉我我应该包含哪些信息来帮助我解决这个问题。
[EDIT] Here is the project A's pom with a dependency on project B. However I either don't understand how to use it in my project or it doesn't work. While I can use IntelliJ's functionality to find and add the artifact, intelliJ can't seem to find any classes that are part of project B(while it does find classes that are part of other pre-defined packages in the maven repository):
[编辑] 这是项目 A的 pom 依赖于项目 B。但是我要么不明白如何在我的项目中使用它,要么它不起作用。虽然我可以使用 IntelliJ 的功能来查找和添加工件,但 intelliJ 似乎无法找到属于项目 B 的任何类(虽然它确实找到了属于 Maven 存储库中其他预定义包的一部分的类):
<?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>planet</groupId>
<artifactId>planet</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>toolbox</groupId>
<artifactId>toolbox</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
采纳答案by user8363
I had to move my classes from test/java to main/java. Silly, but it took me a whole day to realise this. This only worked after updating the repository in "maven options" via the IDE.
我不得不将我的课程从 test/java 移动到 main/java。愚蠢,但我花了一整天才意识到这一点。这仅在通过 IDE 更新“maven 选项”中的存储库后才有效。
回答by Jan Kubovy
You can do the following:
您可以执行以下操作:
<dependency>
<groupId>toolbox</groupId>
<artifactId>toolbox</artifactId>
<version>1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Works for me :)
对我有用:)