[英]Eclipse: Why and when to add libraries to build path when using Maven project to not have defective Eclipse project?
I have an Android project in Eclipse managed by Maven. 我在Eclipse中有一个由Maven管理的Android项目。 Yesterday I upgraded Eclipse and some plugins by the "Checked for Updated" function within Eclipse. 昨天,我通过Eclipse中的“检查更新”功能升级了Eclipse和一些插件。 After the update has finished, my Android project was defective. 更新完成后,我的Android项目存在缺陷。 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. 首先,我认为这只是一个“清理/更新项目/ Maven重建”问题,或者库的包含顺序不再适合(例如,Maven依赖项不在顶部或类似的东西),但是我能够由Maven构建,因此没有项目或Maven问题,而是Eclipse问题。 To get it working again I had to add Hamcrest, Junit and Mockito from the Maven repo to the build path manually. 为了使其再次正常工作,我必须手动将Maven存储库中的Hamcrest,Junit和Mockito添加到构建路径中。 I didn't had to do that before in this project (except android-4.1.1.4.jar). 在此项目中,我之前没有做过这件事(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 .) (我总是通过全新安装android:deploy android:run来构建和创建我的项目。)
Here are some important plugins I have currently installed... 这是我目前已安装的一些重要插件...
pom.xml 的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
or org.mockito.Mock
I get in Eclipse **问题是它找不到类(直到我手动导入它,但是Maven和Eclipse应该处理org.junit.Test
)如果我尝试例如导入org.junit.Test
, org.junit.runner.RunWith
或org.mockito.Mock
我进入Eclipse
The import xxxxx cannot be resolved 导入xxxxx无法解析
Problems tab in Eclipse: Eclipse中的“问题”选项卡:
The project was not built since its build path is incomplete. 由于构建路径不完整,因此未构建该项目。 Cannot find the class file for org.mockito.verification.VerificationMode. 找不到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. 修复构建路径,然后尝试构建此项目com.mygame-TRUNK未知的Java问题无法解析类型org.mockito.verification.VerificationMode。 It is indirectly referenced from required .class files GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1 Java Problem 它是从所需的.class文件GameProcessorTest.java /com.mygame-TRUNK/src/test/java/com/mygam/game line 1中间接引用的Java问题
As of version 1.0.0 Android for Maven Eclipse has changed the way it manages the Maven classpaths. 从1.0.0 版开始,适用于Maven Eclipse的Android已更改了其管理Maven类路径的方式。 Non-runtime dependencies (effectively, anything not in the compile
scope) are now loaded into a new Maven, non-runtime classpath container. 现在,非运行时依赖项(实际上是任何不在compile
范围内的依赖项)都被加载到新的Maven非运行时类路径容器中。 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. 如果不是,请尝试从工作空间中删除项目,删除特定于IDE的.*
元数据文件,然后尝试重新导入为Maven项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.