[ez tut] how2 make executable jar file w/ vs code & command line

gzdani

Newbie
Joined
Feb 8, 2024
Messages
14
Reaction score
12
first u wanna go to the vscode marketplace install extension java extention pack for configuring java enviroment w/ vscode , then write ur program like this


1707447014402.png



then u need to compile the code by packing jar inside vscode, (see bottom left corner) java projects , then look for export jar . click on that


1707447146222.png



its gon ask u to specify main class so select MyCalc . thats the entry point
1707447261651.png



thats it, ur exe jar has been created . gratz .
now if u wanna find the directory just click it and select open with java platform se binary


1707447444109.png


more info below about~(command lines)~read on

1st thing when ur usin command line u needa kno the jar tool 4 certain switches when makin an exejar
  • c creates new archive file
  • v generates verbose output this is 4 ur extracted resource on standard output .
  • m includes manifest information from the given mf file.
  • f specifies the archive file name
  • x extracts files from the archive file
open ur javac with the command line " javac MyCalc.java " usin this javac command will create the MyCalc.class in ur directory . if u got multiple java files - make sure 2 compile them 2 , so u can put that package into ur jar
~some more shi u may need 2 kno below~

ur manifest file is key cuz it sets entry points ,to ur application so main class will execute the jarfile
  • so , create a manifest file with .mf extensions in same directories , that way u dont gotta set the class path explicitly
  • you need to write main-class, hit " : " hit spacebar , then classname where ur entry point is gonna be (MyCalc) . after that hit enter
now u just save the .MF file here


1707448240875.png



now open the cmd , write this out usin ur jar tool switches that r provided
jar -cvfm <jarfilename.jar> <manifestfile> <classname.class>


1707448366786.png


for this example i just named it CALC.jar it will be executed after u run the command . boom .
ur done . its that ez
 
Last edited:
Back
Top