Maven plugin, classpath, Tomcat and classloaders

848 views
Skip to first unread message

Esben Rugbjerg

unread,
Aug 26, 2013, 11:24:15 AM8/26/13
to robotframe...@googlegroups.com
Hi, 

I need some help on a major problem which I think is related to the class path. 

I am using Maven plugin version 1.2, Maven version 3.0.4 and Java 1.7 64-bit.

I am working on a small client which shall interact with Jenkins through its REST interface to retrieve status of builds on the Jenkins server. To make integration tests of the client I want to start up a Tomcat, deploy a Jenkins instance and let it expose some build data and then test the daemon by validating its behaviour when retrieving data from the Jenkins instance. 

I want the Tomcat to be started from the glue code to make easy to control (inspired by http://www.hostettler.net/blog/2012/04/09/embedded-jee-web-application-integration-testing-using-tomcat-7/). I know that might be able to achieve the same by using the Maven Tomcat plugin but I want to have the problem solved to learn something about how to setup test environments when using RF. 

This is my glue code which is called from my RF test case:
public void startJenkinsServer() throws Throwable
{
try
{
LOGGER.info("Starting the server...");
tomcat = new Tomcat();
String portValue = System.getProperty("localJenkinsPort");
LOGGER.info("Jenkins port: " + portValue);
int jenkinsPort = Integer.parseInt(portValue);
tomcat.setPort(jenkinsPort);
tomcat.setBaseDir(tomcatWorkingDir);
String contextPath = "/" + JENKINS;
Context context = tomcat.addWebapp(tomcat.getHost(), contextPath, new File("src/test/resources/jenkinsWebapp/jenkins-1.499.war").getAbsolutePath());
File configFile = new File("src/test/robotframework/tomcatContext.xml").getAbsoluteFile();
context.setConfigFile(configFile.toURI().toURL());
tomcat.start();
      } catch .......

This is my latest Maven configuration
<groupId>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>run</goal><!-- Integrations Test -->
</goals>
</execution>
</executions>
<configuration>
<skipTests>${skipIntegrationTests}</skipTests>
<extraPathDirectories>
<extraPathDirectory>${project.build.directory}/test-classes</extraPathDirectory>
<extraPathDirectory>${org.apache.tomcat.embed:tomcat-embed-core:jar}</extraPathDirectory>
<extraPathDirectory>${org.apache.tomcat.embed:tomcat-embed-logging-juli:jar}</extraPathDirectory>
<extraPathDirectory>${org.eclipse.jdt.core.compiler:ecj:jar}</extraPathDirectory>
<extraPathDirectory>${org.apache.tomcat.embed:tomcat-embed-jasper:jar}</extraPathDirectory>
<extraPathDirectory>${org.slf4j:slf4j-api:jar}</extraPathDirectory>
<extraPathDirectory>${org.slf4j:slf4j-jdk14:jar}</extraPathDirectory>
</extraPathDirectories>
<ExternalRunnerConfiguration>
<externalRunner>
<environmentVariables>
<CLASSPATH>${org.apache.tomcat.embed:tomcat-embed-core:jar}</CLASSPATH>
</environmentVariables>
</externalRunner>
</ExternalRunnerConfiguration>
<excludes>
<exclude>redTest</exclude>
</excludes>
</configuration>
<dependencies>
</dependencies>
</plugin>

When I execute the integration-test goal I get the following exception:

java.lang.ClassNotFoundException: org.apache.catalina.deploy.ServletDef
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

The missing class is included in the tomcat-embed-core.jar which is included in the POM as a Maven dependency with scope 'test'. 

I have tried the following solutions without luck:

1. Before trying the ExternalRunnerConfiguration, I have tried to add the missing jar to the pythonpath using extraPathDirectory as it can seen above. I had no luck with that.

2. Adding the path of the path of the offending jar file to the systems property 'java.class.path' in the class before starting the Tomcat instance. I had no luck with that either.

3. Using the External Runner configuration. I would expect the offending jar to be on the CLASSPATH when I try to execute the code using the ExternalRunnerConfiguration. As it can be seen I have also tried to add it manually to the CLASSPATH of the external runner configuration but with no luck either. When I print out the CLASSPATH environment variable from inside the Java class instantiating the Tomcat instance, using the following snippet of code:

LOGGER.info("CLASSPATH: " + System.getenv("CLASSPATH"));

None of the 'test'-scope dependencies are included. 

I am running out of ideas for a solution. Could somebody please help me ? 

I think the problem might be related to the fact that Tomcat seems to have its own class loader but I am not sure and I can't see how it should influence the CLASSPATH.

Thanks.

Esben Rugbjerg

Dezider Mesko

unread,
Aug 27, 2013, 6:46:42 AM8/27/13
to esbenr...@gmail.com, robotframe...@googlegroups.com
Hi,

Btw, I'm not 100% sure, however extraPathDirectory doesn't have anything with java/classpath libraries as such. Its for keywords libraries.


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages