java - 从 java 类中看不到 Maven 依赖项
问题描述
我已将我的 Java 项目切换为使用 Maven,这是我第一次使用它。
我已经配置了我的 pom.xml 文件(见下文)。
然后我运行方式-> Maven 构建并使用目标“全新安装”。我可以看到所有依赖项都已下载,这很好,但我的主类没有看到它们,仍然说“XXX 无法解析为类型”。我看不出我做错了什么。
在文件的开头,我有所需的导入(例如:“import org.apache.logging.log4j.Logger;”)但 Eclipse 认为不需要此行并继续删除它。
你知道我做错了什么吗?谢谢
<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>MyProject</groupId>
<artifactId>MyProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.12.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scream3r/jssc -->
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.controlsfx/controlsfx -->
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.40.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.dlsc.preferencesfx/preferencesfx-core -->
<dependency>
<groupId>com.dlsc.preferencesfx</groupId>
<artifactId>preferencesfx-core</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/de.endrullis.draggabletabs/draggabletabs -->
<dependency>
<groupId>de.endrullis.draggabletabs</groupId>
<artifactId>draggabletabs</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.my_company.myproject.MainApp</mainClass>
<arguments>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
解决方案
推荐阅读
- .net - 如何使用程序集中的版本号创建预发布的 nuget 包
- php - 更新列的所有行仅返回 foreach 循环中的最后一个值
- testing - 如何在testcafe中存根window.open
- r - 使用noteMD将闪亮ui中的文本框插入pdf或word报告时出错
- 3d - 如何在现实生活中将椅子对象放置在与椅子精确尺寸的 arcore 中?
- multithreading - 多个线程调用相同函数的问题
- wordpress - Wordpress 按元字段上的日期或最后修改日期排序
- gem-fury - 如何限制 gemfury 中的私有包访问,以便特定用户只能在包列表中看到特定包?
- kubernetes - .NET Core - 正确停止 Kestrel
- json - 使用 Jackson 动态替换 Json 值