你的位置:首页 > Java教程

[Java教程]使用maven将代码到私服


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

一、maven pom.

  <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.

三、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:\ts_search\tianditu-search\pom.

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