繁体   English   中英

如何为 Intellij 和/或 VS Code 添加依赖项/第三方 java 库到 Maven 中?

[英]How do I add dependencies/3rd party java libraries into Maven for Intellij and/or VS Code?

I am trying to make a JSON parser for a project using GSON in java with Maven in Intellij or VS Code. 每当我尝试在文件上编译/运行调试器(例如:javac jsonParser.java)时,它总是说“com.google.gson”和相关对象,例如“GSON gson = new Gson();” 不存在。

我尝试过的事情:

  • Watching many tutorials/read many walkthroughs on how to add a dependency/3rd party JAR, however, the best I was able to do was make the App.java file in a default Maven project template be able to use the GSON library, but any文件夹中的其他 java 文件仍然会出现上述编译错误。

  • 在 pom.xml 文件中手动添加依赖信息

  • 在 Intellij 和 VS Code 中使用内置的“添加依赖项”功能
  • I have tried on both Ubuntu and Windows 10 (including adding things to the environment variables)... Often times, I am able to see the dependency automatically added to the pom.xml file, as well as see the JAR file in my project文件夹
  • 在 VS Code 中运行 Maven 命令集 ---> "mvn install" "mvn package" "mvn dependency:resolve" 运行良好,没有错误

TLDR:有人可以指导我在 Maven/Gradle 和/或 Intellij/VS Code 中添加第 3 方库吗? 如果有帮助,我愿意使用 Gradle 或其他一些(免费提供)软件,如果这更容易/更喜欢? 我对任何类型的软件开发都是新手(一年级 CS 学生),所以我没有完成项目的经验。

  1. 您在 MavenCentral ( http://search.maven.org ) 中查找 GSON 坐标(groupId、artifactId、version)

  2. 您从 MavenCentral 获取 XML 并将其复制到pom.xml<dependencies>部分

  3. 您在 Java 代码中使用 GSON

  4. 您使用mvn clean verify构建您的项目

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM