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.
-
First make it work as-is then convert. No magic can help you.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2022-05-14 15:13:09 +00:00Commented 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.howlger– howlger2022-05-16 08:01:52 +00:00Commented May 16, 2022 at 8:01
-
@ThorbjørnRavnAndersen In Eclipse this magic is called Smart Import.howlger– howlger2022-05-16 08:09:08 +00:00Commented May 16, 2022 at 8:09
-
@howlger This does not locate the original dependencies.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2022-05-16 13:40:15 +00:00Commented May 16, 2022 at 13:40
-
@ThorbjørnRavnAndersen Of course it does.howlger– howlger2022-05-16 18:53:57 +00:00Commented May 16, 2022 at 18:53
1 Answer
Here are some steps:
- Tell VS Code to use Maven.
- Add a pom.xml to your project to spell out the dependencies.
- Ask Maven to download the dependencies to your local .m2 repository.
- 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.