Jar: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Java")
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
* http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html
=Internal=
=Internal=


* [[java#Subjects|Java]]
* [[java#Subjects|Java]]
=Overview=
=Create a JAR from Files Located in a Directory Different from the Current One=
Use <tt>-C</tt> ''after'' the JAR name and use <tt>.</tt> instead of <tt>*</tt> if you want to include ''all'' from <tt><directory-we-want-to-JAR-from></tt>:
<syntaxhighlight lang='bash'>
jar -C <directory-we-want-to-JAR-from> cfv <JAR-file-name> .
</syntaxhighlight>
Example:
<syntaxhighlight lang='bash'>
jar cfv ./target/A.ear -C ./target/ear-A-content .
</syntaxhighlight>
=Update an existing JAR File=
<syntaxhighlight lang='bash'>
jar ufv <jar-file> [-C <some_dir>] .
</syntaxhighlight>
The command fails if the target JAR does not exist, so it will have to be created with "c".
=Extract a Specific File from a JAR=
jar xf .../source.jar META-INF/MANIFEST.MF
=Do Not Create a Manifest File=
jar cfM ...
=Create a JAR with a Specific Manifest Content=
jar cfm .../''<jar-file-name>.jar'' .../''<maifest-file>'' *
=Executable JAR=
==Executable JAR in META-INF==
<pre>
Main-Class: some.class.Main
</pre>
==Executable JAR in Maven==
{{Internal|Maven_jar_Plugin#Declaring_a_Main_Class_in_JAR|Maven JAR Plugin - Declaring a Main Class}}
==Executable JAR in ant==
<pre>
<target name="jar" depends="compile">
    <jar destfile="target/tdanalyzer.jar">
        <zipfileset dir="./target/classes" includes="**/*.class"/>
        <manifest>
          <attribute name="Main-Class" value="com.novaordis.universus.tdanalyzer.Main"/>
        </manifest>
    </jar>
</target>
</pre>

Latest revision as of 02:03, 27 March 2021

External

Internal

Overview

Create a JAR from Files Located in a Directory Different from the Current One

Use -C after the JAR name and use . instead of * if you want to include all from <directory-we-want-to-JAR-from>:

jar -C <directory-we-want-to-JAR-from> cfv <JAR-file-name> .

Example:

jar cfv ./target/A.ear -C ./target/ear-A-content .

Update an existing JAR File

jar ufv <jar-file> [-C <some_dir>] .

The command fails if the target JAR does not exist, so it will have to be created with "c".

Extract a Specific File from a JAR

jar xf .../source.jar META-INF/MANIFEST.MF

Do Not Create a Manifest File

jar cfM ...

Create a JAR with a Specific Manifest Content

jar cfm .../<jar-file-name>.jar .../<maifest-file> *

Executable JAR

Executable JAR in META-INF

Main-Class: some.class.Main

Executable JAR in Maven

Maven JAR Plugin - Declaring a Main Class

Executable JAR in ant

<target name="jar" depends="compile">
    <jar destfile="target/tdanalyzer.jar">
        <zipfileset dir="./target/classes" includes="**/*.class"/>
        <manifest>
           <attribute name="Main-Class" value="com.novaordis.universus.tdanalyzer.Main"/>
        </manifest>
    </jar>
</target>