Java app's jar package is all-in-oneness

Source: Internet
Author: User

Previously developed Java programs because of the more dependent jar package, the start command is "Java-classpath.: Lib/*.jar The main class name", which requires specifying the CLASSPATH, the entry class name, and the existence of jar packet missing hidden dangers.

Now, with Springboot's MAVEN packaging plug-in, you can organize your dependent jar packages into a jar file.

I. Creating a MAVEN Project

A name to pick up. It's called configclient. Use the following plug-in in the Pom.xml file.

Specify MainClass, note that this mainclass is not the class of the current project, it is the main class of the program we wrote ourselves.

1 <plugin>2                 <groupId>Org.springframework.boot</groupId>3                 <Artifactid>Spring-boot-maven-plugin</Artifactid>4                 <Configuration>5                     <MainClass>Com.bonc.tool.Tool2</MainClass>6                      <Layout>Zip</Layout>7                 </Configuration>8                 <executions>9                     <Execution>Ten                         <Goals> One                             <goal>Repackage</goal> A                         </Goals> -                     </Execution> -                 </executions> the             </plugin>
springboot Packaging Plug-inSecond, packaging
MVN Package
Iii. entering target 1. Unzip the jar file

Get three of directories:

(1) Org Application entry class, responsible for loading the check jar package

(2) Boot-inf contains two directories

Lib classes, Lib is used to store all of the dependent jar packages, classes is stored in our own development program

(3) Meta-inf contains a central file for this article MANIFEST.MF this file is read first when you start the Java program to get the main classpath.

manifest-version:1.01.5.93.2.11.8.0_131main-class: Org.springframework.boot.loader.PropertiesLauncher # Java Application Portal Class
2. Move files

If we write a program that is not packaged as a jar file, put them in boot-inf/classes

If we write a program that has been packaged as a jar file, place the jar file and all of the dependent jar packages into boot-inf/lib

3. Non-compressed packaging
BOOT-inf meta-inf org

-C indicates that create creates a new file

-V indicates that the verbose detailed information is listed

-F Specify File name

-M does not create a new MANIFEST.MF

-0 Do not compress, just organize the files together.

This 0 must be added, which means no compression. Because the internal jar package has been compressed, it is compressed again, causing the internal jar to be unreadable.

4. Run the jar package
Java-jar Configclient.jar

At this point, a runnable jar package can be used.

Java app's jar package is all-in-oneness

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.