Suppose I want to create and use an H2 database for my integration tests.
Maven has a command to run tests: mvn test.
Is there a way to tell maven to start an H2 database server for the tests and stop it when it's done?
I imagine this working similar to how I can run tomcat via a Maven command (mvn tomcat:run).
Sorry if this question is nonsensical, I'm still wrapping my head around new concepts.
I was able to get it to work without using an external server just by adding the dependency to H2 via Maven and then using this bean:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:file:h2\db"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
Then again, this required that I use a file-based DB instead of in-memory. But it does the trick.
you can create 2 small classes with main methods that start and stop the database. the idea is to run the StartServer class before the integration tests are run and then class StopServer after the tests have run.
you should do the same for your DB server as described somewhere in this document (description is for starting and stopping Jetty in integration tests)
in your pom.xml you should define the maven-exec-plugin to run the exec:java goal and create 2 executions (1 for calling StartServer and 1 for StopServer):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<!-- start server before integration tests -->
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.foo.StartServer</mainClass>
</configuration>
</execution>
<execution>
<!-- stop server after integration tests -->
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.foo.StopServer</mainClass>
</configuration>
</execution>
</executions>
</plugin>
hope that's what you want
This plugin works fine to spawn a new H2 DB with tcp mode before integration tests (the default plugin phase): h2-maven-plugin on github
It is not well documented but you can check the Mojo sources to know the configuration options. It is published on maven central.
Basically, for integration tests, you may want Maven to:
Reserve randomly available network ports, for your Tomcat server, and your H2 (to avoid port conflicts)
Start the H2 server
Start the Tomcat server
Run integration tests
Stop the Tomcat server
Stop the H2 server
This can be achieved with a Maven configuration looking like this.
Assuming your integration tests are annoted with a custom interface JUnit Category:
#Category(IntegrationTest.class)
This Maven configuration works fine for me:
<profile>
<id>it</id>
<build>
<plugins>
<!-- Reserve randomly available network ports -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>tomcat.test.http.port</portName>
<portName>h2.test.tcp.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!-- Start H2 before integration tests, accepting tcp connections on the randomly selected port -->
<plugin>
<groupId>com.edugility</groupId>
<artifactId>h2-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<port>${h2.test.tcp.port}</port>
</configuration>
<executions>
<execution>
<id>Spawn a new H2 TCP server</id>
<goals>
<goal>spawn</goal>
</goals>
</execution>
<execution>
<id>Stop a spawned H2 TCP server</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Start Tomcat before integration tests on the -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<systemProperties>
<spring.profiles.active>integration_tests</spring.profiles.active>
<httpPort>${http.test.http.port}</httpPort>
<h2Port>${h2.test.tcp.port}</h2Port>
</systemProperties>
<port>${http.test.http.port}</port>
<contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>
<fork>true</fork>
</configuration>
<executions>
<execution>
<id>run-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- Run the integration tests annotated with #Category(IntegrationTest.class) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- Bug in 2.12.x -->
<version>2.11</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12.4</version>
</dependency>
</dependencies>
<configuration>
<groups>com.mycompany.junit.IntegrationTest</groups>
<failIfNoTests>false</failIfNoTests>
<junitArtifactName>junit:junit-dep</junitArtifactName>
<systemPropertyVariables>
<httpPort>${tomcat.test.http.port}</httpPort>
<h2Port>${h2.test.tcp.port}</h2Port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
You may want to use maven filters on the tomcat context file so that the port is replaced:
<contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>
With the file content being:
<Resource name="jdbc/dataSource"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username=""
password=""
driverClassName="org.h2.Driver"
url="jdbc:h2:tcp://localhost:${h2.test.tcp.port}/mem:db;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL"/>
Or if you don't want a JNDI datasource, you can use a Spring declared dataSource, using the the same property...
One extra trip if you want to be able to setup your integration tests tomcat, and run the integration tests from your IDE:
You can use use a property to fork or not the Tomcat server:
<fork>${integrationTestsForkTomcatJvm}</fork>
When you set fork=false, the server will block and maven won't continue, so the integration tests won't be run, but you will be able to run them from your ide.
I create a file-based H2 database before unit tests are run. The file lives in the target directory and can be removed at any time using mvn clean.
I use the maven-sql-plugin as follows:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.166</version>
</dependency>
</dependencies>
<configuration>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:file:target/db/testdb</url>
<username>sa</username>
<password></password>
<autocommit>true</autocommit>
<skip>${maven.test.skip}</skip>
</configuration>
<executions>
<execution>
<id>create-db</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<srcFiles>
<srcFile>${sql.dir}/drop_db.sql</srcFile>
<srcFile>${sql.dir}/tables.sql</srcFile>
<srcFile>${sql.dir}/constraints.sql</srcFile>
... etc ...
</srcFiles>
</configuration>
</execution>
</executions>
</plugin>
The database can be created by running mvn process-test-resources. When tests are run, make sure you connect to the database in target/db/testdb via hibernate properties.
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="org.h2.Driver"
p:url="jdbc:h2:file:target/db/testdb"
p:username="sa"
p:password="" />
You will also need to a dependency on com.h2database.h2 in maven's dependencies.
In my project, for unit testing, I asked Spring to handle this database creation and initialization. As stated in the H2 documentation, you can create a bean for that:
<bean id = "org.h2.tools.Server"
class="org.h2.tools.Server"
factory-method="createTcpServer"
init-method="start"
destroy-method="stop">
<constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
</bean>
You simply need to start the Spring context with this configuration when you start your unit tests.
I've just started project for H2 plugin for maven # bitbucket. I will appreciate any help with it.
https://bitbucket.org/dohque/maven-h2-plugin
Hope it will be helpful.
If you want to make it in memory, then just use a different URL:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:mem:db"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
You can give additional options, such as: ;DB_CLOSE_DELAY=-1
see: http://www.h2database.com/html/features.html#in_memory_databases
following does the job for me (just using h2 dependency and the exec-maven-plugin):
<build>
<plugins>
<!-- start/stop H2 DB as a server -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>start-h2</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.h2.tools.Server</mainClass>
<arguments>
<argument>-tcp</argument>
<argument>-tcpDaemon</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>stop-h2</id>
<phase>post-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.h2.tools.Server</mainClass>
<arguments>
<argument>-tcpShutdown</argument>
<argument>tcp://localhost:9092</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</executableDependency>
</configuration>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.173</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
please note, in my pom.xml the com.h2database:h2 was not project dependency.
In case you'd have it you might don't need to explicitly name it as a plugin dependency.
Since H2 doesn't provide Maven plugin you should start it using maven-antrun-plugin. Write code for start and stop h2 engine in ant task and call it when your integration test starts and stop.
See details on http://docs.codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing
Related
Using Maven, I need to automatically deploy a web application to a Tomcat server, then run a MainClass in order to do some post-deploy operations.
These two things alone are already working, through cargo-maven2-plugin respectively exec-maven-plugin. However I don't know how bind them together.
I see two options:
Making the "official" maven deploy goal to simply execute cargo-plugin, then exec-maven and nothing else
Binding the execution of exec-maven to the completion of cargo:deploy
The first is my favouire. Unfortunately I don't know how to implement any of them.
The current pom.xml:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.15</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
<type>remote</type>
<systemProperties>
<cargo.jvmargs>-XX:MaxPermSize=256M -Xmx1024m</cargo.jvmargs>
</systemProperties>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname>${my.hostname}</cargo.hostname>
<cargo.servlet.port>${my.port}</cargo.servlet.port>
<cargo.tomcat.manager.url>${my.hostname}/manager</cargo.tomcat.manager.url>
<cargo.remote.username>tomcat</cargo.remote.username>
<cargo.remote.password>tomcat</cargo.remote.password>
</properties>
</configuration>
<deployables>
<deployable>
<location>${project.build.directory}/${project.build.finalName}.war</location>
<type>war</type>
<properties>
<context>/${project.build.finalName}</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<!-- NEED TO BE AFTER DEPLOY -->
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>ch.MainClass</mainClass>
<arguments>
<argument>Will be forwarded to main()</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
I would suggest to bind cargo-maven2-plugin to the pre-integration-test phase and the exec-maven-plugin in your case to the integration-test phase which is after the package phase. See also the documentation about the default life cycle phases.
The deploy phase is usually used to deploy the generated artifacts to a maven repository so it does not really make sense to bind running an integration test to this phase.
<plugin>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>xxxx</goal>
</goals>
<configuration>
....
</configuration>
</execution>
</executions>
</plugin>
The above configuration can be applied to both of your plugins exec-maven-plugin as well as cargo-maven2-plugin...
The best approach is to separate such integration test scenarios into a separate module or if you have only a single module use a profile to active integration tests.
How can I set active spring profile o tomcat maven plugin? I want to get active profiles in runtime from Environment, but I' always getting empty array.
I tried to add this systemProperties in plugin configuration in pom.xml:
<JAVA_OPTS>-Dspring.profiles.active=local</JAVA_OPTS>
or
<name>spring.profiles.active</name>
<value>locale</value>
I try to add this in context.xml:
<environment name="spring.profiles.active" value="local" type="java.lang.String" override="false"/>
But still getting no active profile...
My env: Java 6, tomcat7-maven-plugin version 2.2, Netbeans 8.0.2, Spring 3.1.1.RELEASE.
My pom.xml tomcat plugin looks this:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!-- http port -->
<port>8084</port>
<contextFile>${basedir}/src/main/resources-local/context.xml</contextFile>
<systemProperties>
<JAVA_OPTS>-Dspring.profiles.active=local</JAVA_OPTS>
</systemProperties>
</configuration>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>run-war</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<dependencies>
Tomcat 7 Documentation shows a different syntax for System Properties like the one below. So try doing it this way:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<systemProperties>
<example.value.1>alpha</example.value.1>
<example.value.2>beta</example.value.2>
</systemProperties>
</configuration>
</plugin>
I'm trying to make work arquillian tests with jboss managed server and IBM DB2 database.
For now I'm stuck on creating datasource. Since JBoss is unpacked on each run, I'm trying to add driver and datasource configuration into pom.xml in order to Maven take care of creating proper configurations on JBoss and resulting section looks like this:
<profile>
<id>arquillian-jboss-managed</id>
<build>
<plugins>
<!-- JBoss server itself -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-dist</artifactId>
<version>7.1.1.Final</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- adding datasource -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-driver</id>
<phase>process-test-classes</phase>
<!-- groupId and artifactId aren't global, I've got jar on defined path -->
<configuration>
<groupId>db2</groupId>
<artifactId>db2cc</artifactId>
<name>db2jcc4.jar</name>
</configuration>
<goals>
<goal>deploy-artifact</goal>
</goals>
</execution>
<execution>
<id>add-datasource</id>
<phase>process-test-resources</phase>
<configuration>
<address>subsystem=datasources,data-source=MyDataSource</address>
<properties>
<connection-url>jdbc:db2://host:port/database</connection-url>
<jndi-name>MyDataSource</jndi-name>
<enabled>true</enabled>
<pool-name>MyDataSource</pool-name>
<user-name>db2inst1</user-name>
<password>pass</password>
<driver-name>db2jcc4.jar</driver-name>
</properties>
</configuration>
<goals>
<goal>add-resource</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Yet I've got an error:
Failed to execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:add-resource
(add-datasource) on project testrunner: Could not execute goal
add-resource. Reason: I/O Error could not execute operation '{
"address" => [], "operation" => "read-attribute", "name" =>
"launch-type" }': java.net.ConnectException: JBAS012144: Could not
connect to remote://localhost:9999. The connection timed out
I guess the problem is JBoss isn't started at the moment Maven tries to apply configuration parameters or simply doesn't listen to required port.
Any help is greatly appreciated
Thanks in advance
Fixing this problem was as simple as adding start and shutdown goals to jboss-as-maven-plugin executions before and after other configuration:
<execution>
<id>start-server</id>
<phase>process-test-classes</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<!-- copying driver and datasource here -->
<execution>
<id>shutdown-server</id>
<phase>process-test-classes</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
Also this start goal downloads it's own JBoss instance if one is not provided. So this part is not needed any more:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<!-- skipped -->
</plugin>
I have the following setup: normally my webapp will be deployed on stand-alone server and connect to MySQL database. However I want ability to "self-test" the application with Selenium. So during mvn clean install there will be embedded server (Jetty 7), Selenium Server and in-memory database (HSQLDB) that will allow to perform some actions (example user inputs for the webapp).
Now I already setup Selenium/embedded server setup using maven plugins:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<!-- Log to the console. -->
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<!-- This doesn't do anything for Jetty, but is a workaround for a Maven bug
that prevents the requestLog from being set. -->
<append>true</append>
</requestLog>
</configuration>
</plugin>
<!--
*******************************************************
Start selenium-server before the integration test start
*******************************************************
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<id>start-selenium-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
<logOutput>true</logOutput>
<multiWindow>true</multiWindow>
</configuration>
</execution>
<execution>
<id>stop-selenium-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ********************************************************
Force to run the testcases in the integration-test phase
******************************************************** -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
<!-- ***********************************************************
Deploy the war in the embedded jetty of cargo2-maven-plugin
*********************************************************** -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<wait>false</wait>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
</container>
</configuration>
</plugin>
And it is working just fine. Unfortunately I'm having some issues trying to make Spring/Maven use different XML configuration file when app is being deployed on embedded server for integration testing purposes.
I tried using:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "classpath:servlet-context-test.xml" })
#FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestWebapp extends SeleneseTestCase{
(servlet-context-text.xml is located in src/test/resources)
but when Selenium tests run the webapp is still started with default configuration.
I'm trying to load different xml file because I basically want to use this:
<jdbc:embedded-database id="dataSource">
<jdbc:script location="classpath:sql/schema.sql"/>
<jdbc:script location="classpath:sql/fk.sql"/>
<jdbc:script location="classpath:sql/data.sql"/>
</jdbc:embedded-database>
instead of my normal dataSource declaration.
You should have a look at the Spring profiles (http://blog.springsource.org/2011/02/14/spring-3-1-m1-introducing-profile/). With a profile, you can activate/deactivate beans in different ways (programamtically, with environment variable etc.)
Maybe it will be helpful to someone out there. I finally resolved this issue using Maven profiles (separate profiles for integration testing and for production build) and filtering (parametrized my servlet-context.xml in regards to importing either dataSource.xml or dataSourceIntegrationTesting.xml). Works like a charm.
Since I'm trying to set an embded container in my maven project I want to it run during the integration test phase. I have two problems with jetty that I can not manage to resolve :
<daemon>true</daemon> doesn't have the expected effect. The server is run but then it locks the build process (in fact it blocks the unit tests). So where am I supposed to place that configuration ?
The <useTestClasspath>true</useTestClasspath> is a mystery for me. I don't want to use the src/main/webapp/WEB-INF/lib to place the postgresql jar (which is called by jetty for the datasource (postegresql-driver)) because it would be embeded in the application and I don't want it to be in the war (client side). So I want to use <useTestClasspath>true</useTestClasspath> but when I place postgresql in the src/test/resources it doesn't find/recognize it. So, how am I supposed to use that property ?
Here is the complete plugin configuration :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.9</version>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<useTestClasspath>true</useTestClasspath>
<daemon>true</daemon>
<contextPath>agepro-prototype</contextPath>
<webApp>
${project.build.directory}/agepro-prototype.war
</webApp>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9091</port>
</connector>
</connectors>
<stopPort>9092</stopPort>
<stopKey>test</stopKey>
</configuration>
</plugin>
Thanks in advance for the help you could provide me. I must apologize for my grammar, because my english is quite bad.
Regards,
Depado
Not sure about your first question, but as for your second, specify the postgresql jar as provided scope in your main dependency block (this will prevent it from being bundled in the war), and add an additional dependency block in the jetty plugin definition (with compile scope), which will make the postgresql jar available at jetty runtime:
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.9</version>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war</goal>
</goals>
<configuration>
<daemon>true</daemon>
<contextPath>agepro-prototype</contextPath>
<webApp>
${project.build.directory}/agepro-prototype.war
</webApp>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9091</port>
</connector>
</connectors>
<stopPort>9092</stopPort>
<stopKey>test</stopKey>
</configuration>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
<scope>provided</scope>
</dependency>
</dependencies>
I don't want to use the src/main/webapp/WEB-INF/lib to place the postgresql jar (which is called by jetty for the datasource (postegresql-driver)) because it would be embeded in the application and I don't want it to be in the war (client side). So I want to use true but when I place postgresql in the src/test/resources it doesn't find/recognize it
You shouldn't be placing jars in any folders (src/main/resources or src/main/webapp/WEB-INF/classes), they should all be defined as dependencies in your pom.
I also imagine the useTestClasspath is being ignored when you define the webApp configuration element, as the it's using the packaged war, which will not contain your test resources / classes
useTestClasspath/useTestScope are only available for jetty:run
This is why it doesn't work with jetty:run-war and other jetty:goals