MAVEN项目打包成jar,供普通Java项目调用

1、定义生成格式

把pom.xml中<packaging>设置为jar
<name>scenarioname> 

2、将MAVEN依赖也打进jar包中

在工程的pom.xml文件中配置maven-assembly-plugin

<build>  
    <plugins>  
    <plugin>
         <artifactId>maven-compiler-pluginartifactId>
             <version>2.3.2version>
             <configuration>
                 <source>1.8source>
                 <target>1.8target>
             configuration>
     plugin>
       <plugin>  
         <artifactId>maven-assembly-pluginartifactId>  
           <configuration>  
             <archive>  
               <manifest>  
                <mainClass>kpmg.thrift.scenario.taskmainClass>  
              manifest>  
                  archive>  
                  <descriptorRefs>  
                      <descriptorRef>jar-with-dependenciesdescriptorRef>  
                  descriptorRefs>  
              configuration>  
              <executions>
                      <execution>
                           <id>make-assemblyid>
                           <phase>packagephase>
                           <goals>
                                <goal>singlegoal>
                           goals>
                      execution>
              executions>
          plugin>  
        plugins>  
    build> 

3、右键项目,MAVEN-》UPDATE PROJECT….

4、右键项目,RUN AS-》MAVEN CLEAN

5、右键项目,RUN AS-》MAVEN INSTALL

6、项目目录target下生成有jar
scenario-1.0-SNAPSHOT-jar-with-dependencies.jar

你可能感兴趣的:(MAVEN项目打包成jar,供普通Java项目调用)