Java packaging settings and running commands

Source: Internet
Author: User

One, Java Run command

There are three ways to start a Java program:

1, Java-jar

In the generated jar package, the manifest file defines the main Class, which you can use to

Java-jar Test.jar

2, JAVA-CP

There is no main class configuration in the generated jar package, which can be used

JAVA-CP Test.jar Cn.matt.Test

The command can also start the Java program from the class file, which must be explicitly listed for the dependent jar package, separated by a semicolon (Windows) or colon (Linux)

JAVA-CP./target/classes;test2.jar cn.matt.Test

3, Java-djava.ext.dirs

When the jar does not contain a dependent package, it is not convenient to use JAVA-CP, which allows you to specify the dependent package directory only

Java-djava.ext.dirs=. Cn.matt.maven_test. App

Second, Java Packaging settings

With Maven packaging, the generated jar package does not run directly (without the main Class) and does not contain a dependent jar package, by default

Specify the main Class and include the dependent jar package configuration:

<build> <plugins> <plugin> <artifactid>maven-assembly-plugin</artifacti                 D> <configuration> <appendAssemblyId>false</appendAssemblyId>                 <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef>                         </descriptorRefs> <archive> <manifest> <mainclass>cn.matt.maven_test3. app</mainclass> </manifest> </archive> </configuratio n> <executions> <execution> <id>make-assembly</id&                     Gt <phase>package</phase> <goals> <goal>assembly</goal         > </goals> </execution>    </executions> </plugin> </plugins> </build> 

Reference:

MAVEN package contains the Main method jar and runs

The Java command line runs the main class in the Jar

Java packaging settings and running commands

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.