Bundle私服使用规范

                

私服地址

http://10.250.95.30:8081

一,相关配置

  1. 从私服中下载你需要的maven 插件

    打开maven目录下的conf\settings.xml

    1. 添加私服为镜像

      在<mirrors>标签中加入:

    2. <mirror>
    3. <id>nexus</id>
    4. <mirrorOf>*</mirrorOf>
    5. <name>Nexus Mirror</name>
    6. <url>http://10.250.95.30:8081/nexus/content/groups/public/</url>
    7. </mirror>
    8. 添加私服在<profiles>标签中加入这一段
    9. <profile>
    10. <id>nexus</id>
    11. <repositories>
    12. <repository>
    13. <id>nexus</id>
    14. <name>local private nexus</name> <url>http://10.250.95.30:8081/nexus/content/groups/public</url>
    15. <releases>
    16. <enabled>true</enabled>
    17. </releases>
    18. <snapshots>
    19. <enabled>false</enabled>
    20. </snapshots>
    21. </repository>
    22. <repository>
    23. <id>nexus</id>
    24. <name>local private nexus</name>
    25. <url>http://10.250.95.30:8081/nexus/content/groups/public-snapshots</url>
    26. <releases>
    27. <enabled>false</enabled>
    28. </releases>
    29. <snapshots>
    30. <enabled>true</enabled>
    31. </snapshots>
    32. </repository>
    33.  
    34. </repositories>
    35. <pluginRepositories>
    36. <pluginRepository>
    37. <id>nexus</id>
    38. <name>local private nexus</name> <url>http://10.250.95.30:8081/nexus/content/groups/public</url>
    39. <releases>
    40. <enabled>true</enabled>
    41. </releases>
    42. <snapshots>
    43. <enabled>false</enabled>
    44. </snapshots>
    45. </pluginRepository>
    46. <pluginRepository>
    47. <id>nexus</id>
    48. <name>local private nexus</name>
    49. <url>http://10.250.95.30:8081/nexus/content/groups/public-snapshots</url>
    50. <releases>
    51. <enabled>false</enabled>
    52. </releases>
    53. <snapshots>
    54. <enabled>true</enabled>
    55. </snapshots>
    56. </pluginRepository>
    57. </pluginRepositories>
    58. </profile>

</profiles>后加入

  1. <activeProfiles>
  2. <activeProfile>nexus</activeProfile>
  3. </activeProfiles>

2,把你的插件发布到私服中

发布需要相应的权限

1,在<servers>中加入:

  1. <server>
  2. <id>nexus-release</id>
  3. <username>admin</username>
  4. <password>admin123</password>
  5. </server>
  6. <server>
  7. <id>nexus-snapshots</id>
  8. <username>admin</username>
  9. <password>admin123</password>
  10. </server>
  11. 2,在你的pom.xml<distributionManagement>标签中加入
  12.  
  13. <repository>
  14. <id>nexus-release</id>
  15. <url>http://10.250.95.30:8081/nexus/content/repositories/releases/</url>
  16. </repository>
  17. <!-- snapshot repo -->
  18. <snapshotRepository>
  19. <id>nexus-snapshots</id>
  20. <url>http://10.250.95.30:8081/nexus/content/repositories/snapshots/</url>
  21. </snapshotRepository>

当你开发完成后只需输入mvn deploy即可发布到远程仓库

  1. 发布你的第三方库到私服中

    进入nexus主页

    http://10.250.95.30:8081/nexus/index.html#welcome

Repositories-> 3rd party->artifact upload

 

 

 

 

 

 

 

 

 

 

 

 

如何将bundle以及相应的第三方库打包:

第三方库解压打包:

 

这里需要用到mvn assembly:assemly命令

pom文件中添加如下

  1.     <plugin>
  2. <!-- NOTE: We don't need a groupId specification because the group is
  3. org.apache.maven.plugins ...which is assumed by default.
  4. -->
  5. <artifactId>maven-assembly-plugin</artifactId>
  6. <version>2.2-beta-5</version>
  7. <configuration>
  8. <descriptorRefs>
  9. <descriptorRef>jar-with-dependencies</descriptorRef>
  10. </descriptorRefs>
  11. </configuration>
  12. </plugin>

其中

<descriptorRef>jar-with-dependencies</descriptorRef>

指明了打包方式。现在mvn assembly:assembly maven你会在${project}/target 文件夹下发现新生成的  {artifactId}-jar-with-dependencies.jar  这个文件

在上面的这个命令执行的过程中,maven会将jar包所依赖的包导出,并且解压(unpackage),一并放在这个{artifactId}-jar-with-dependencies.jar 包中,这样对于程序的部署人员来说很方便,哪怕你的项目依赖了再多的第三方包,在部署的时候都会合并到一个assembly

但是有时候我们并不需要解压

Jar独立打包,

方法一:

这个jar-with-dependenciesassembly预先写好的一个,组装描述引用(assembly descriptor)我们来看一下这个定义这个组装描述(assemly descriptor)的xml文件

[xhtml] view plaincopy

  1. <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"  
  2.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">  
  4.   <id>jar-with-dependencies</id>  
  5.   <formats>  
  6.     <format>jar</format>  
  7.   </formats>  
  8.   <includeBaseDirectory>false</includeBaseDirectory>  
  9.   <dependencySets>  
  10.     <dependencySet>  
  11.       <unpack>true</unpack>  
  12.       <scope>runtime</scope>  
  13.     </dependencySet>  
  14.   </dependencySets>  
  15.   <fileSets>  
  16.     <fileSet>  
  17.       <directory>${project.build.outputDirectory}</directory>  
  18.     </fileSet>  
  19.   </fileSets>  
  20. </assembly>  

其实只要将上面这个xml文件中的

[xhtml] view plaincopy

  1. <dependencySet>  
  2.       <unpack>true</unpack>  
  3.       <scope>runtime</scope>  
  4. </dependencySet>  

改成:

[xhtml] view plaincopy

  1. <dependencySet>  
  2. <unpack>false</unpack>  
  3. <scope>runtime</scope>  
  4. </dependencySet>  

 main/assembly 下创建 src.xml文件,将刚才修改过的内用写入文件中,内容为:

[xhtml] view plaincopy

  1. <assembly  
  2.     xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">  
  5.     <id>jar-with-dependencies</id>  
  6.     <formats>  
  7.         <format>jar</format>  
  8.     </formats>  
  9.     <includeBaseDirectory>false</includeBaseDirectory>  
  10.     <dependencySets>  
  11.         <dependencySet>  
  12.             <unpack>false</unpack>  
  13.             <scope>runtime</scope>  
  14.         </dependencySet>  
  15.     </dependencySets>  
  16.     <fileSets>  
  17.         <fileSet>  
  18.             <directory>${project.build.outputDirectory}</directory>  
  19.         </fileSet>  
  20.     </fileSets>  
  21. </assembly>  

   

将之前pom.xml 中的plugin改成如下:

<plugin>  

  1.                 <artifactId>maven-assembly-plugin</artifactId>  
  2.                 <configuration>  
  3.                     <descriptors>  
  4.                         <descriptor>src/main/assembly/src.xml</descriptor>  
  5.                     </descriptors>  
  6.                 </configuration>  
  7.             </plugin>  

 

方法二:

如果你和我一样懒:那么请用这个方法:

pom文件中添加如下

  1.     <plugin>
  2. <!-- NOTE: We don't need a groupId specification because the group is
  3. org.apache.maven.plugins ...which is assumed by default.
  4. -->
  5. <artifactId>maven-assembly-plugin</artifactId>
  6. <version>2.2-beta-5</version>
  7. <configuration>
  8. <descriptorRefs>
  9. <descriptorRef>jar-with-dependencies</descriptorRef>
  10. </descriptorRefs>
  11. </configuration>
  12. </plugin>

 

然后直接修改maven-assembly-plugin插件

找到maven-assembly-plugin插件所在地址我的是在C:\Users\豪豪好好\.m2\repository\org\apache\maven\plugins\maven-assembly-plugin\2.2-beta-5

打开maven-assembly-plugin-2.2-beta-5.jar,修改assemblies\jar-with-dependencies.xml的中的<unpack>标签为

  1. <unpack>false</unpack>

打包后效果如图

posted on 2012-07-26 21:15  宝宝乖  阅读(655)  评论(0编辑  收藏  举报

导航