views:

43

answers:

2

I have a straightforward Maven2/Spring project. Locally in Intellij all the tests run fine, however on the build server (Hudson), the application context won't start because test-context.xml can't be found on the classpath.

New to this...any ideas? Assuming this is something obvious...

Project dir structure:

-src
--java
--resources
-test
--java
---test-context.xml

Note: makes no difference locally if test-context.xml is in test/java or test/resources

Relevant bits of the pom:

<properties>
    <org.springframework.version>3.0.3.RELEASE</org.springframework.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.build.testOutputDirectory>test-classes</project.build.testOutputDirectory>
    <project.build.testSourceDirectory>test</project.build.testSourceDirectory>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc-portlet</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.7</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>1.6</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>net.javacrumbs</groupId>
        <artifactId>spring-ws-test</artifactId>
        <version>0.19</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor-xml</artifactId>
        <version>1.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.2.2</version>
    </dependency>

    <dependency>
        <groupId>hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>1.8.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
    </dependency>

    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.11.0.GA</version>
    </dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time-hibernate</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>

<build>
    <sourceDirectory>src/java</sourceDirectory>
    <testSourceDirectory>test/java</testSourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <formats>
                    <format>xml</format>
                    <format>html</format>
                </formats>
            </configuration>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
            <configuration>
                <junitArtifactName>junit:junit</junitArtifactName>
                <includes>
                    <include>**/*Tests.java</include>
                </includes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <configuration>
                <formats>
                    <format>xml</format>
                    <format>html</format>
                </formats>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.4.3</version>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>1.2</version>
        </plugin>
    </plugins>
</reporting>
A: 

Where is your test-context.xml located? In the src/test/resources folder ? How does your pom look like ? Otherwise this will be some kind of "magic" to answer this question with such less information...

khmarbaise
I've added some more detail, hopefully that helps. The odd part is that the exact same code, and same pom work locally, but the context can't be loaded from the classpath on the server.
Thody
First question on that: Why are you redefining the locations ? Like test-classes etc. instead of using the Maven way (Convention over configuration) Are there particular reasons for that? On the other hand can you past the log file excerpt from Hudson to see the error messages there in detail...
khmarbaise
+1  A: 

Locally in Intellij all the tests run fine

The question is: does your project build fine when running Maven on the command line? This is the only way to reproduce the issue (and this is also the reference, having things running under any IDE is not really relevant). Then look at the traces of the unit test (logged in a text file under target/surefire-reports). And maybe attach them to this question.

however on the build server (Hudson), the application context won't start because test-context.xml can't be found on the classpath.

And how do you load it?

PS: I would also recommend sticking to Maven's default project layout.

Pascal Thivent
They run fine via the command line locally as well. It's been a few days since I did the pom setup, but I believe the test-classes weren't being picked up by cobertura, so I referenced them explicitly, I didn't change the location though.I load the context via a ContextConfiguration annotation in the tests.From the test report:Caused by: java.io.FileNotFoundException: class path resource [test-context.xml] cannot be opened because it does not exist
Thody
@Thody Are you saying that you can't reproduce? That's annoying. And this somehow means that your build is environment dependent which is not a good thing. Can you reproduce on the Hudson machine? Or maybe provide the traces you get on hudson?
Pascal Thivent