用maven在liunx上将java程序进行打包
随着Maven运用越来越广泛,使用Maven对java程序进行打包变得十分必要,下面我将介绍maven打包方法,对写好的maven程序进行打包;
没有用过maven的朋友可以先看看这篇博客:
http://448230305.iteye.com/admin/blogs/2172780
我使用的编译器是IDEA,感觉比eclipse好,也推荐给大家:
http://www.jetbrains.com/idea/
进入官网直接下载即可;
下面我们进入正题:
<!--[if !supportLists]-->1、<!--[endif]-->在工程的pom.xml文件中,引入“assembly”;
??? <build>
??????? <plugins>
??????????? <plugin>
??????????????? <artifactId>maven-compiler-plugin</artifactId>
???? ???????????<version>2.3.1</version>
??????????????? <configuration>
??????????????????? <encoding>UTF-8</encoding>
??????????????????? <source>1.6</source>
??????????????????? <target>1.6</target>
??????????????? </configuration>
??????????? </plugin>
??? ????????<plugin>
??????????????? <groupId>org.apache.maven.plugins</groupId>
??????????????? <artifactId>maven-jar-plugin</artifactId>
??????????????? <version>2.3.1</version>
??????????????? <configuration>
??????????????????? <archive>
????????????????? ??????<!-- 配置jar包里MANIFEST信息 -->
??????????????????????? <manifest>
?????????????????????????? ?<mainClass>demo.S_Enter_phone</mainClass>
??????????????????????????? <!-- 增加该配置可减少在运行时配置的依赖 -->
??????????????????????????? <addClasspath>true</addClasspath>
??????????????????????????? <classpathPrefix>lib</classpathPrefix>
??????????????????????? </manifest>
??????????????????? </archive>
??????????????? </configuration>
??????????? </plugin>
??????????? <plugin>
??????????????? <groupId>org.apache.maven.plugins</groupId>
??????????????? <artifactId>maven-assembly-plugin</artifactId>
??????????????? <configuration>
??????????????????? <descriptor>assembly.xml</descriptor>
??????????????????? <finalName>rc-es</finalName>
??????????????????? <outputDirectory>target</outputDirectory>
??????????????????? <workDirectory>target</workDirectory>
??????????????? </configuration>
??????????? </plugin>
??????? </plugins>
</build>
红色字处为指定头文件;
2、其次在工程根目录下添加一个文件“assembly.xml”文件,与“pom.xml”同级;
?
<!--[endif]-->
<!--[if !supportLists]-->3、<!--[endif]-->添加成功后压缩,并上传到liunx下,解压
?
<!--[endif]-->
<!--[if !supportLists]-->4、<!--[endif]-->进入magguo_spider_1224,在根目录下输入:
?
<!--[endif]-->
<!--[if !supportLists]-->5、<!--[endif]-->如果出现以下信息说明打包成功:
?
<!--[endif]-->
<!--[if !supportLists]-->6、<!--[endif]-->进入以下目录输入解压命令
?
<!--[endif]-->
<!--[if !supportLists]-->7、<!--[endif]-->解压
?
<!--[endif]-->
<!--[if !supportLists]-->8、<!--[endif]-->进入rc-es即可看到我们打包好的jar包,下面我们输入命令运行一下吧
?
?
好了,打包方法介绍到这里,希望对大家有帮助!!!!
原文:http://448230305.iteye.com/blog/2186236