Maven project package jar depends on external jar, maven project package jar

Source: Internet
Author: User
Tags unpack

Maven project package jar depends on external jar, maven project package jar

 

Sometimes we want to develop some small java programs. We need to package them into jar and execute them separately to create a maven project. maven is very convenient and there is a plug-in that is automatically packaged into jar, but sometimes our project may depend on other jar packages, so it is very troublesome.

I recently encountered a small problem. The company's projects have scheduled tasks, and sometimes there may be unexecuted situations or execution errors. So I need some additional functions that can be manually executed. If you put a button on the page and re-execute it once, for fear of permission issues, write webservice and then write external jar to call webservice. Although it is very simple, it should be written on the original project, after writing the code, you have to submit it to the test department for testing. After the test, you have to lead the approval before you can use it online. Therefore, you have to write an external jar.

 

This is my file directory, which is generally written. Please criticize and correct it.

It is a bit of a headache now. To become a jar, you need to rely on a lot of external jar. After Baidu and their own attempts, I finally wrote it. The plugins in the pom configuration are as follows:

<plugins>             <plugin>              <groupId>org.apache.maven.plugins</groupId>              <artifactId>maven-jar-plugin</artifactId>              <version>2.4</version>              <configuration>                  <archive>                     <manifest>                         <addClasspath>true</addClasspath>                         <classpathPrefix>lib/</classpathPrefix>                         <mainClass>com.coamctech.historyreport.App</mainClass>                     </manifest>                  </archive>              </configuration>           </plugin>              <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-assembly-plugin</artifactId>             <version>2.4</version>             <!-- The configuration of the plugin -->             <configuration>                 <!-- Specifies the configuration file of the assembly plugin -->                 <descriptors>                     <descriptor>src/main/assembly/package.xml</descriptor>                 </descriptors>             </configuration>             <executions>                 <execution>                     <id>make-assembly</id>                     <phase>package</phase>                     <goals>                         <goal>single</goal>                     </goals>                 </execution>             </executions>         </plugin>         </plugins>

 

 

The assembly plug-in is used to introduce its configuration file:

<Assembly xmlns = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id> bin </id> <! -- Finally packaged into a zip file for publishing --> <formats> <format> zip </format> </formats> <! -- Adds dependencies to zip package under lib directory --> <dependencySets> <dependencySet> <! -- Do not use the artifact of the Project. Do not decompress the third-party jar, package it into the lib directory of the zip file --> <useProjectArtifact> false </useProjectArtifact> <outputDirectory> lib </outputDirectory> <unpack> false </unpack> </dependencySet> </dependencySets> <fileSets> <! -- Package the project-related description file into the root directory of the zip file --> <fileSet> <directory >$ {project. basedir} </directory> <outputDirectory>/</outputDirectory> <includes> <include> README * </include> <include> LICENSE * </include> <include> NOTICE * </include> </includes> </fileSet> <! -- Package the project configuration file into the config directory of the zip file --> <fileSet> <directory >$ {project. basedir }\ src \ main \ resources </directory> <outputDirectory> </outputDirectory> <supported des> <include> *. xml </include> <include> *. properties </include> </program des> </fileSet> <! -- Package the startup script file in the script file directory of the project (src/main/scripts) into the directory of the zip file --> <fileSet> <directory >$ {project. basedir }\ src \ main \ bin </directory> <outputDirectory> </outputDirectory> <includes> <include> startup. * </include> </includes> </fileSet> <! -- Package the project script file (except the startup script file) into the script directory of the zip file --> <! -- <FileSet> <directory >$ {project. build. scriptSourceDirectory} </directory> <outputDirectory> </outputDirectory> <excludes> <exclude> startup. * </exclude> </excludes> </fileSet> --> <! -- Package the jar file compiled by the project into the root directory of the zip file --> <fileSet> <directory >$ {project. build. directory} </directory> <outputDirectory> </outputDirectory> <includes> <include> *. jar </include> </program des> </fileSet> </fileSets> </assembly>

 

 

 

Refer to blog:

Http://blog.csdn.net/WANGYAN9110/article/details/38646677/

 

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.