Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding classpath to jetty running in maven integration-test

I'm trying to set up integration tests for a Maven project that produces a war file. (As seen here http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/.) However I the war file requires a bunch of .properties files on the classpath, that I don't want to bundle in the war.

Is there a way (preferably through plugin configuration) to add a folder to the classpath used by jetty?

I Googled this and found http://markmail.org/message/awtqrgxxttra3uxx but this, as far as I can tell, does not actually work at all. The .properties files are not found.

like image 772
Sindri Traustason Avatar asked Feb 01 '10 10:02

Sindri Traustason


People also ask

How does maven run integration tests?

The simplest way to run integration tests is to use the Maven failsafe plugin. By default, the Maven surefire plugin executes unit tests during the test phase, while the failsafe plugin runs integration tests in the integration-test phase.

What does Mvn jetty run do?

Using the Jetty Plugin enables you to quickly test your web application by skipping the last two steps. By default the Jetty Plugin scans target/classes for any changes in your Java sources and src/main/webapp for changes to your web sources.

How do I run Mvn jetty?

port on the command line, for example, "mvn -Djetty. port=9999 jetty:run". Alternatively, you can specify as many connectors as you like. You could also instead configure the connectors in a standard [jetty xml config] file and put its location into the <jettyXml> parameter.

What is Mvn jetty?

Jetty is a java servlet. Maven is a build automation tool used primarily for Java projects. the jetty's url in github is https://github.com/eclipse/jetty.project. mvn jetty:run is run a web project from pom config. mvn jetty:run are supported by maven-jetty-plugin.


3 Answers

This should be possible using the webAppConfig configuration element (sample below taken from this thread):

<webAppConfig>
  <contextPath>/nportal</contextPath>
  <!-- All I want to do here is add in the /etc/jetty/classes for runtime files. For some reason I have to also add back in the /target/classes directory -->
  <extraClasspath>${basedir}/target/classes/;${basedir}/etc/jetty/classes/</extraClasspath>
</webAppConfig> 
like image 90
Pascal Thivent Avatar answered Oct 20 '22 04:10

Pascal Thivent


If you find that the above solution doesn't work for you, consider including the test classpath into your Jetty configuration.

<configuration>
   <useTestClasspath>true</useTestClasspath>
   ...
</configuration>

This will then allow you to place all manner of resources/classes on the test classpath and have them visible to the Jetty server without them creeping into the production code.

like image 31
Gary Rowe Avatar answered Oct 20 '22 06:10

Gary Rowe


You can place your additional configuration files under /src/test/resources and set a property <useTestScope>true</useTestScope> in the plugin configuration as specified here:

useTestScope

If true, the classes from testClassesDirectory and dependencies of scope "test" are placed first on the classpath. By default this is false.

like image 28
Innokenty Avatar answered Oct 20 '22 05:10

Innokenty