使用maven将代码到私服

在上一节中,我们讲述了maven私服搭建 ,那么本章,我们讲述如何使用maven将代码打包并上传到maven私服上。

一、maven pom.xml关键配置信息。

   <distributionManagement>
 	 <repository>
        <id>releases</id>
        <name>Nexus Release Repository</name>
        <url>http://192.9.104.17:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://192.9.104.17:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
 </distributionManagement>

 二、maven 代码编译、打包、生成java doc相关配置

 

 <build>
	<plugins>
	
	
	    <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://192.9.104.116:8090/manager</url>
                    <server>tomcat-remote-deploy</server>
                    <path>/search-web</path>
                </configuration>
        </plugin>	
		  
      <plugin>
      
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.7</version>
        <configuration>
          <connectors>
            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8888</port>
              <maxIdleTime>30000</maxIdleTime>
            </connector>
          </connectors>
          <!-- 
          <webAppSourceDirectory>${project.build.directory}/${pom.artifactId}-${pom.version}</webAppSourceDirectory> -->
           <webApp>
              <contextPath>/search</contextPath>
           </webApp>
        </configuration>
      </plugin>
      
		  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${plugin.version}</version>
          </plugin>
  		  <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>${plugin.version}</version>
            </plugin>
	       <plugin>
			 <groupId>org.apache.maven.plugins</groupId>
			 <artifactId>maven-source-plugin</artifactId>
			 <version>${plugin.version}</version>
			 <executions>
				 <execution>
				 <id>attach-sources</id>
				 <phase>verify</phase>
				 <goals>
					 <goal>jar-no-fork</goal>
				 </goals>
				 </execution>
			 </executions>
		 </plugin>
		 
		  <plugin>
			 <groupId>org.apache.maven.plugins</groupId>
			 <artifactId>maven-compiler-plugin</artifactId>
			 <version>${plugin.version}</version>
<!-- 			 <version>2.1.2</version> -->
			 <configuration>
			 	<source>1.6</source>
			 	<target>1.6</target>
			 	<complianceLevel>1.6</complianceLevel>
			 </configuration>
		 </plugin>
		 
		  <plugin> 
			 <groupId>org.apache.maven.plugins</groupId>
			 <artifactId>maven-javadoc-plugin</artifactId>
			 <version>${java.doc.version}</version>
			 <executions>
				 <execution>
				 <id>attach-javadocs</id>
				 <goals>
				 <goal>jar</goal>
				 </goals>
				 </execution>
			 </executions>
		 </plugin> 
     </plugins>
 </build>

  其中:

    maven-clean-plugin     执行mvn clean 命令相关插件

    maven-resources-plugin 执行mvn 工程resources打包管理

           maven-source-plugin  执行maven 代码源码打包的工具

           maven-compiler-plugin   maven代码编译的工具

     maven-javadoc-plugin    生成javadoc的maven工具

    tomcat-maven-plugin  进行tomcat远程部署的工具,主要配置的信息<server>tomcat-remote-deploy</server>就是setting.xml中servers中的配置信息,用户名和密码配置以后,就可以远程部署。

三、maven上传jar包到nexus私服。

  1、创建maven执行命令。

    点击Debug>>Debug configurations>>

    

    点击执行按钮:

    

   查看执行情况(见eclipse console):

    

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.tianditu.search:search-nlp:jar:0.1
[WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:tomcat-maven-plugin is missing. @ com.tianditu.search:tianditu-search:0.8, P:	s_search	ianditu-searchpom.xml, line 62, column 14
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building search-nlp 0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.4:resources (default-resources) @ search-nlp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.4:compile (default-compile) @ search-nlp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.4:testResources (default-testResources) @ search-nlp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory P:	s_search	ianditu-searchsearch-nlpsrc	est
esources
[INFO] 
[INFO] --- maven-compiler-plugin:2.4:testCompile (default-testCompile) @ search-nlp ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.7.1:test (default-test) @ search-nlp ---
[INFO] No tests to run.
[INFO] Surefire report directory: P:	s_search	ianditu-searchsearch-nlp	argetsurefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ search-nlp ---
[INFO] Building jar: P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1.jar
[INFO] 
[INFO] --- maven-javadoc-plugin:2.7:jar (attach-javadocs) @ search-nlp ---
[ERROR] Error fetching link: http://java.sun.com/javase/6/docs/api/package-list. Ignored it.
[INFO] 
正在加载程序包com.tianditu.search.nlp的源文件...
正在构造 Javadoc 信息...
标准 Doclet 版本 1.7.0_45
正在构建所有程序包和类的树...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpBCConvert.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpPinyin.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpStringTool.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lppackage-frame.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lppackage-summary.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lppackage-tree.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsconstant-values.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpclass-useStringTool.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpclass-usePinyin.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lpclass-useBCConvert.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocscom	ianditusearch
lppackage-use.html...
正在构建所有程序包和类的索引...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsoverview-tree.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsindex-all.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsdeprecated-list.html...
正在构建所有类的索引...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsallclasses-frame.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsallclasses-noframe.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocsindex.html...
正在生成P:	s_search	ianditu-searchsearch-nlp	argetapidocshelp-doc.html...
7 个警告
[WARNING] Javadoc Warnings
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:107: 警告 - @return 标记没有参数。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:127: 警告 - @return 标记没有参数。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:148: 警告 - @return 标记没有参数。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:171: 警告 - @return 标记没有参数。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:359: 警告 - @return 标记没有参数。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:73: 警告 - @note是未知标记。
[WARNING] P:	s_search	ianditu-searchsearch-nlpsrcmainjavacom	ianditusearch
lpStringTool.java:91: 警告 - @note是未知标记。
[INFO] Building jar: P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1-javadoc.jar
[INFO] 
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ search-nlp ---
[INFO] Building jar: P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1-sources.jar
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ search-nlp ---
[INFO] Installing P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1.jar to C:UsersGCZX-016.m2
epositorycom	ianditusearchsearch-nlp.1search-nlp-0.1.jar
[INFO] Installing P:	s_search	ianditu-searchsearch-nlppom.xml to C:UsersGCZX-016.m2
epositorycom	ianditusearchsearch-nlp.1search-nlp-0.1.pom
[INFO] Installing P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1-javadoc.jar to C:UsersGCZX-016.m2
epositorycom	ianditusearchsearch-nlp.1search-nlp-0.1-javadoc.jar
[INFO] Installing P:	s_search	ianditu-searchsearch-nlp	argetsearch-nlp-0.1-sources.jar to C:UsersGCZX-016.m2
epositorycom	ianditusearchsearch-nlp.1search-nlp-0.1-sources.jar
[INFO] 
[INFO] --- maven-deploy-plugin:2.5:deploy (default-deploy) @ search-nlp ---
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Uploading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1.jar
Uploading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1.pom
Uploaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1.jar (30 KB at 137.9 KB/sec)
Uploaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1.pom (5 KB at 46.4 KB/sec)
Downloading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/maven-metadata.xml
Downloaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/maven-metadata.xml (305 B at 8.1 KB/sec)
Uploading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/maven-metadata.xml
Uploaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/maven-metadata.xml (305 B at 0.6 KB/sec)
Uploading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1-javadoc.jar
Uploaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1-javadoc.jar (47 KB at 649.1 KB/sec)
Uploading: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1-sources.jar
Uploaded: http://192.9.104.17:8081/nexus/content/repositories/releases/com/tianditu/search/search-nlp/0.1/search-nlp-0.1-sources.jar (23 KB at 340.6 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.709s
[INFO] Finished at: Thu Jun 04 17:26:55 CST 2015
[INFO] Final Memory: 18M/386M
[INFO] ------------------------------------------------------------------------

   如有错误,然后定位并解决,主要错误就是用户没有权限,或者仓库地址没有配置等等。

    

    

原文地址:https://www.cnblogs.com/likehua/p/4552678.html