Brian White
Brian White

Reputation: 8736

Eclipse test-run looking for classes in different directory than build is placing them

I recently make the switch from Objectify 3.1 to Objectify 4.0 which involved a switch to Maven. The build puts the output .class files under war/WEB_INF/classes and the app runs just fine both locally and on App-Engine.

My problem is that when I run my test target, it can't find any of my test classes because it is trying to load them from the target/classes directory. If I switch the default output directory temporarily to that, the tests run fine but then of course the real target won't run (class definitions not found at run-time under war/WEB-INF/classes).

I tried to delete the target/classes directory and maybe link it to the new location but Eclipse immediately recreates it as soon as I remove it.

Am I doing something wrong? How to I make the test target read classes from the designated output directory?

Update 2013-12-21: If I look at the "Source" information for both the App-Engine run-config and the associated tests run-config, both have (under the project name) a "target" entry with sub-entries of "classes" and "test-classes". It also has a "war/WEB-INF" entry with sub-entries of "classes" and "lib". Unfortunately, I can't seem to delete the former set and I have no idea what is causing it to be there.

Update 2013-12-30: Here is my pom.xml file...

<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>

Upvotes: 4

Views: 1499

Answers (2)

Brian White
Brian White

Reputation: 8736

I finally figured it out.

  • Go to "Run configurations..."
  • select target (e.g. MyProjectTests)
  • select "Classpath" tab
  • select "User Entries"
  • click the "Advanced..." button
  • choose "Add Folders"
  • browse to war/WEB-INF/classes and click "OK"
  • "Apply" and "Run"

Upvotes: 1

Siva Tumma
Siva Tumma

Reputation: 1701

In mine, The working configuration's .classpath file contains something like this...

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
.
.
.
</classpath>

I think it is to do with .classpath file of individual projects (if you have multiple projects). And please note that it will not be visible by default under linux, you have to open file from file menu and type .classpath in addressbar.

Upvotes: 0

Related Questions