我最近从 Objectify 3.1 切换到至 Objectify 4.0其中涉及切换到 Maven。构建将输出的 .class 文件放在 war/WEB_INF/classes 下,应用程序在本地和 App-Engine 上都运行良好。
我的问题是,当我运行我的 test 目标时,它找不到我的任何测试类,因为它正试图从 target/classes 目录加载它们。如果我暂时将默认输出目录切换到那个目录,测试运行正常,但当然真正的目标将不会运行(在运行时在 war/WEB-INF/classes 下找不到类定义)。
我尝试删除 target/classes 目录并可能将其链接到新位置,但 Eclipse 会在我删除它后立即重新创建它。
我做错了什么吗?如何让测试目标从指定的输出目录读取类?
2013-12-21 更新:如果我查看 App-Engine run-config 和相关测试 run-config 的“源”信息,两者都有(在项目名称下) 一个“目标”条目,带有“类”和“测试类”的子条目。它也有一个“war/WEB-INF”条目,其中包含“classes”和“lib”的子条目。不幸的是,我似乎无法删除前一组,而且我不知道是什么原因导致它存在。
2013 年 12 月 30 日更新:这是我的 pom.xml
文件...
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>DeityAE</groupId>
<artifactId>DeityAE</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.8.8</version>
</plugin>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Found this on the web but doesn't seem to be working. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execute>
<id>default-cli</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
</configuration>
</execute>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.8.8</version>
</dependency -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
<version>4.0rc2</version>
</dependency>
</dependencies>
</project>
最佳答案
我终于明白了。
- 转到“运行配置...”
- 选择目标(例如
MyProjectTests
) - 选择“类路径”选项卡
- 选择“用户条目”
- 单击“高级...”按钮
- 选择“添加文件夹”
- 浏览到
war/WEB-INF/classes
并单击“确定” - “应用”和“运行”
关于java - Eclipse 测试运行在与构建目录不同的目录中查找类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20268938/