Home > Software engineering >  Converting an existing Java project to Maven in vscode
Converting an existing Java project to Maven in vscode

Time:05-12

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.
Can someone tell me how to convert that project to maven WITH VSCODE.

CodePudding user response:

Here are some steps:

  1. Tell VS Code to use Maven.
  2. Add a pom.xml to your project to spell out the dependencies.
  3. Ask Maven to download the dependencies to your local .m2 repository.
  4. Use the Maven lifecycle to compile/test/package your code.

You'll have no problem as long as all the JARs you need are in 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.

If this is an old Java project you might want to think about updating. Check the JARs for security vulnerabilities and upgrade them if you can. Hopefully there will be a good Junit suite to prove that upgrades didn't break your code.

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.

This is easy in IntelliJ. I'd prefer it to VS Code.

  • Related