Languages
[Edit]
EN

VS Code - create Java Maven project

11 points
Created by:
halfera
411

In this article, we want to show how to create and develop a Java Maven project in VS Code.

Prerequirements

Edit
  1. installed VS Code (link),
  2. installed Java 11 (JDK) or later (link),
  3. installed Extension Pack for Java in VS Code (link).

Hints:

 

Example project

Edit

Presented project configuration provides example configuration that uses:

  • Lombok preprocessor to generate automatically constructors, getters, setters, etc. in classes,
  • JUnit 4 that lets to write unit tests.

 

Project structure

Edit
Java Maven project in VS Code.
Java Maven project in VS Code.

Project preparation

Edit

1. Create a directory and go there.

e.g. C:\Projects\my-project

 

2. Create a Maven project file inside.

e.g. pom.xml file:

Where:

  • junit is optional and allows writing Java tests,
  • assertj-core is optional and provides nice assertions API,
  • lombok provides additional Java preprocessor (generates constructors, setters, getters, etc. in classes).

 

3. Create a Java source code file inside.

e.g. src/com/example/Program.java file:

 

4. Create a test source code file inside.

e.g. test/com/example/ProgramTest.java file:

 

5. Run in the command line:

Hint: to skip tests use: mvn clean install -Dmaven.test.skip=true

 

6. Open the directory in VS Code.

 

See also

Edit
  1. VS Code - create Python project

Alternative titles

  1. VS Code - example Java Maven project
  2. VSCode - create Java Maven project
  3. VSCode - example Java Maven project
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join