我有一个问题,因为我在 Intellij 中编写了一个使用 native 包的小应用程序,除了一个 org.json
。现在需要在 Eclipse
中打开它(假设 版本:Mars.2 Release (4.5.2)
)。所以我在项目的主目录下添加了一个pom.xml
文件:
<?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>groupId</groupId>
<artifactId>companyManagement</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
</dependencies>
</project>
在 Maven Projects
下的 Intellij 中,我将单击 Generate sources and update folders
一切正常。另一方面,在 Eclipse
中,它不是。我已经完成了:File
->new
->Java Project
->use default location
并指向 main文件夹(其中包括 pom.xml
)。接下来我完成了:右键单击 pom.xml
->run as
->Maven install
。 maven-compiler-plugin
没有问题,但是好像没有下载org.json
。我没有选中:不自动从远程存储库更新依赖项
。还有什么我可以尝试修复它?因为 IDE 仍然看不到 org.json
(我想通过 maven 做到这一点)
已编辑
实际上我已经将版本号更改为 20151123
并且它似乎没问题,因为 mvn install
返回:
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/json/json/20151123/json-20151123.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/json/json/20151123/json-20151123.pom (5 KB at 7.5 KB/sec)
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/json/json/20151123/json-20151123.jar
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/json/json/20151123/json-20151123.jar (48 KB at 170.0 KB/sec)
但是import org.json.*
仍然被标记为不可用(红色下划线)
最佳答案
在那种情况下,你可以试试这个。它可能对您有所帮助。
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.6</version>
</dependency>
而不是你的依赖
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
</dependency>
关于java - 在eclipse中安装maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36068433/