简体   繁体   English

在 vscode 中将现有的 Java 项目转换为 Maven

[英]Converting an existing Java project to Maven in vscode

I have this old Java project without anything, I want to use maven with it because some dependencies are missing and I can't find the libs.我有这个没有任何东西的旧 Java 项目,我想使用 maven,因为缺少一些依赖项并且我找不到库。
Can someone tell me how to convert that project to maven WITH VSCODE .有人可以告诉我如何将该项目转换为 maven WITH VSCODE

Here are some steps:以下是一些步骤:

  1. Tell VS Code to use Maven .告诉 VS Code使用 Maven
  2. Add a pom.xml to your project to spell out the dependencies.pom.xml添加到您的项目中以说明依赖项。
  3. Ask Maven to download the dependencies to your local .m2 repository.要求 Maven 将依赖项下载到本地 .m2 存储库。
  4. Use the Maven lifecycle to compile/test/package your code.使用Maven 生命周期来编译/测试/打包您的代码。

You'll have no problem as long as all the JARs you need are in Maven Central.只要您需要的所有 JAR 都在 Maven Central 中,您就没有问题。 If some of them were internal to your organization you'll have to find them and pull them from a private repo or add them to your local .m2.如果其中一些是您组织内部的,您必须找到它们并将它们从私人存储库中提取或将它们添加到您的本地 .m2 中。

If this is an old Java project you might want to think about updating.如果这是一个旧的 Java 项目,您可能需要考虑更新。 Check the JARs for security vulnerabilities and upgrade them if you can.检查 JAR 是否存在安全漏洞,如果可以,请升级它们。 Hopefully there will be a good Junit suite to prove that upgrades didn't break your code.希望会有一个好的 Junit 套件来证明升级没有破坏你的代码。

One last suggestion: Try to compile and run it on a LTS version of the JDK - 11 or 17. Don't continue with JDK 8 - it's past the end of its support life.最后一个建议:尝试在 JDK 11 或 17 的 LTS 版本上编译和运行它。不要继续使用 JDK 8——它的支持寿命已经结束。

This is easy in IntelliJ.这在 IntelliJ 中很容易。 I'd prefer it to VS Code.我更喜欢它而不是 VS Code。

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

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