取maven copy部分
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
- 这句话可以将下载的jar包,放到本地仓库中
- maven实际应用
- lt;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>
- <groupId>com.xuanwu</groupId>
- <artifactId>sxt_mtoserver</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>sxt_mtoserver</name>
- <url>http://maven.apache.org</url>
- <properties>
- <!-- 自定义变量 -->
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.deploy>deploy</project.deploy>
- </properties>
- <build>
- <plugins>
- <!-- maven编译插件,指定编译jdk版本
- 如果编译目标版本是1.6,然后在1.5虚拟机上运行错误提示Bad version number in .class file。所以,如果希望在1.5编译时就发现错误,就要用1.5的编译器-->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <!-- maven打包插件,可执行jar包配置 -->
- <!--
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>1.4</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <transformers>
- <transformer
- implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
- <mainClass>com.xuanwu.mtoserver.App</mainClass>
- </transformer>
- </transformers>
- </configuration>
- </execution>
- </executions>
- </plugin>
- -->
- <!-- maven源文件插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.5</version>
- <executions>
- <execution>
- <id>copy-resources</id>
- <phase>package</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <encoding>UTF-8</encoding>
- <outputDirectory>${project.build.directory}/${project.deploy}/conf
- </outputDirectory>
- <resources>
- <resource>
- <directory>src/main/resources/</directory>
- <includes>
- <include>*.xml</include>
- <include>*.properties</include>
- <include>*.conf</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
- <execution>
- <id>copy-sh</id>
- <phase>package</phase>
- <goals>
- <goal>copy-resources</goal>
- </goals>
- <configuration>
- <encoding>UTF-8</encoding>
- <outputDirectory>${project.build.directory}/${project.deploy}/
- </outputDirectory>
- <resources>
- <resource>
- <directory>src/main/resources/</directory>
- <includes>
- <include>*.sh</include>
- <include>*.pl</include>
- <include>*.bat</include>
- </includes>
- </resource>
- </resources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <!-- maven打jar包插件,打包后不包含pom.xml文件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <archive>
- <!-- 打包后不包括pom的描述文件 -->
- <addMavenDescriptor>false</addMavenDescriptor>
- <!-- Maven在生成jar时,并不知道这个jar是lib还是app,所以使用以下这个插件告之MAVEN这个jar为app,指定main类 -->
- <manifest>
- <mainClass>com.xuanwu.mtoserver.util.Test</mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>jarexclude</id>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>
- <excludes>
- <exclude>*.xml</exclude>
- <exclude>*.pl</exclude>
- <exclude>*.sql</exclude>
- <exclude>*.properties</exclude>
- <exclude>*.bat</exclude>
- <exclude>*.conf</exclude>
- <exclude>*.sh</exclude>
- <exclude>*.doc</exclude>
- </excludes>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <!-- maven打war包插件,打包后不包含pom.xml文件 -->
- <!--
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <version>2.1.1</version>
- <configuration>
- <archive>
- <addMavenDescriptor>false</addMavenDescriptor>
- </archive>
- </configuration>
- </plugin>
- -->
- <!-- 想要把工程的所有依赖的jar都一起打包 -->
- <!--
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2.1</version>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- </plugin>
- -->
- <!-- 将项目所有包放到一个指定目录 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.3</version>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/${project.deploy}/lib</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>false</overWriteSnapshots>
- <overWriteIfNewer>true</overWriteIfNewer>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>axis</groupId>
- <artifactId>axis</artifactId>
- <version>1.4</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>axis</groupId>
- <artifactId>axis-jaxrpc</artifactId>
- <version>1.4</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>commons-discovery</groupId>
- <artifactId>commons-discovery</artifactId>
- <version>20040218.194635</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>axis</groupId>
- <artifactId>axis-saaj</artifactId>
- <version>1.4</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>axis</groupId>
- <artifactId>axis-wsdl4j</artifactId>
- <version>1.5.1</version>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
- </dependencies>
- lt;/project>
原地址:http://www.blogjava.NET/toby/archive/2011/11/01/362460.html
- maven工程编译并生成可执行JAR包命令
- 2012-02-03 09:54 提问者: 储流香 |浏览次数:3230次
- 在JAVA持续集成构建中,需要从SVN check out的代码编译并打成可执行JAR包,高手告诉我maven命令如何?
- 我用mvn compile package或mvn jar:jar都能打成jar包,但不能执行
- 问题补充:
- 利用HUDSON+MAVEN编译打包java maven工程,打包成可执行的JAR包。在HUDSON中需要填写maven命令。我想知道的是打可执行jar包的maven命令。
- 我的pom.xml中添加了:
- <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>
- 目前的mvn命令是:clean assembly:assembly
- 但是build时报错:mavenExecutionResult exceptions not empty
- org.apache.maven.InternalErrorException: Internal error: ava.lang.NullPointerException
- 换成jar:jar打成的jar包不能执行。
- 我来帮他解答
- 满意回答
- 2012-02-03 15:28
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <classpathPrefix>lib/</classpathPrefix>
- <mainClass>com.abc.ABCTest</mainClass> -->入口类名
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy</id>
- <phase>install</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/lib</outputDirectory> -->拷贝所以依赖存放位置
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- 然后再用mvn clean install 装配一下,打出的jar包就可以运行
maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized
提交到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里,
- <server>
- <id>releases</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- <server>
- <id>snapshots</id>
- <username>admin</username>
- <password>admin123</password>
- </server>
- </servers>
用户名和密码都是nexus的。再次deploy即可。
注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:
- <!-- 配置远程发布到私服,mvn deploy -->
- <distributionManagement>
- <repository>
- <id>releases</id>
- <name>Nexus Release Repository</name>
- <url>http://10.1.81.199:8081/nexus/content/repositories/releases/</url>
- </repository>
- <snapshotRepository>
- <id>snapshots</id>
- <name>Nexus Snapshot Repository</name>
- <url>http://10.1.81.199:8081/nexus/content/repositories/snapshots/</url>
- </snapshotRepository>
- </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
取maven copy部分的更多相关文章
- Maven copy方式列举
maven copy有很多种方法: 1.maven-antrun-plugin (使用ant复制) <build> <finalName>flex</finalName& ...
- maven copy jar 插件
插件比较特殊 eclipse下的 首先声明插件 <pluginManagement> <plugin> <groupId>org.apache.maven.plu ...
- maven copy 依赖jar包
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-depen ...
- k8s版jenkins--master/slave模式实现CI/CD---带solo开源博客项目--带maven、djk、git工具
k8s环境: 192.168.0.91 master 192.168.0.92 node 192.168.0.96 gitlab 192.168.0.98 harbor k8s集群安装请参照:http ...
- maven相关的学习资料
1, maven的settings配置文件详解: http://blog.csdn.net/jinshuaiwang/article/details/23686099 2,maven原理---翡青的博 ...
- Java + Selenium + TestNG + Maven
环境准备: 1. Java: Install Java jdk: Version: java 1.8 or aboveConfigure Java Environment Variables:Add ...
- ubuntu16.04 搭建nexus+maven 学习
/opt/nexus-2.10.0-02/bin vim nexus 关键配置: RUN_AS_USER=root JAVA_HOME=/usr/lib/java/jre export NEXUS_H ...
- JavaWeb日常笔记
1. XML文档的作用和解析 1. XML的基本概述: XML的主要是用来存储一对多的数据,另外还可以用来当做配置文件存储数据.XML的表头如下: <?xml version='1.0' e ...
- HttpRunnerManager平台异步生成及展示代码覆盖率报告
ant+jacoco+jenkins+HttpRunnerManager代码覆盖率统计平台搭建 实现思路通过jenkins构建,并使用HttpRunnerManager异步实现报告更新与展示. 现在整 ...
随机推荐
- javaScript-继承2种方式
1.组合继承 组合继承带来的问题很明细就是父类的构造函数会调用两次,如: function Person(name, age, sex) { this.name = name; this.age = ...
- SVN的使用、分支合并及解决冲突详解
一.什么是SVN SVN是Subversion的简称,是一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS. 二.SVN的下载安装 下载地址:http ...
- nio笔记
http://blog.csdn.net/z69183787/article/category/2191483此人的博客 首先你要知道阻塞和非阻塞的概念,阻塞体现在这个线程不能干别的了,只能在这里等着 ...
- HTML+CSS图文排版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- 问候Maven3(笔记一)
第一节:Maven 简介 百度百科:Maven 官网:http://maven.apache.org/ 第二节:Maven 安装与配置 Maven 下载:http://maven.apache.org ...
- 如何提交代码到CEPH Repo。 顺便庆祝下,提交了第一个ceph pull request。实现了从0到1的突破
庆祝一下!经过社区老司机的带路,昨天提交了第一个ceph pull request.实现了从0到1的突破,希望再接再厉提交更多代码到社区,为社区发展贡献一点自己力量. 提交的第一个被社区fix的bug ...
- hdu 5001(概率DP)
Walk Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 关于HTML&CSS的笔记
最近在看Jon Duckett的HTML&CSS一书(http://book.douban.com/subject/6585090/),书的排版和讲解方式很不错,并且有许多其他教学材料遗漏的关 ...
- oracle去掉字段值中的某些字符串
我想去掉字段值中的“_” select replace(fdisplayname,'_','') from SHENZHENJM1222.B replace 第一个参数:字段/值,第二个参数时替换字符 ...
- jquery通配符说明
按姓名匹配 1,name前缀为aa的所有div的jquery对象 Js代码 收藏代码$("div[name^='aa']"); 2,name后缀为aa的所有div的jquery对象 ...