Create jar executable

I extracted the jar executable containing xml, java class, etc. In fact, this jar executable is a dependency library. I need to change one line of code in one of the class files in this library. I have successfully edited the class file, now I want to repack it into an executable jar. how to do it.

+1
source share
3 answers

Just zip it all up, a jar is just a zip file.

  • Unzip .jar
  • Change class
  • Converts the entire structure to .zip
  • Rename it to .jar
  • There you go.

You can automate it using the ant <jar> task.

As stated below, you can use the jar tool that comes with the JDK installation. jar -xvf your.jar to extract and jar -cvf your.jar inputfiles . See the documentation.

What makes an executable JAR file consists in that it contains in its structure a file located in META-INF/MANIFEST.MF , which describes what an entry point class is, for example:

 Manifest-Version: 1.0 Main-Class: foo.bar.FooBar 
+5
source

using jar command you can do it

take the command line and get your root folder where all the classes are. and use the following command

  jar -cvf myjarname.jar * * means all the files and folders in that location 
+1
source

Also make sure you have a file association for executable jars. If you do not, you can create this link to this batch file:

 @ECHO off SETLOCAL ENABLEDELAYEDEXPANSION :: this script creates a file association for executable .jar files ECHO Creating .jar file association... ECHO JAVA_HOME is %JAVA_HOME% IF NOT DEFINED JAVA_HOME GOTO :FAIL REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f REG ADD "HKCR\jarfile\shell" /ve /f REG ADD "HKCR\jarfile\shell\open" /ve /f ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f ECHO Finished creating .jar file association for executable .jar files. PAUSE GOTO EOF :FAIL ECHO Script failed. JAVA_HOME not defined. PAUSE 
0
source

All Articles