'Exporting jar file in VS Code

I recently switched over to VS Code from Eclipse as my primary Java editor. I need to frequently export my code into a jar file which includes all libraries and dependencies for running on a Raspberry Pi. However, I currently see no obvious menus or tabs to accomplish this purpose.

Are there any extensions or built-in features which will behave in a manner similar to Eclipse's "Export" window? Would I be able to easily write a script to export for me?



Solution 1:[1]

If you want to export jar file then you first get maven extension installed in your vscode. In explorer of your vscode, you can find different options as shown in screenshot below. enter image description here

In JAVA PROJECTS you can find option export jar(shown by right arrow). Just click on it and it will automatically create jar file of your project.

Solution 2:[2]

Let's say your project has app package. Under that a App.java class resides which has the main method.It also uses yourlib.jar library. Now after building App.java file from vscode the class files let's assume the class file folder structure is

bin
   |app
       |App.class

Now go to the bin folder and make a manifest.txt file in bin folder. manifest.txt file must contain Main-Class . here app.App is the name of the Main-Class.Following can be the contents of manifest.txt file

 Main-Class: app.App
 Class-Path: yourlib.jar

Note manifest.txt file must be ended with a new line or carriage return . If your manifest file only contains Main-Class no Class-Path The after Main-Class: app.App put a new line at least. Now copy the yourlib.jar file in bin and run this command from the bin folder

jar cfmv App.jar manifest.txt app/

then test the Jar with

java -jar App.jar

Note: You can run and build class file by installing https://marketplace.visualstudio.com/items?itemName=redhat.java extension.

Solution 3:[3]

I use "pure java" as my projects are simple enough, and the button you are looking for is this one

magic button screenshot

I only have installed Extension Pack for Java

only plugin needed screenshot

Next steps are pretty intuitive, even the "checkboxes" for including external jars

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mayank Kumar Thakur
Solution 2 lazyTank
Solution 3