月蚀:为什么和使用Maven项目没有缺陷的Eclipse项目时,时添加库来构建路径? [英] Eclipse: Why and when to add libraries to build path when using Maven project to not have defective Eclipse project?
问题描述
我在Eclipse中的Android项目由Maven的管理。昨天我的检查更新在Eclipse功能升级Eclipse和一些插件。更新完成后,我的Android项目是有缺陷的。首先,我认为这只是一个清洁/更新项目/ Maven的重建的问题或可能的包括库不适合了的顺序(例如,Maven的依赖是不是在顶部或类似的东西),但我是能够通过Maven构建,所以没有项目或Maven的问题,而是一个Eclipse的问题。得到它的工作再一次,我不得不从Maven的回购手动添加Hamcrest,JUnit和向的Mockito构建路径。我并没有说之前做这个项目(除Android的4.1.1.4.jar)。
我想明白的时候,为什么我突然有这样做吗? (在早期的一个项目我也不得不手动添加一些外部库)。
(我总是构建和干净安装Android我的项目:部署机器人:运行)
下面是我目前已经安装了一些插件的重要...
的pom.xml
<?XML版本=1.0编码=UTF-8&GT?;
<项目的xmlns =http://maven.apache.org/POM/4.0.0的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instanceXSI:=的schemaLocationHTTP: //maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
< modelVersion> 4.0.0< / modelVersion>
<&的groupId GT; com.mydomain< /的groupId>
<&的artifactId GT;的myapp< / artifactId的>
<包装和GT;&APK LT; /包装>
<&版GT; 1.0-SNAPSHOT< /版本>
<名称>我的应用程序和LT; /名称>
&LT; URL&GT; HTTP://maven.apache.org< / URL&GT; &LT;性状&gt;
&LT; platform.version&GT; 2.2.1&LT; /platform.version>
&LT; android.sdk.path&GT;的/ opt / Android的SDK-Linux和LT; /android.sdk.path>
&LT; project.build.sourceEncoding&GT; UTF-8&LT; /project.build.sourceEncoding>
&LT; project.reporting.outputEncoding&GT; UTF-8&LT; /project.reporting.outputEncoding>
&LT; junit.version&GT; 4.8.2&LT; /junit.version>
&LT; mockito.version&GT; 1.9.5&LT; /mockito.version>
&LT; jackson.version&GT; 1.9.13&LT; /jackson.version>
&LT; hamcrest.version&GT; 1.3&LT; /hamcrest.version>
&LT; android.version&GT; 4.1.1.4&LT; /android.version>
&LT; annotations.version&GT; 4.1.1.4&LT; /annotations.version>
&LT; supportv4.version&GT; R13&LT; /supportv4.version>
&LT; /性状&gt; &LT;库&GT;
&LT;&库GT;
&LT;&ID GT; codehaus&LT; / ID&GT;
&LT; URL&GT; HTTP://repository.$c$chaus.org/org/$c$chaus< / URL&GT;
&LT; /存储库&GT;
&LT; /存储库&GT; &LT;依赖和GT;
&LT;&依赖性GT;
&LT;&的groupId GT; com.google.android&LT; /的groupId&GT;
&LT;&的artifactId GT; Android设备和LT; / artifactId的&GT;
&LT;&版GT; $ {android.version}&LT; /版本&GT;
&LT;&范围GT;及提供LT; /&范围GT;
&LT; /依赖性&GT;
&LT;&依赖性GT;
&LT;&的groupId GT; com.google.android&LT; /的groupId&GT;
&LT;&的artifactId GT;支持-V4&LT; / artifactId的&GT;
&LT;&版GT; $ {supportv4.version}&LT; /版本&GT;
&LT; /依赖性&GT;
&LT;! - 皮棉注释 - &GT;
&LT;&依赖性GT;
&LT;&的groupId GT; com.google.android&LT; /的groupId&GT;
&LT;&的artifactId GT;注释&LT; / artifactId的&GT;
&LT;&版GT; $ {annotations.version}&LT; /版本&GT;
&LT; /依赖性&GT; &LT;&依赖性GT;
&LT;的groupId方式&gt;组织codehaus.jackson&LT; /的groupId&GT;
&LT;&的artifactId GT;杰克逊映射器 - 翔升&LT; / artifactId的&GT;
&LT;&版GT; $ {jackson.version}&LT; /版本&GT;
&LT; /依赖性&GT; &LT;! - 非Android的测试 - &GT;&LT;! - hamcrest必定是由于编译错误的JUnit之前 - &GT;
&LT;&依赖性GT;
&LT;&的groupId GT; org.hamcrest&LT; /的groupId&GT;
&LT;&的artifactId GT; hamcrest-所有与LT; / artifactId的&GT;
&LT;&版GT; $ {hamcrest.version}&LT; /版本&GT;
&LT;&范围GT;试验&LT; /&范围GT;
&LT; /依赖性&GT; &LT;&依赖性GT;
&LT;&的groupId GT;的JUnit&LT; /的groupId&GT;
&LT;&的artifactId GT;的JUnit&LT; / artifactId的&GT;
&LT;&版GT; $ {junit.version}&LT; /版本&GT;
&LT;&范围GT;试验&LT; /&范围GT;
&LT; /依赖性&GT; &LT;&依赖性GT;
&LT;&的groupId GT; org.mockito&LT; /的groupId&GT;
&LT;&的artifactId GT;的Mockito,所有与LT; / artifactId的&GT;
&LT;&版GT; $ {mockito.version}&LT; /版本&GT;
&LT;&范围GT;试验&LT; /&范围GT;
&LT; /依赖性&GT; &LT;&依赖性GT;
&LT;&的groupId GT; org.powermock&LT; /的groupId&GT;
&LT;&的artifactId GT; powermock-API和的Mockito LT; / artifactId的&GT;
&LT;&版GT; 1.5.1&LT; /版本&GT;
&LT; /依赖性&GT; &LT;&依赖性GT;
&LT;&的groupId GT; org.powermock&LT; /的groupId&GT;
&LT;&的artifactId GT; powermock模块-junit4&LT; / artifactId的&GT;
&LT;&版GT; 1.5.1&LT; /版本&GT;
&LT; /依赖性&GT;
&LT; /依赖和GT; &LT;建立&GT;
&LT;输出目录&GT;斌/班&LT; /输出目录&GT;
&LT; testOutputDirectory&GT;斌/测试类&LT; / testOutputDirectory&GT; &LT;&插件GT;
&LT;&插件GT;
&LT;&的artifactId GT; Maven的编译器插件&LT; / artifactId的&GT;
&LT;&版GT; 2.5.1&LT; /版本&GT;
&LT;结构&gt;
&lt;信源&GT; 1.6 LT; /源&GT;
&lt;目标&GT; 1.6 LT; /目标与GT;
&LT; /结构&gt;
&LT; /插件&GT;
&LT;&插件GT;
&LT;&的artifactId GT;的maven-的jarsigner,插件和LT; / artifactId的&GT;
&LT;&版GT; 1.2 LT; /版本&GT;
&LT; /插件&GT;
&LT;&插件GT;
&LT;&的artifactId GT; Maven的资源 - 插件和LT; / artifactId的&GT;
&LT;&版GT; 2.5 LT; /版本&GT;
&LT;结构&gt;
&LT;&编码GT; UTF-8&LT; /编码&GT;
&LT; /结构&gt;
&LT; /插件&GT;
&LT;&插件GT;
&LT;&的groupId GT; com.jayway.maven.plugins.android.generation2&LT; /的groupId&GT;
&LT;&的artifactId GT; Android的Maven的插件&LT; / artifactId的&GT;
&LT;&版GT; 3.5.0&LT; /版本&GT;
&LT;结构&gt;
&LT; androidManifestFile&GT; $ {} project.basedir /AndroidManifest.xml</androidManifestFile>
&LT; assetsDirectory&GT; $ {} project.basedir /资产&LT; / assetsDirectory&GT;
&LT; resourceDirectory&GT; $ {} project.basedir / RES&LT; / resourceDirectory&GT;
&LT; nativeLibrariesDirectory&GT; $ {} project.basedir /钢骨混凝土/主/天然的LT; / nativeLibrariesDirectory&GT;
&LT;广告及GT;
&LT;调试和GT;真&LT; /调试&GT;
&LT; /标志&GT;
&LT; SDK开发及GT;
&LT;平台和GT 13 LT; /平台&GT;
&LT;路径&GT; $ {android.sdk.path}&LT; /路径&GT;
&LT; / SDK&GT;
&LT; undeployBeforeDeploy&GT;假LT; / undeployBeforeDeploy&GT;
&LT; /结构&gt;
&LT;附加功能,GT;真&LT; /扩展&GT;
&LT; /插件&GT;
&LT;&插件GT;
&LT;的groupId方式&gt;组织codehaus.mojo&LT; /的groupId&GT;
&LT;&的artifactId GT;建立辅助-Maven的插件&LT; / artifactId的&GT;
&LT;&版GT; 1.5 LT; /版本&GT;
&LT; /插件&GT;
&所述;! - 此插件的配置用于存储唯一的Eclipse M2E设置。它有Maven的没有影响自身建设。 - &GT;
&LT;&插件GT;
&LT;&的groupId GT; org.eclipse.m2e&LT; /的groupId&GT;
&LT;&的artifactId GT;生命周期映射&LT; / artifactId的&GT;
&LT;&版GT; 1.0.0&LT; /版本&GT;
&LT;结构&gt;
&LT; lifecycleMappingMetadata&GT;
&LT; pluginExecutions&GT;
&LT; pluginExecution&GT;
&LT; pluginExecutionFilter&GT;
&LT;&的groupId GT; com.jayway.maven.plugins.android.generation2&LT; /的groupId&GT;
&LT;&的artifactId GT; Android的Maven的插件&LT; / artifactId的&GT;
&LT; versionRange&GT;双环[3.2.0,)LT; / versionRange&GT;
&LT;目标&GT;
&LT;&目标GT;清单更新&LT; /目标&GT;
&LT; /目标&GT;
&LT; / pluginExecutionFilter&GT;
&lt;作用&GT;
&LT;执行/&GT;
&LT; /作用&gt;
&LT; / pluginExecution&GT;
&LT; / pluginExecutions&GT;
&LT; / lifecycleMappingMetadata&GT;
&LT; /结构&gt;
&LT; /插件&GT;
&LT; /插件&GT;
&LT; /构建&GT;
&LT; /项目&GT;
这是错误日志结果的输出
**的问题是,它并没有找到类(直到我手动导入它,但Maven和Eclipse应该处理)如果我尝试导入例如 org.junit.Test
, org.junit.runner.RunWith
或 org.mockito.Mock
我得到在Eclipse
进口XXXXX不能得到解决。
块引用>在Eclipse中的问题标签:
该项目没有内置因为它的构建路径是不完整的。不能
找到org.mockito.verification.VerificationMode类文件。固定
构建路径,然后尝试建立这种
项目com.mygame干线未知的Java问题的类型
org.mockito.verification.VerificationMode不能得到解决。它是
从所需的.class间接引用
文件GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game线
1 Java问题
块引用>解决方案随着1.0.0版本的的Android对Maven的Eclipse 改变其管理的Maven的类路径的方式。非运行时依赖(实际上,任何事情不是在
编译
范围内)正在加载到一个新的Maven的,非运行时类路径容器。你看到这些库出现在这个新的类路径容器?如果不行,请尝试从您的工作空间中删除项目,删除IDE特定的
。*
元数据文件,并试图重新导入一个Maven项目。I have an Android project in Eclipse managed by Maven. Yesterday I upgraded Eclipse and some plugins by the "Checked for Updated" function within Eclipse. After the update has finished, my Android project was defective. First I thought that it's just a "Clean/Update Project/Maven Rebuild" issue or maybe the order of the includes of the libraries didn't fit anymore (for example, Maven dependencies are not on top or something similar), but I was able to build by Maven, so no project or Maven problems, but an Eclipse problem. To get it working again I had to add Hamcrest, Junit and Mockito from the Maven repo to the build path manually. I didn't had to do that before in this project (except android-4.1.1.4.jar). I would like to understand when and why I suddenly have to do that? (In an earlier project I also had to add some external libraries manually).
(I always build and my project by clean install android:deploy android:run.)
Here are some important plugins I have currently installed...
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mydomain</groupId> <artifactId>myapp</artifactId> <packaging>apk</packaging> <version>1.0-SNAPSHOT</version> <name>My App</name> <url>http://maven.apache.org</url> <properties> <platform.version>2.2.1</platform.version> <android.sdk.path>/opt/android-sdk-linux</android.sdk.path> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <junit.version>4.8.2</junit.version> <mockito.version>1.9.5</mockito.version> <jackson.version>1.9.13</jackson.version> <hamcrest.version>1.3</hamcrest.version> <android.version>4.1.1.4</android.version> <annotations.version>4.1.1.4</annotations.version> <supportv4.version>r13</supportv4.version> </properties> <repositories> <repository> <id>codehaus</id> <url>http://repository.codehaus.org/org/codehaus</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>${android.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.android</groupId> <artifactId>support-v4</artifactId> <version>${supportv4.version}</version> </dependency> <!-- LInt Annotations --> <dependency> <groupId>com.google.android</groupId> <artifactId>annotations</artifactId> <version>${annotations.version}</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson.version}</version> </dependency> <!-- Non Android Tests --><!-- hamcrest must be before JUnit due to build errors --> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>${hamcrest.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>${mockito.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> <version>1.5.1</version> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.5.1</version> </dependency> </dependencies> <build> <outputDirectory>bin/classes</outputDirectory> <testOutputDirectory>bin/test-classes</testOutputDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <artifactId>maven-jarsigner-plugin</artifactId> <version>1.2</version> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.5.0</version> <configuration> <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> <assetsDirectory>${project.basedir}/assets</assetsDirectory> <resourceDirectory>${project.basedir}/res</resourceDirectory> <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> <sign> <debug>true</debug> </sign> <sdk> <platform>13</platform> <path>${android.sdk.path}</path> </sdk> <undeployBeforeDeploy>false</undeployBeforeDeploy> </configuration> <extensions>true</extensions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.5</version> </plugin> <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. --> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <versionRange>[3.2.0,)</versionRange> <goals> <goal>manifest-update</goal> </goals> </pluginExecutionFilter> <action> <execute /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </build> </project>
This is the output of the error log
**The problem is that it doesn't find the classes (until I import it manually, but Maven and Eclipse should handle that) If I try to import for example
org.junit.Test
,org.junit.runner.RunWith
ororg.mockito.Mock
I get in EclipseThe import xxxxx cannot be resolved
Problems tab in Eclipse:
The project was not built since its build path is incomplete. Cannot find the class file for org.mockito.verification.VerificationMode. Fix the build path then try building this project com.mygame-TRUNK Unknown Java Problem The type org.mockito.verification.VerificationMode cannot be resolved. It is indirectly referenced from required .class files GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1 Java Problem
解决方案As of version 1.0.0 Android for Maven Eclipse has changed the way it manages the Maven classpaths. Non-runtime dependencies (effectively, anything not in the
compile
scope) are now loaded into a new Maven, non-runtime classpath container. Are you seeing these libraries appear in this new classpath container?If not, please try deleting the project from your workspace, deleting the IDE-specific
.*
metadata files and trying re-importing as a Maven project.这篇关于月蚀:为什么和使用Maven项目没有缺陷的Eclipse项目时,时添加库来构建路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!