Bundle私服使用规范
私服地址
一,相关配置
-
从私服中下载你需要的maven 插件
打开maven目录下的conf\settings.xml
-
添加私服为镜像
在<mirrors>标签中加入:
-
<mirror>
-
<id>nexus</id>
-
<mirrorOf>*</mirrorOf>
-
<name>Nexus Mirror</name>
-
<url>http://10.250.95.30:8081/nexus/content/groups/public/</url>
-
</mirror>
-
添加私服在<profiles>标签中加入这一段
-
<profile>
-
<id>nexus</id>
-
<repositories>
-
<repository>
-
<id>nexus</id>
-
<name>local private nexus</name> <url>http://10.250.95.30:8081/nexus/content/groups/public</url>
-
<releases>
-
<enabled>true</enabled>
-
</releases>
-
<snapshots>
-
<enabled>false</enabled>
-
</snapshots>
-
</repository>
-
<repository>
-
<id>nexus</id>
-
<name>local private nexus</name>
-
<url>http://10.250.95.30:8081/nexus/content/groups/public-snapshots</url>
-
<releases>
-
<enabled>false</enabled>
-
</releases>
-
<snapshots>
-
<enabled>true</enabled>
-
</snapshots>
-
</repository>
-
-
</repositories>
-
<pluginRepositories>
-
<pluginRepository>
-
<id>nexus</id>
-
<name>local private nexus</name> <url>http://10.250.95.30:8081/nexus/content/groups/public</url>
-
<releases>
-
<enabled>true</enabled>
-
</releases>
-
<snapshots>
-
<enabled>false</enabled>
-
</snapshots>
-
</pluginRepository>
-
<pluginRepository>
-
<id>nexus</id>
-
<name>local private nexus</name>
-
<url>http://10.250.95.30:8081/nexus/content/groups/public-snapshots</url>
-
<releases>
-
<enabled>false</enabled>
-
</releases>
-
<snapshots>
-
<enabled>true</enabled>
-
</snapshots>
-
</pluginRepository>
-
</pluginRepositories>
-
</profile>
-
在</profiles>后加入
-
<activeProfiles>
-
<activeProfile>nexus</activeProfile>
-
</activeProfiles>
2,把你的插件发布到私服中
发布需要相应的权限
1,在<servers>中加入:
-
<server>
-
<id>nexus-release</id>
-
<username>admin</username>
-
<password>admin123</password>
-
</server>
-
<server>
-
<id>nexus-snapshots</id>
-
<username>admin</username>
-
<password>admin123</password>
-
</server>
-
2,在你的pom.xml中<distributionManagement>标签中加入
-
-
<repository>
-
<id>nexus-release</id>
-
<url>http://10.250.95.30:8081/nexus/content/repositories/releases/</url>
-
</repository>
-
<!-- snapshot repo -->
-
<snapshotRepository>
-
<id>nexus-snapshots</id>
-
<url>http://10.250.95.30:8081/nexus/content/repositories/snapshots/</url>
-
</snapshotRepository>
当你开发完成后只需输入mvn deploy即可发布到远程仓库
-
发布你的第三方库到私服中
进入nexus主页
Repositories-> 3rd party->artifact upload
如何将bundle以及相应的第三方库打包:
第三方库解压打包:
这里需要用到mvn assembly:assemly命令
在pom文件中添加如下
-
<plugin>
-
<!-- NOTE: We don't need a groupId specification because the group is
-
org.apache.maven.plugins ...which is assumed by default.
-
-->
-
<artifactId>maven-assembly-plugin</artifactId>
-
<version>2.2-beta-5</version>
-
<configuration>
-
<descriptorRefs>
-
<descriptorRef>jar-with-dependencies</descriptorRef>
-
</descriptorRefs>
-
</configuration>
-
</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-dependencies是assembly预先写好的一个,组装描述引用(assembly descriptor)我们来看一下这个定义这个组装描述(assemly descriptor)的xml文件
[xhtml] view plaincopy
-
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
-
<id>jar-with-dependencies</id>
-
<formats>
-
<format>jar</format>
-
</formats>
-
<includeBaseDirectory>false</includeBaseDirectory>
-
<dependencySets>
-
<dependencySet>
-
<unpack>true</unpack>
-
<scope>runtime</scope>
-
</dependencySet>
-
</dependencySets>
-
<fileSets>
-
<fileSet>
-
<directory>${project.build.outputDirectory}</directory>
-
</fileSet>
-
</fileSets>
-
</assembly>
其实只要将上面这个xml文件中的
[xhtml] view plaincopy
-
<dependencySet>
-
<unpack>true</unpack>
-
<scope>runtime</scope>
-
</dependencySet>
改成:
[xhtml] view plaincopy
-
<dependencySet>
-
<unpack>false</unpack>
-
<scope>runtime</scope>
-
</dependencySet>
在 main/assembly 下创建 src.xml文件,将刚才修改过的内用写入文件中,内容为:
[xhtml] view plaincopy
-
<assembly
-
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
-
<id>jar-with-dependencies</id>
-
<formats>
-
<format>jar</format>
-
</formats>
-
<includeBaseDirectory>false</includeBaseDirectory>
-
<dependencySets>
-
<dependencySet>
-
<unpack>false</unpack>
-
<scope>runtime</scope>
-
</dependencySet>
-
</dependencySets>
-
<fileSets>
-
<fileSet>
-
<directory>${project.build.outputDirectory}</directory>
-
</fileSet>
-
</fileSets>
-
</assembly>
将之前pom.xml 中的plugin改成如下:
<plugin>
-
<artifactId>maven-assembly-plugin</artifactId>
-
<configuration>
-
<descriptors>
-
<descriptor>src/main/assembly/src.xml</descriptor>
-
</descriptors>
-
</configuration>
-
</plugin>
方法二:
如果你和我一样懒:那么请用这个方法:
在pom文件中添加如下
-
<plugin>
-
<!-- NOTE: We don't need a groupId specification because the group is
-
org.apache.maven.plugins ...which is assumed by default.
-
-->
-
<artifactId>maven-assembly-plugin</artifactId>
-
<version>2.2-beta-5</version>
-
<configuration>
-
<descriptorRefs>
-
<descriptorRef>jar-with-dependencies</descriptorRef>
-
</descriptorRefs>
-
</configuration>
-
</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>标签为
-
<unpack>false</unpack>
打包后效果如图