eclpse使用maven打包工程和报错处理

0  在工程的pom.xml中增加打包build如下:

  </dependencies>
  
  	<build>
		<plugins>
			<!-- compiler插件, 设定JDK版本 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.3.2</version>
				<configuration>
					<encoding>UTF-8</encoding>
					<source>1.7</source>
					<target>1.7</target>
					<showWarnings>true</showWarnings>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
					<archive>
						<manifest>
							<mainClass>bj.zm.myspider.MySpider</mainClass>
						</manifest>
					</archive>
				</configuration>
				<executions>
					<execution>
						<id>make-assembly</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

1 使用eclipse 的maven插件来打包工程, 打包过程如下:

 工程,右键 ---> run an ---> 选择 run configuration ---> 选择Maven Build ---->  右键,new ,

如下图:



 

2   上述配置好后,点击 Apply, Run即可。

3 可能出现的错:  作者就遇到过

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre7\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
[INFO] 1 error

  处理方式:

打开 :Window -> Preferences -> Java -> installed JREs -> 

选择你正在使用的JRE(应该是一个在jdk。例:C:\Program Files\Java\jdk1.6.0_43 )

接着,点击“Edit”,进入下一个画面:选择添加 C:\Program Files\Java\jdk1.6.0_43\lib\tools.jar ,点击 Finish。

接下来,打开 Window -> Preferences -> Java -> installed JREs -> Execution Enviroments ->

进入画面:选择JavaSE-1.6和相匹配的 jre 。点击OK。

网上别的方式在我本机上验证都失败,只有这种方式可行, 即 将你 eclipse的 jre 设置为你机器安装的jre

并且在你的jre内添加 jdk的tools.jar 。

参考链接:

http://www.xuebuyuan.com/2083610.html

最终,经过漫长等待下载依赖包之后,出现令人期待的:

[INFO] META-INF/maven/org.apache.commons/ already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35:16 min
[INFO] Finished at: 2015-03-21T22:10:17+08:00
[INFO] Final Memory: 50M/290M
[INFO] ------------------------------------------------------------------------

 

打包后一把在工程的 target 目录下,比如作者的: D:\workspace\myspider\target

打包后上传 执行命令:  java -jar 打好的.jar包即可执行

猜你喜欢

转载自chengjianxiaoxue.iteye.com/blog/2194493