简体   繁体   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. I am trying to make a JSON parser for a project using GSON in java with Maven in Intellij or VS Code. Whenever I try to compile/run the debugger on the file (ex: javac jsonParser.java) it always says the "com.google.gson" and related objects such as "GSON gson = new Gson();"每当我尝试在文件上编译/运行调试器(例如:javac jsonParser.java)时,它总是说“com.google.gson”和相关对象,例如“GSON gson = new Gson();” does not exist.不存在。

Things I have tried:我尝试过的事情:

  • 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 additional java files in the folder would still get the above compilation error. 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 文件仍然会出现上述编译错误。

  • Manually add the dependency information in the pom.xml file在 pom.xml 文件中手动添加依赖信息

  • Use the built in "add dependency" features in both Intellij and VS Code在 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 folder 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文件夹
  • Running sets of Maven commands in VS Code ---> "mvn install" "mvn package" "mvn dependency:resolve" which run fine with no errors在 VS Code 中运行 Maven 命令集 ---> "mvn install" "mvn package" "mvn dependency:resolve" 运行良好,没有错误

TLDR: Would someone be able to walk me through adding a 3rd party library in Maven/Gradle and/or Intellij/VS Code? TLDR:有人可以指导我在 Maven/Gradle 和/或 Intellij/VS Code 中添加第 3 方库吗? If it helps, I am willing to use Gradle or some other (freely available) software if that is easier/preferred?如果有帮助,我愿意使用 Gradle 或其他一些(免费提供)软件,如果这更容易/更喜欢? I am new to any sort of software development (first year CS student) so I have no experience in terms of making a completed project.我对任何类型的软件开发都是新手(一年级 CS 学生),所以我没有完成项目的经验。

  1. You look up the GSON coordinates (groupId, artifactId, version) in MavenCentral( http://search.maven.org )您在 MavenCentral ( http://search.maven.org ) 中查找 GSON 坐标(groupId、artifactId、version)

  2. You take the XML from MavenCentral and copy it to the <dependencies> section of your pom.xml您从 MavenCentral 获取 XML 并将其复制到pom.xml<dependencies>部分

  3. You use GSON in your Java code您在 Java 代码中使用 GSON

  4. You build your project with mvn clean verify您使用mvn clean verify构建您的项目

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

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