Maven学习记录3——创建、编译、打包、运行项目 :[url]http://blog.youkuaiyun.com/yaya1943/article/details/48464371[/url]
使用maven编译Java项目:[url]http://www.tuicool.com/articles/YfIfIrq[/url]
netty github 导入 Eclipse:[url]http://www.th7.cn/Program/java/201502/389732.shtml[/url]
netty源码编译环境搭建 :[url]http://blog.youkuaiyun.com/wuyinxian/article/details/46382051[/url]
Plugin error: execution not covered by lifecycle configuration:
[url]https://stackoverflow.com/questions/7391201/plugin-error-execution-not-covered-by-lifecycle-configuration[/url]
Execution Not Covered:[url]http://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html[/url]
netty项目github地址:[url]https://github.com/netty/netty.git[/url]
由于netty项目在github中,没有.project和.classpath文件,所以不能够直接转换为eclipse工程Maven项目,要手动去编译,具体可参考netty源码编译环境搭建和netty github导入Eclipse这两篇文章。
我们总结一下从github检出netty项目,编译maven项目,主要遇到的问题:
[size=medium][b]1.Failure to transfer io.netty:netty-tcnative:jar:${tcnative.classifier}:2.0.3.Final[/b][/size]
这个问题主要是tcnative jar在netty-parent:
的POM中定义了如下片段:
根据操作系统探测tcnative的classifier,我们只需要将上面这句话注释掉如下:
同时在相应子模块项目中,tcnative包依赖中将:
改为:
这里我们是以netty-handler子模块为例:
[size=medium][b]2.Plugin execution not covered by lifecycle configuration:
org.codehaus.mojo:build-helper-maven-plugin:1.10:add-source
(execution: add-source, phase: generate-sources)[/b][/size]
这个问题主要是执行不能被声明周期配置覆盖导致,我们以netty-common子模块为例:
groupId为org.codehaus.mojo,artifactId为build-helper-maven-plugin的add-source执行不行被生命周期覆盖,解决方式,在pom文件的build标签下加入pluginManagement对应的片段:
还有一种方式为配置Maven -> Lifecycle mapping->lifecycle-mapping-metadata.xml ,
官方显示这种方法针对Eclipse 4.2,具体配置在Windows -> Preferences -> Maven -> Lifecycle mapping ,文件(eclipse/plugins/org.eclipse.m2e.lifecyclemapping.defaults_1.2.0.20120903-1050.jar/lifecycle-mapping-metadata.xml)内容如下:
[color=red]注意:pluginExecutionFilter中的groupId,artifactId,goal的对应关系。[/color]
在配置完后记得要重新加载。如果你有多个Eclipse工作空间或者为一个团队项目,强烈建立使用配置POM文件的方式,,即第一种方式。
然后更新项目模块(maven-》update勾选force online update)。
如果还有问题,看看是不是JRE的原因(JRE6-8),一般为JRE7,
如果项目没有maven依赖包(Maven Dependencies),查看项目的.class
和.project文件
[b].class文件是否包含如下信息:[/b]
不包括,则添加上,不同,则修改。
[b].project文件是否为如下:[/b]
对于没有含有项,则添加上,不同,则修改。
最后,记得刷新工作空间项目。
使用maven编译Java项目:[url]http://www.tuicool.com/articles/YfIfIrq[/url]
netty github 导入 Eclipse:[url]http://www.th7.cn/Program/java/201502/389732.shtml[/url]
netty源码编译环境搭建 :[url]http://blog.youkuaiyun.com/wuyinxian/article/details/46382051[/url]
Plugin error: execution not covered by lifecycle configuration:
[url]https://stackoverflow.com/questions/7391201/plugin-error-execution-not-covered-by-lifecycle-configuration[/url]
Execution Not Covered:[url]http://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html[/url]
netty项目github地址:[url]https://github.com/netty/netty.git[/url]
由于netty项目在github中,没有.project和.classpath文件,所以不能够直接转换为eclipse工程Maven项目,要手动去编译,具体可参考netty源码编译环境搭建和netty github导入Eclipse这两篇文章。
我们总结一下从github检出netty项目,编译maven项目,主要遇到的问题:
[size=medium][b]1.Failure to transfer io.netty:netty-tcnative:jar:${tcnative.classifier}:2.0.3.Final[/b][/size]
这个问题主要是tcnative jar在netty-parent:
<groupId>io.netty</groupId>
<artifactId>netty-parent</artifactId>
<packaging>pom</packaging>
<version>4.1.13.Final-SNAPSHOT</version>的POM中定义了如下片段:
<tcnative.artifactId>netty-tcnative</tcnative.artifactId>
<tcnative.version>2.0.3.Final</tcnative.version>
<tcnative.classifier>${os.detected.classifier}</tcnative.classifier>根据操作系统探测tcnative的classifier,我们只需要将上面这句话注释掉如下:
<!-- <tcnative.classifier>${os.detected.classifier}</tcnative.classifier> -->同时在相应子模块项目中,tcnative包依赖中将:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${tcnative.artifactId}</artifactId>
<classifier>${tcnative.classifier}</classifier>
<optional>true</optional>
</dependency>改为:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${tcnative.artifactId}</artifactId>
<!-- <classifier>${tcnative.classifier}</classifier> -->
<version>${tcnative.version}</version>
<optional>true</optional>
</dependency>这里我们是以netty-handler子模块为例:
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-parent</artifactId>
<version>4.1.13.Final-SNAPSHOT</version>
</parent>
<artifactId>netty-handler</artifactId>
<packaging>jar</packaging>[size=medium][b]2.Plugin execution not covered by lifecycle configuration:
org.codehaus.mojo:build-helper-maven-plugin:1.10:add-source
(execution: add-source, phase: generate-sources)[/b][/size]
这个问题主要是执行不能被声明周期配置覆盖导致,我们以netty-common子模块为例:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${collection.src.dir}</source>
</sources>
</configuration>
</execution>
</plugin>groupId为org.codehaus.mojo,artifactId为build-helper-maven-plugin的add-source执行不行被生命周期覆盖,解决方式,在pom文件的build标签下加入pluginManagement对应的片段:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- plugin执行器过滤器 -->
<pluginExecution>
<!-- plugin执行器过滤器 -->
<pluginExecutionFilter>
<!-- 这里的groupId和artifactId和上面的相对应 -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<!-- 版本大于等于1.0.0 -->
<versionRange>[1.0.0,)</versionRange>
<goals>
<!-- 目标与上面对应者execution goals中goal -->
<goal>add-source</goal>
<goal>add-test-source</goal>
</goals>
</pluginExecutionFilter>
<!-- plugin执行器忽略 groupId,artifactId 对应的goals中goal -->
<action>
<!--忽略执行 -->
<ignore/>
</action>
</pluginExecution>
<!-- plugin执行器过滤器 -->
<pluginExecution>
<!-- plugin执行器过滤器 -->
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>parse-version</goal>
<goal>check-style</goal>
</goals>
</pluginExecutionFilter>
<!-- plugin执行器忽略 groupId,artifactId 对应的goals中goal -->
<action>
<ignore/>
</action>
</pluginExecution>
<!-- plugin执行器过滤器 -->
<pluginExecution>
<!-- plugin执行器过滤器 -->
<pluginExecutionFilter>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>execute</goal>
</goals>
</pluginExecutionFilter>
<!-- plugin执行器忽略 groupId,artifactId 对应的goals中goal -->
<action>
<ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>还有一种方式为配置Maven -> Lifecycle mapping->lifecycle-mapping-metadata.xml ,
官方显示这种方法针对Eclipse 4.2,具体配置在Windows -> Preferences -> Maven -> Lifecycle mapping ,文件(eclipse/plugins/org.eclipse.m2e.lifecyclemapping.defaults_1.2.0.20120903-1050.jar/lifecycle-mapping-metadata.xml)内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<goals>
<goal>create-timestamp</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<goals>
<goal>list</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<goals>
<goal>generate</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<goals>
<goal>compile</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<goals>
<goal>copy-dependencies</goal>
<goal>unpack</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>[color=red]注意:pluginExecutionFilter中的groupId,artifactId,goal的对应关系。[/color]
在配置完后记得要重新加载。如果你有多个Eclipse工作空间或者为一个团队项目,强烈建立使用配置POM文件的方式,,即第一种方式。
然后更新项目模块(maven-》update勾选force online update)。
如果还有问题,看看是不是JRE的原因(JRE6-8),一般为JRE7,
如果项目没有maven依赖包(Maven Dependencies),查看项目的.class
和.project文件
[b].class文件是否包含如下信息:[/b]
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>不包括,则添加上,不同,则修改。
[b].project文件是否为如下:[/b]
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>netty_trunk</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>对于没有含有项,则添加上,不同,则修改。
最后,记得刷新工作空间项目。

本文介绍如何从GitHub检出Netty项目并进行Maven编译。解决常见问题如tcnative依赖失败及Pluginexecution未被生命周期配置覆盖等,并提供详细的配置步骤。
1424

被折叠的 条评论
为什么被折叠?



