3

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.

9
  • First make it work as-is then convert. No magic can help you. Commented May 14, 2022 at 15:13
  • Since the Java language support of VSCode is Eclipse, converting the project to a Maven project should be possible with Eclipse in order to be able to edit the converted project with both Eclipse and VSCode: in Eclipse do File > Open Projects from File System... and then right-click the project folder and choose Configure > Convert to Maven Project. Commented May 16, 2022 at 8:01
  • @ThorbjørnRavnAndersen In Eclipse this magic is called Smart Import. Commented May 16, 2022 at 8:09
  • @howlger This does not locate the original dependencies. Commented May 16, 2022 at 13:40
  • @ThorbjørnRavnAndersen Of course it does. Commented May 16, 2022 at 18:53

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

4 Comments

“Spell out the dependencies” - isn’t this where help is needed?
I don’t think so. Method is more important here.
i 'Asked maven to download the dependencies'. it's not listening. i feel this answer should be more in depth for new users...what exactly does 'ask' mean in context of vscode? is there a maven explorer, is there a command like (pip install)?
'Ask' means 'create a pom.xml for your project with all the dependencies inside'. Maven is built into IntelliJ. The Maven command line equivalent is "mvn" command. I expect that somebody will go and read about Maven without me having to recreate all its documentation here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.