I'm trying to create a maven project - so that I can compile Java files in the root folder and output the class files in another folder.
I've already downloaded mvn.
I'm trying to integrate with VS Code. My goal is to edit the java files in VS Code and on saving the compiler saves the .class file in the appropriate output folder.
That's all - no war or jar files.
Any help?
Open the Maven project folder in VS Code via File menu -> Open Folder... and select the appname folder. Open the Command Palette (via the View menu or by right-clicking) and type in and select Tasks: Configure task then select Create tasks. json from template . Choose maven ("Executes common Maven commands").
You can also create a Java project using the Java: Create Java Project command. Bring up the Command Palette (Ctrl+Shift+P) and then type java to search for this command. After selecting the command, you will be prompted for the location and name of the project. You can also choose your build tool from this command.
Launch/Attach - You can either launch the Java project within VS Code or attach to any running JVM process in debug mode, locally or remotely. Breakpoints - Conditional breakpoints by Hit Count is supported and can easily be set using the inline breakpoint settings window.
It also helps you to create new Java projects, packages, and classes. To get the complete Java language support in Visual Studio Code, you can install the Extension Pack for Java, which includes the Project Manager for Java extension.
Here is a complete list of steps - you may not need steps 1-3 but am including them for completeness:-
vscode:extension/vscjava.vscode-java-pack
and then clicking on the green Install button after it opens in VS Code.mvn archetype:generate -DgroupId=
com.companyname.appname-DartifactId=
appname-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
. This will create an appname folder with Maven's Standard Directory Layout (i.e. src/main/java/com/companyname/appname
and src/main/test/com/companyname/appname
to begin with and a sample "Hello World!" Java file named appname.java
and associated unit test named appnameTest.java
).*Tasks: Configure task
then select Create tasks.json from template
.Choose maven ("Executes common Maven commands"). This creates a tasks.json file with "verify" and "test" tasks. More can be added corresponding to other Maven Build Lifecycle phases. To specifically address your requirement for classes to be built without a JAR file, a "compile" task would need to be added as follows:
{ "label": "compile", "type": "shell", "command": "mvn -B compile", "group": "build" },
Save the above changes and then open the Command Palette and select "Tasks: Run Build Task" then pick "compile" and then "Continue without scanning the task output". This invokes Maven, which creates a target
folder at the same level as the src
folder with the compiled class files in the target\classes
folder.
Addendum: How to run/debug a class
Following a question in the comments, here are some steps for running/debugging:-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With