Maven Packaged executable jar package

Source: Internet
Author: User

Create a folder Haha, which contains three items

    • Haha.java
    • Main.java
    • Pom.xml

Pom.xml

<?xmlVersion= "1.0" encoding= "UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>Wyf</groupId>    <artifactId>Clonesite</artifactId>    <version>1.0-snapshot</version>    <build>        <sourceDirectory>.</sourceDirectory>        <finalName>haha</finalName>        <plugins>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <artifactId>Maven-compiler-plugin</artifactId>                <configuration>                    <source>1.7</source>                    <target>1.7</target>                    <encoding>Utf-8</encoding>                </configuration>            </plugin>        </plugins>    </build></project>

The MAVEN compliance convention is more than the configuration principle, it has a default directory structure, but you can also specify the source code directory and the resource file directory in build.

Main.java

publicclass Main{    publicstaticvoidmain(String[] args) {        System.out.println("天下大势为我所控");    }}

Haha.java

publicclass Haha {    publicstaticvoidmain(String[] args) {        System.out.println("hello world");    }}

Open the CMD,MVN package under this folder and pack to generate the target directory.
CD to target, execution java -cp haha.jar Main runs the main class, and execution java -cp haha.jar Haha runs the Haha class.
I think this way of running the jar is better than packaging it directly into a runnable jar package because it's easier to package.
The executable jar package can actually java -cp haha.jar Something run other classes in the same way, except that it has the default main class.

Maven Packaged executable jar package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.