Maven packaged to run jar

Source: Internet
Author: User

To tie in with automating the deployment of Hudson, a recent study has been made to package the Eclipse Maven project into runnable jar functions and corresponding resource files.
Since we have multiple runnable tasks in our project that need to be exported separately when packaged into jars, the Pom mentions that the repository needs to be consistent and cannot deploy a single task to submit the code once. So consider the class where main in the jar is exported by passing parameters during MVN packaging. Define the properties in the Pom and pass the parameters when the command is executed. such as MVN package-dtaskfinalname=contentpoolurl-dmainclassname= Com.ifec.blueair.task.contentpoolurl.ContentPoolUrlRun, in addition to the MVN export jar can not find the configuration file, found that the current directory is not found, by adding manifestentries to specify the directory. The contents of Class-path in the MANIFEST.MF generated by Maven are missing something, such as the current execution directory (.), which can be added in the manifestentries above.
pom.xml content is as follows:
<project xmlns= "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>

<parent>
<groupId>com.ifec.blueair</groupId>
<artifactId>blueair-packagemanager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativepath>, .... /blueair-packagemanager/pom.xml</relativepath>
</parent>

<artifactId>blueair-task</artifactId>
<packaging>jar</packaging>

<name>blueair-task</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<propertiesName>contentpoolurl</propertiesName>
<taskFinalName>contentpoolurl</taskFinalName>
<mainClassName>com.ifec.blueair.task.contentpoolurl.ContentPoolUrlRun</mainClassName>
</properties>
    
<build>
<finalName>${taskFinalName}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sh</include>
<include>**/${propertiesName}.properties</include>
<include>**/log4j.properties</include>
<include>**/config.properties</include>
</includes>
<filtering>true</filtering>
<targetPath>${project.build.directory}</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${taskFinalName}_lib</classpathPrefix>
<mainClass>${mainClassName}</mainClass>
</manifest> <!--the content of Class-path in maven-generated MANIFEST.MF is missing something, such as the current Line directory (.), you can add it by manifestentries the above method. -
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/${taskfinalname}_lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
    
<dependencies>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>

</dependencies>
</project>

Maven packaged to run 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.