Main-class and Class-path configuration files when Maven projects generate jars

Source: Internet
Author: User

Write this blog mainly for their own later can quickly find.

Add the following build content to the project node of the Pom.xml file:

    <build> <plugins> <plugin> <groupid>org.apache.maven.plugi Ns</groupid> <artifactId>maven-jar-plugin</artifactId> <version>2. 3.2</version> <configuration> <archive> <
                            manifest> <!--change Addclasspath to True if Daks is desktop version--> <addClasspath>true</addClasspath> <classpathprefix>lib/</c
                            Lasspathprefix> <mainClass>com.daks.timesheethelper.App</mainClass>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> </mani
               Fest>         <manifestEntries> <Permissions>${Permissions}</Permissions>
                        <Caller-Allowable-Codebase>${Caller-Allowable-Codebase}</Caller-Allowable-Codebase>
            </manifestEntries> </archive> </configuration> </plugin> <plugin> &LT;GROUPID&GT;ORG.APACHE.MAVEN.PLUGINS&LT;/GROUPID&G
                T
                <artifactId>maven-dependency-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-dependencies</id&
                        Gt <phase>package</phase> <configuration> <overwrite Releases>false</overwritereleases> <overwritesnapshots>fAlse</overwritesnapshots> <overWriteIfNewer>true</overWriteIfNewer>
                            <outputDirectory> ${project.build.directory}/lib 
                            </outputDirectory> </configuration> <goals>
                    <goal>copy-dependencies</goal> </goals> </execution> </executions> </plugin> </plugins> & Lt;/build>

The end result is a Lib directory under target that contains some third-party jars that the project uses, or a jar of its own other projects, and then Main-class and Class-path configuration information in the MF file of the main jar package. This is the condition that guarantees that the jar package is executable.


See also: http://www.alanzeng.cn/2015/08/maven-executive-jar/

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.