取maven copy部分

  1. 云栖社区>
  2. 博客>
  3. 正文

取maven copy部分

小麋鹿666 2018-01-13 15:05:13 浏览1407
展开阅读全文

mvn deploy:deploy-file -DgroupId=com.mycompany -DartifactId=my-project -Dversion=1.0.0 -Dpackaging=jar -Dfile=myproject-name.jar -Durl=http://localhost:8081/nexus/content/repositories/release/ -DrepositoryId=releasemvn install:install-file -Dfile=/home.jar -DgroupId=xx -DartifactId=xx -Dversion=1.0 -Dpackaging=jar

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. 这句话可以将下载的jar包,放到本地仓库中  

 

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. maven实际应用  
  2. lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  4.  <modelVersion>4.0.0</modelVersion>  
  5.   
  6.  <groupId>com.xuanwu</groupId>  
  7.  <artifactId>sxt_mtoserver</artifactId>  
  8.  <version>1.0-SNAPSHOT</version>  
  9.  <packaging>jar</packaging>  
  10.   
  11.  <name>sxt_mtoserver</name>  
  12.  <url>http://maven.apache.org</url>  
  13.   
  14.  <properties>  
  15.      <!-- 自定义变量 -->  
  16.    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  17.    <project.deploy>deploy</project.deploy>  
  18.  </properties>  
  19.    
  20.  <build>  
  21.      <plugins>  
  22.          <!-- maven编译插件,指定编译jdk版本     
  23.          如果编译目标版本是1.6,然后在1.5虚拟机上运行错误提示Bad version number in .class file。所以,如果希望在1.5编译时就发现错误,就要用1.5的编译器-->  
  24.          <plugin>  
  25.              <groupId>org.apache.maven.plugins</groupId>  
  26.              <artifactId>maven-compiler-plugin</artifactId>  
  27.              <version>2.3.2</version>  
  28.              <configuration>  
  29.                <source>1.5</source>  
  30.                <target>1.5</target>  
  31.            </configuration>  
  32.          </plugin>  
  33.            
  34.          <!-- maven打包插件,可执行jar包配置 -->  
  35.          <!--    
  36.          <plugin>  
  37.              <groupId>org.apache.maven.plugins</groupId>  
  38.              <artifactId>maven-shade-plugin</artifactId>  
  39.              <version>1.4</version>  
  40.              <executions>  
  41.                <execution>  
  42.                    <phase>package</phase>  
  43.                    <goals>  
  44.                        <goal>shade</goal>  
  45.                    </goals>  
  46.                    <configuration>  
  47.                        <transformers>  
  48.                            <transformer  
  49.                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  50.                            <mainClass>com.xuanwu.mtoserver.App</mainClass>  
  51.                            </transformer>  
  52.                        </transformers>  
  53.                    </configuration>  
  54.                </execution>  
  55.            </executions>  
  56.          </plugin>  
  57.          -->  
  58.            
  59.          <!-- maven源文件插件 -->  
  60.             
  61.          <plugin>  
  62.              <groupId>org.apache.maven.plugins</groupId>  
  63.              <artifactId>maven-resources-plugin</artifactId>  
  64.              <version>2.5</version>  
  65.              <executions>  
  66.                    <execution>  
  67.                        <id>copy-resources</id>  
  68.                        <phase>package</phase>  
  69.                        <goals>  
  70.                            <goal>copy-resources</goal>  
  71.                        </goals>  
  72.                        <configuration>  
  73.                            <encoding>UTF-8</encoding>  
  74.                            <outputDirectory>${project.build.directory}/${project.deploy}/conf  
  75.                            </outputDirectory>  
  76.                            <resources>  
  77.                                <resource>  
  78.                                    <directory>src/main/resources/</directory>  
  79.                                    <includes>  
  80.                                        <include>*.xml</include>  
  81.                                        <include>*.properties</include>  
  82.                                        <include>*.conf</include>  
  83.                                    </includes>  
  84.                                </resource>  
  85.                            </resources>  
  86.                        </configuration>  
  87.                    </execution>  
  88.                    <execution>  
  89.                        <id>copy-sh</id>  
  90.                        <phase>package</phase>  
  91.                        <goals>  
  92.                            <goal>copy-resources</goal>  
  93.                        </goals>  
  94.                        <configuration>  
  95.                            <encoding>UTF-8</encoding>  
  96.                            <outputDirectory>${project.build.directory}/${project.deploy}/  
  97.                            </outputDirectory>  
  98.                            <resources>  
  99.                                <resource>  
  100.                                    <directory>src/main/resources/</directory>  
  101.                                    <includes>  
  102.                                        <include>*.sh</include>  
  103.                                        <include>*.pl</include>  
  104.                                        <include>*.bat</include>  
  105.                                    </includes>  
  106.                                </resource>  
  107.                            </resources>  
  108.                        </configuration>  
  109.                    </execution>  
  110.                </executions>  
  111.          </plugin>  
  112.            
  113.            
  114.          <!-- maven打jar包插件,打包后不包含pom.xml文件 -->  
  115.          <plugin>  
  116.              <groupId>org.apache.maven.plugins</groupId>  
  117.              <artifactId>maven-jar-plugin</artifactId>  
  118.              <version>2.3.2</version>  
  119.              <configuration>   
  120.                 <archive>  
  121.                     <!-- 打包后不包括pom的描述文件 -->   
  122.                      <addMavenDescriptor>false</addMavenDescriptor>  
  123.                    <!-- Maven在生成jar时,并不知道这个jar是lib还是app,所以使用以下这个插件告之MAVEN这个jar为app,指定main类 -->   
  124.                    <manifest>      
  125.                           <mainClass>com.xuanwu.mtoserver.util.Test</mainClass>      
  126.                       </manifest>  
  127.                </archive>   
  128.             </configuration>  
  129.              <executions>  
  130.                    <execution>  
  131.                        <id>jarexclude</id>  
  132.                        <phase>package</phase>  
  133.                        <goals>  
  134.                            <goal>jar</goal>  
  135.                        </goals>  
  136.                        <configuration>  
  137.                            <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>  
  138.                            <excludes>  
  139.                                <exclude>*.xml</exclude>  
  140.                                <exclude>*.pl</exclude>  
  141.                                <exclude>*.sql</exclude>  
  142.                                <exclude>*.properties</exclude>  
  143.                                <exclude>*.bat</exclude>  
  144.                                <exclude>*.conf</exclude>  
  145.                                <exclude>*.sh</exclude>  
  146.                                <exclude>*.doc</exclude>  
  147.                            </excludes>  
  148.                        </configuration>  
  149.                    </execution>  
  150.            </executions>  
  151.          </plugin>  
  152.            
  153.          <!-- maven打war包插件,打包后不包含pom.xml文件 -->  
  154.          <!--   
  155.          <plugin>  
  156.              <groupId>org.apache.maven.plugins</groupId>  
  157.              <artifactId>maven-war-plugin</artifactId>  
  158.              <version>2.1.1</version>  
  159.              <configuration>   
  160.                 <archive>   
  161.                      <addMavenDescriptor>false</addMavenDescriptor>   
  162.                </archive>   
  163.             </configuration>  
  164.          </plugin>  
  165.           -->  
  166.             
  167.           <!-- 想要把工程的所有依赖的jar都一起打包 -->  
  168.           <!--   
  169.          <plugin>  
  170.              <groupId>org.apache.maven.plugins</groupId>  
  171.              <artifactId>maven-assembly-plugin</artifactId>  
  172.              <version>2.2.1</version>  
  173.              <configuration>  
  174.                  <descriptorRefs>  
  175.                    <descriptorRef>jar-with-dependencies</descriptorRef>  
  176.                  </descriptorRefs>  
  177.            </configuration>  
  178.          </plugin>  
  179.           -->  
  180.             
  181.          <!-- 将项目所有包放到一个指定目录 -->  
  182.          <plugin>  
  183.              <groupId>org.apache.maven.plugins</groupId>  
  184.              <artifactId>maven-dependency-plugin</artifactId>  
  185.              <version>2.3</version>  
  186.              <executions>  
  187.                    <execution>  
  188.                        <id>copy-dependencies</id>  
  189.                        <phase>package</phase>  
  190.                        <goals>  
  191.                            <goal>copy-dependencies</goal>  
  192.                        </goals>  
  193.                        <configuration>  
  194.                            <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>  
  195.                            <overWriteReleases>false</overWriteReleases>  
  196.                            <overWriteSnapshots>false</overWriteSnapshots>  
  197.                            <overWriteIfNewer>true</overWriteIfNewer>  
  198.                        </configuration>  
  199.                    </execution>  
  200.            </executions>  
  201.          </plugin>  
  202.            
  203.      </plugins>  
  204.  </build>  
  205.  <dependencies>  
  206.    <dependency>  
  207.      <groupId>junit</groupId>  
  208.      <artifactId>junit</artifactId>  
  209.      <version>3.8.1</version>  
  210.      <scope>test</scope>  
  211.    </dependency>  
  212.      
  213.    <dependency>  
  214.        <groupId>axis</groupId>  
  215.        <artifactId>axis</artifactId>  
  216.        <version>1.4</version>  
  217.        <type>jar</type>  
  218.        <scope>compile</scope>  
  219.    </dependency>  
  220.    <dependency>  
  221.        <groupId>axis</groupId>  
  222.        <artifactId>axis-jaxrpc</artifactId>  
  223.        <version>1.4</version>  
  224.        <type>jar</type>  
  225.        <scope>compile</scope>  
  226.    </dependency>  
  227.    <dependency>  
  228.        <groupId>commons-discovery</groupId>  
  229.        <artifactId>commons-discovery</artifactId>  
  230.        <version>20040218.194635</version>  
  231.        <type>jar</type>  
  232.        <scope>compile</scope>  
  233.    </dependency>  
  234.    <dependency>  
  235.        <groupId>commons-logging</groupId>  
  236.        <artifactId>commons-logging</artifactId>  
  237.        <version>1.1.1</version>  
  238.        <type>jar</type>  
  239.        <scope>compile</scope>  
  240.    </dependency>  
  241.    <dependency>  
  242.        <groupId>axis</groupId>  
  243.        <artifactId>axis-saaj</artifactId>  
  244.        <version>1.4</version>  
  245.        <type>jar</type>  
  246.        <scope>compile</scope>  
  247.    </dependency>  
  248.    <dependency>  
  249.        <groupId>axis</groupId>  
  250.        <artifactId>axis-wsdl4j</artifactId>  
  251.        <version>1.5.1</version>  
  252.        <type>jar</type>  
  253.        <scope>compile</scope>  
  254.    </dependency>  
  255.  </dependencies>  
  256. lt;/project>  



 


 

原地址:http://www.blogjava.NET/toby/archive/2011/11/01/362460.html

 

 

 

 

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. maven工程编译并生成可执行JAR包命令  
  2. 2012-02-03 09:54 提问者: 储流香 |浏览次数:3230次  
  3.   
  4. 在JAVA持续集成构建中,需要从SVN check out的代码编译并打成可执行JAR包,高手告诉我maven命令如何?  
  5.   
  6. 我用mvn compile package或mvn jar:jar都能打成jar包,但不能执行  
  7.   
  8. 问题补充:  
  9.   
  10. 利用HUDSON+MAVEN编译打包java maven工程,打包成可执行的JAR包。在HUDSON中需要填写maven命令。我想知道的是打可执行jar包的maven命令。  
  11. 我的pom.xml中添加了:  
  12. <plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs<descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><archive<manifest>mainClass>com.ImageViewer.dao.ImageViewer</mainClass></manifest>               </archive></configuration></plugin>  
  13.   
  14. 目前的mvn命令是:clean assembly:assembly  
  15. 但是build时报错:mavenExecutionResult exceptions not empty  
  16. org.apache.maven.InternalErrorException: Internal error: ava.lang.NullPointerException  
  17. 换成jar:jar打成的jar包不能执行。  
  18.   
  19. 我来帮他解答  
  20. 满意回答  
  21. 2012-02-03 15:28  
  22.   
  23. <plugins>  
  24. <plugin>  
  25.     <groupId>org.apache.maven.plugins</groupId>  
  26.     <artifactId>maven-compiler-plugin</artifactId>  
  27.     <version>2.3.2</version>  
  28.     <configuration>  
  29.         <source>1.6</source>  
  30.         <target>1.6</target>  
  31.         <encoding>UTF-8</encoding>  
  32.     </configuration>  
  33. </plugin>  
  34. <plugin>  
  35.     <groupId>org.apache.maven.plugins</groupId>  
  36.     <artifactId>maven-jar-plugin</artifactId>  
  37.     <configuration>  
  38.     <archive>  
  39.     <manifest>  
  40.     <addClasspath>true</addClasspath>  
  41.     <classpathPrefix>lib/</classpathPrefix>  
  42.     <mainClass>com.abc.ABCTest</mainClass>    -->入口类名  
  43.     </manifest>  
  44.     </archive>  
  45.     </configuration>  
  46. </plugin>  
  47. <plugin>  
  48.     <groupId>org.apache.maven.plugins</groupId>  
  49.     <artifactId>maven-dependency-plugin</artifactId>  
  50.     <executions>  
  51.     <execution>  
  52.     <id>copy</id>  
  53.     <phase>install</phase>  
  54.     <goals>  
  55.         <goal>copy-dependencies</goal>  
  56.     </goals>  
  57.     <configuration>  
  58.     <outputDirectory>${project.build.directory}/lib</outputDirectory>  -->拷贝所以依赖存放位置  
  59.     </configuration>  
  60.     </execution>  
  61.     </executions>  
  62. </plugin>  
  63. </plugins>   
  64.   
  65. 然后再用mvn clean install 装配一下,打出的jar包就可以运行  



 

 

 

 

 

 

 

maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized

分类: maven

 

提交到nexus时候报错:

 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

原来是没有配置认证。

 

maven目录conf的setting.xml里,

  1.   <server>  
  2.     <id>releases</id>  
  3.     <username>admin</username>  
  4.     <password>admin123</password>  
  5.   </server>  
  6.  <server>  
  7.   <id>snapshots</id>  
  8.   <username>admin</username>  
  9.   <password>admin123</password>  
  10.   </server>  
  11. </servers>  

用户名和密码都是nexus的。再次deploy即可。

注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

  1. <!-- 配置远程发布到私服,mvn deploy -->  
  2.     <distributionManagement>  
  3.         <repository>  
  4.             <id>releases</id>  
  5.             <name>Nexus Release Repository</name>  
  6.             <url>http://10.1.81.199:8081/nexus/content/repositories/releases/</url>  
  7.         </repository>  
  8.         <snapshotRepository>  
  9.             <id>snapshots</id>  
  10.             <name>Nexus Snapshot Repository</name>  
  11.             <url>http://10.1.81.199:8081/nexus/content/repositories/snapshots/</url>  
  12.         </snapshotRepository>  
  13.     </distributionManagement>  




如果这里不配置,会报错:报错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

posted @ 2017-02-25 16:20 左正 阅读(86) 评论(0) 编辑 收藏
 

公告

 
 

mvn deploy:deploy-file -DgroupId=com.mycompany -DartifactId=my-project -Dversion=1.0.0 -Dpackaging=jar -Dfile=myproject-name.jar -Durl=http://localhost:8081/nexus/content/repositories/release/ -DrepositoryId=releasemvn install:install-file -Dfile=/home.jar -DgroupId=xx -DartifactId=xx -Dversion=1.0 -Dpackaging=jar

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. 这句话可以将下载的jar包,放到本地仓库中  

 

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. maven实际应用  
  2. lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  4.  <modelVersion>4.0.0</modelVersion>  
  5.   
  6.  <groupId>com.xuanwu</groupId>  
  7.  <artifactId>sxt_mtoserver</artifactId>  
  8.  <version>1.0-SNAPSHOT</version>  
  9.  <packaging>jar</packaging>  
  10.   
  11.  <name>sxt_mtoserver</name>  
  12.  <url>http://maven.apache.org</url>  
  13.   
  14.  <properties>  
  15.      <!-- 自定义变量 -->  
  16.    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  17.    <project.deploy>deploy</project.deploy>  
  18.  </properties>  
  19.    
  20.  <build>  
  21.      <plugins>  
  22.          <!-- maven编译插件,指定编译jdk版本     
  23.          如果编译目标版本是1.6,然后在1.5虚拟机上运行错误提示Bad version number in .class file。所以,如果希望在1.5编译时就发现错误,就要用1.5的编译器-->  
  24.          <plugin>  
  25.              <groupId>org.apache.maven.plugins</groupId>  
  26.              <artifactId>maven-compiler-plugin</artifactId>  
  27.              <version>2.3.2</version>  
  28.              <configuration>  
  29.                <source>1.5</source>  
  30.                <target>1.5</target>  
  31.            </configuration>  
  32.          </plugin>  
  33.            
  34.          <!-- maven打包插件,可执行jar包配置 -->  
  35.          <!--    
  36.          <plugin>  
  37.              <groupId>org.apache.maven.plugins</groupId>  
  38.              <artifactId>maven-shade-plugin</artifactId>  
  39.              <version>1.4</version>  
  40.              <executions>  
  41.                <execution>  
  42.                    <phase>package</phase>  
  43.                    <goals>  
  44.                        <goal>shade</goal>  
  45.                    </goals>  
  46.                    <configuration>  
  47.                        <transformers>  
  48.                            <transformer  
  49.                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  50.                            <mainClass>com.xuanwu.mtoserver.App</mainClass>  
  51.                            </transformer>  
  52.                        </transformers>  
  53.                    </configuration>  
  54.                </execution>  
  55.            </executions>  
  56.          </plugin>  
  57.          -->  
  58.            
  59.          <!-- maven源文件插件 -->  
  60.             
  61.          <plugin>  
  62.              <groupId>org.apache.maven.plugins</groupId>  
  63.              <artifactId>maven-resources-plugin</artifactId>  
  64.              <version>2.5</version>  
  65.              <executions>  
  66.                    <execution>  
  67.                        <id>copy-resources</id>  
  68.                        <phase>package</phase>  
  69.                        <goals>  
  70.                            <goal>copy-resources</goal>  
  71.                        </goals>  
  72.                        <configuration>  
  73.                            <encoding>UTF-8</encoding>  
  74.                            <outputDirectory>${project.build.directory}/${project.deploy}/conf  
  75.                            </outputDirectory>  
  76.                            <resources>  
  77.                                <resource>  
  78.                                    <directory>src/main/resources/</directory>  
  79.                                    <includes>  
  80.                                        <include>*.xml</include>  
  81.                                        <include>*.properties</include>  
  82.                                        <include>*.conf</include>  
  83.                                    </includes>  
  84.                                </resource>  
  85.                            </resources>  
  86.                        </configuration>  
  87.                    </execution>  
  88.                    <execution>  
  89.                        <id>copy-sh</id>  
  90.                        <phase>package</phase>  
  91.                        <goals>  
  92.                            <goal>copy-resources</goal>  
  93.                        </goals>  
  94.                        <configuration>  
  95.                            <encoding>UTF-8</encoding>  
  96.                            <outputDirectory>${project.build.directory}/${project.deploy}/  
  97.                            </outputDirectory>  
  98.                            <resources>  
  99.                                <resource>  
  100.                                    <directory>src/main/resources/</directory>  
  101.                                    <includes>  
  102.                                        <include>*.sh</include>  
  103.                                        <include>*.pl</include>  
  104.                                        <include>*.bat</include>  
  105.                                    </includes>  
  106.                                </resource>  
  107.                            </resources>  
  108.                        </configuration>  
  109.                    </execution>  
  110.                </executions>  
  111.          </plugin>  
  112.            
  113.            
  114.          <!-- maven打jar包插件,打包后不包含pom.xml文件 -->  
  115.          <plugin>  
  116.              <groupId>org.apache.maven.plugins</groupId>  
  117.              <artifactId>maven-jar-plugin</artifactId>  
  118.              <version>2.3.2</version>  
  119.              <configuration>   
  120.                 <archive>  
  121.                     <!-- 打包后不包括pom的描述文件 -->   
  122.                      <addMavenDescriptor>false</addMavenDescriptor>  
  123.                    <!-- Maven在生成jar时,并不知道这个jar是lib还是app,所以使用以下这个插件告之MAVEN这个jar为app,指定main类 -->   
  124.                    <manifest>      
  125.                           <mainClass>com.xuanwu.mtoserver.util.Test</mainClass>      
  126.                       </manifest>  
  127.                </archive>   
  128.             </configuration>  
  129.              <executions>  
  130.                    <execution>  
  131.                        <id>jarexclude</id>  
  132.                        <phase>package</phase>  
  133.                        <goals>  
  134.                            <goal>jar</goal>  
  135.                        </goals>  
  136.                        <configuration>  
  137.                            <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>  
  138.                            <excludes>  
  139.                                <exclude>*.xml</exclude>  
  140.                                <exclude>*.pl</exclude>  
  141.                                <exclude>*.sql</exclude>  
  142.                                <exclude>*.properties</exclude>  
  143.                                <exclude>*.bat</exclude>  
  144.                                <exclude>*.conf</exclude>  
  145.                                <exclude>*.sh</exclude>  
  146.                                <exclude>*.doc</exclude>  
  147.                            </excludes>  
  148.                        </configuration>  
  149.                    </execution>  
  150.            </executions>  
  151.          </plugin>  
  152.            
  153.          <!-- maven打war包插件,打包后不包含pom.xml文件 -->  
  154.          <!--   
  155.          <plugin>  
  156.              <groupId>org.apache.maven.plugins</groupId>  
  157.              <artifactId>maven-war-plugin</artifactId>  
  158.              <version>2.1.1</version>  
  159.              <configuration>   
  160.                 <archive>   
  161.                      <addMavenDescriptor>false</addMavenDescriptor>   
  162.                </archive>   
  163.             </configuration>  
  164.          </plugin>  
  165.           -->  
  166.             
  167.           <!-- 想要把工程的所有依赖的jar都一起打包 -->  
  168.           <!--   
  169.          <plugin>  
  170.              <groupId>org.apache.maven.plugins</groupId>  
  171.              <artifactId>maven-assembly-plugin</artifactId>  
  172.              <version>2.2.1</version>  
  173.              <configuration>  
  174.                  <descriptorRefs>  
  175.                    <descriptorRef>jar-with-dependencies</descriptorRef>  
  176.                  </descriptorRefs>  
  177.            </configuration>  
  178.          </plugin>  
  179.           -->  
  180.             
  181.          <!-- 将项目所有包放到一个指定目录 -->  
  182.          <plugin>  
  183.              <groupId>org.apache.maven.plugins</groupId>  
  184.              <artifactId>maven-dependency-plugin</artifactId>  
  185.              <version>2.3</version>  
  186.              <executions>  
  187.                    <execution>  
  188.                        <id>copy-dependencies</id>  
  189.                        <phase>package</phase>  
  190.                        <goals>  
  191.                            <goal>copy-dependencies</goal>  
  192.                        </goals>  
  193.                        <configuration>  
  194.                            <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>  
  195.                            <overWriteReleases>false</overWriteReleases>  
  196.                            <overWriteSnapshots>false</overWriteSnapshots>  
  197.                            <overWriteIfNewer>true</overWriteIfNewer>  
  198.                        </configuration>  
  199.                    </execution>  
  200.            </executions>  
  201.          </plugin>  
  202.            
  203.      </plugins>  
  204.  </build>  
  205.  <dependencies>  
  206.    <dependency>  
  207.      <groupId>junit</groupId>  
  208.      <artifactId>junit</artifactId>  
  209.      <version>3.8.1</version>  
  210.      <scope>test</scope>  
  211.    </dependency>  
  212.      
  213.    <dependency>  
  214.        <groupId>axis</groupId>  
  215.        <artifactId>axis</artifactId>  
  216.        <version>1.4</version>  
  217.        <type>jar</type>  
  218.        <scope>compile</scope>  
  219.    </dependency>  
  220.    <dependency>  
  221.        <groupId>axis</groupId>  
  222.        <artifactId>axis-jaxrpc</artifactId>  
  223.        <version>1.4</version>  
  224.        <type>jar</type>  
  225.        <scope>compile</scope>  
  226.    </dependency>  
  227.    <dependency>  
  228.        <groupId>commons-discovery</groupId>  
  229.        <artifactId>commons-discovery</artifactId>  
  230.        <version>20040218.194635</version>  
  231.        <type>jar</type>  
  232.        <scope>compile</scope>  
  233.    </dependency>  
  234.    <dependency>  
  235.        <groupId>commons-logging</groupId>  
  236.        <artifactId>commons-logging</artifactId>  
  237.        <version>1.1.1</version>  
  238.        <type>jar</type>  
  239.        <scope>compile</scope>  
  240.    </dependency>  
  241.    <dependency>  
  242.        <groupId>axis</groupId>  
  243.        <artifactId>axis-saaj</artifactId>  
  244.        <version>1.4</version>  
  245.        <type>jar</type>  
  246.        <scope>compile</scope>  
  247.    </dependency>  
  248.    <dependency>  
  249.        <groupId>axis</groupId>  
  250.        <artifactId>axis-wsdl4j</artifactId>  
  251.        <version>1.5.1</version>  
  252.        <type>jar</type>  
  253.        <scope>compile</scope>  
  254.    </dependency>  
  255.  </dependencies>  
  256. lt;/project>  



 


 

原地址:http://www.blogjava.NET/toby/archive/2011/11/01/362460.html

 

 

 

 

[html] view plain copy
 
 print?在CODE上查看代码片派生到我的代码片
  1. maven工程编译并生成可执行JAR包命令  
  2. 2012-02-03 09:54 提问者: 储流香 |浏览次数:3230次  
  3.   
  4. 在JAVA持续集成构建中,需要从SVN check out的代码编译并打成可执行JAR包,高手告诉我maven命令如何?  
  5.   
  6. 我用mvn compile package或mvn jar:jar都能打成jar包,但不能执行  
  7.   
  8. 问题补充:  
  9.   
  10. 利用HUDSON+MAVEN编译打包java maven工程,打包成可执行的JAR包。在HUDSON中需要填写maven命令。我想知道的是打可执行jar包的maven命令。  
  11. 我的pom.xml中添加了:  
  12. <plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs<descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><archive<manifest>mainClass>com.ImageViewer.dao.ImageViewer</mainClass></manifest>               </archive></configuration></plugin>  
  13.   
  14. 目前的mvn命令是:clean assembly:assembly  
  15. 但是build时报错:mavenExecutionResult exceptions not empty  
  16. org.apache.maven.InternalErrorException: Internal error: ava.lang.NullPointerException  
  17. 换成jar:jar打成的jar包不能执行。  
  18.   
  19. 我来帮他解答  
  20. 满意回答  
  21. 2012-02-03 15:28  
  22.   
  23. <plugins>  
  24. <plugin>  
  25.     <groupId>org.apache.maven.plugins</groupId>  
  26.     <artifactId>maven-compiler-plugin</artifactId>  
  27.     <version>2.3.2</version>  
  28.     <configuration>  
  29.         <source>1.6</source>  
  30.         <target>1.6</target>  
  31.         <encoding>UTF-8</encoding>  
  32.     </configuration>  
  33. </plugin>  
  34. <plugin>  
  35.     <groupId>org.apache.maven.plugins</groupId>  
  36.     <artifactId>maven-jar-plugin</artifactId>  
  37.     <configuration>  
  38.     <archive>  
  39.     <manifest>  
  40.     <addClasspath>true</addClasspath>  
  41.     <classpathPrefix>lib/</classpathPrefix>  
  42.     <mainClass>com.abc.ABCTest</mainClass>    -->入口类名  
  43.     </manifest>  
  44.     </archive>  
  45.     </configuration>  
  46. </plugin>  
  47. <plugin>  
  48.     <groupId>org.apache.maven.plugins</groupId>  
  49.     <artifactId>maven-dependency-plugin</artifactId>  
  50.     <executions>  
  51.     <execution>  
  52.     <id>copy</id>  
  53.     <phase>install</phase>  
  54.     <goals>  
  55.         <goal>copy-dependencies</goal>  
  56.     </goals>  
  57.     <configuration>  
  58.     <outputDirectory>${project.build.directory}/lib</outputDirectory>  -->拷贝所以依赖存放位置  
  59.     </configuration>  
  60.     </execution>  
  61.     </executions>  
  62. </plugin>  
  63. </plugins>   
  64.   
  65. 然后再用mvn clean install 装配一下,打出的jar包就可以运行  



 

 

 

 

 

 

 

maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized

分类: maven

 

提交到nexus时候报错:

 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

原来是没有配置认证。

 

maven目录conf的setting.xml里,

  1.   <server>  
  2.     <id>releases</id>  
  3.     <username>admin</username>  
  4.     <password>admin123</password>  
  5.   </server>  
  6.  <server>  
  7.   <id>snapshots</id>  
  8.   <username>admin</username>  
  9.   <password>admin123</password>  
  10.   </server>  
  11. </servers>  

用户名和密码都是nexus的。再次deploy即可。

注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

  1. <!-- 配置远程发布到私服,mvn deploy -->  
  2.     <distributionManagement>  
  3.         <repository>  
  4.             <id>releases</id>  
  5.             <name>Nexus Release Repository</name>  
  6.             <url>http://10.1.81.199:8081/nexus/content/repositories/releases/</url>  
  7.         </repository>  
  8.         <snapshotRepository>  
  9.             <id>snapshots</id>  
  10.             <name>Nexus Snapshot Repository</name>  
  11.             <url>http://10.1.81.199:8081/nexus/content/repositories/snapshots/</url>  
  12.         </snapshotRepository>  
  13.     </distributionManagement>  




如果这里不配置,会报错:报错:Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy (default-deploy) on project git-demo: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

posted @ 2017-02-25 16:20 左正 阅读(86) 评论(0) 编辑 收藏
 

公告

本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/p/6442111.html,如需转载请自行联系原作者

网友评论

登录后评论
0/500
评论
小麋鹿666
+ 关注