Angular 2 and Spring Boot - Deploy to War - spring

Let me just start off by saying, I am new to Maven / Spring and am having a hard time figuring out what to do when my directory does not follow the preferred Maven structure.
I followed instructions for setting up a project with Angular 2 and Spring Boot via this tutorial. This tutorial creates two modules, frontend and backend, with corresponding pom.xml's and one parent pom.xml. I can run the application just fine using my IDE, IntelliJ, or by running "mvn spring-boot:run" from the backend directory. However, for deployment, I wish to package the application into a WAR file to drop into a Tomcat server. I am unsure how to do this using the pom.xml's that I currently have. I am quite sure that it has to do with my directory structure, however I am not sure if I should restructure my application or of there is a way to configure Maven to place the two modules into resulting WAR file that works as intended.
I have found a similar answer here but the last part is what throws me off. I do not have a /src/main/webapp/WEB-INF folder and am unsure where to make it.
My application structure is as follows:
AppRoot
-backend
--src
---main
----java
--pom.xml
-frontend
--src
---main
----frontend
--pom.xml
-pom.xml
My root pom.xml is:
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>c-cop</name>
<description>C-COP Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<modules>
<module>frontend</module>
<module>backend</module>
<module>web</module>
Frontend pom.xml:
<artifactId>frontend</artifactId>
<name>frontend</name>
<description>C-COP Project frontend</description>
<parent>
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<nodeVersion>v6.9.1</nodeVersion>
<npmVersion>4.0.3</npmVersion>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/frontend</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
Backend pom.xml:
<artifactId>backend</artifactId>
<name>backend</name>
<description>C-COP Project backend</description>
<parent>
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.trinityinnovations</groupId>
<artifactId>frontend</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
</dependency>
<dependency>
<groupId>com.javaetmoi.core</groupId>
<artifactId>javaetmoi-hibernate5-hydrate</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.1.20</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Please let me know if there is any more information that is needed.

After doing a lot of searching, I came across the Maven War Plugin. This allowed me to pull in the necessary frontend files to the backend for the successful creation of my WAR file. The changes that need to be made are as follows:
Backend pom.xml -
after the description tags add:
<packaging>war</packaging>
Then, inside the build tags, inside plugins add this plugin:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>../frontend/target/frontend</directory>
</resource>
</webResources>
</configuration>
</plugin>
Other than that, you can keep the existing pom.xml's the same as only the backend pom.xml needs include war packaging. It ended up being a rather simple answer.
Also need to set the base-href in the package.json. Note "build":
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build": "ng build --base-href=\"./\""
},

Hello i use Angular 4 and Spring boot to deploy war. It's work fine and i share it.
Here pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Spring_Angular</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging><name>Spring_Angular</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${basedir}/target/angular4Client</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<nodeVersion>v8.9.2</nodeVersion>
<npmVersion>5.6.0</npmVersion>
<installDirectory>target</installDirectory>
<workingDirectory>${basedir}/src/main/angular4client</workingDirectory>
</configuration>
<executions>
<!-- It will install nodejs and npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v8.9.2</nodeVersion>
<npmVersion>5.6.0</npmVersion>
</configuration>
</execution>
<!-- It will execute command "npm install" inside "/e2e-angular2" directory -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- It will execute command "npm build" inside "/e2e-angular2" directory
to clean and create "/dist" directory -->
<execution>
<id>npm build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Plugin to copy the content of /angular/dist/ directory to output
directory (ie/ /target/transactionManager-1.0/) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/angular4Client/dist/angular4Client</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/angular4Client</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
</project>
Then in your angular package.json change like this:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
Create a proxy.conf.json file in angular project root :
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
And last things to do, move your angular 4 project into : "src/main/" on SpringBoot project.
Good luck according to this demo : http://javasampleapproach.com/java-integration/integrate-angular-4-springboot-web-app-springtoolsuite

The reference doc contains a detailed description of this. You need <packaging>war</packaging> in both your frontend and backed module pom and some Java code. All described here
With that said, I try to avoid war deploys if not totally necessary. You could just run the built jar file with java -jar your.jar and it will start in an embedded Tomcat.

Related

Make Intellij IDE run the Kotlin/Java annotation processing when changing Kotlin source files

Recently I have started using Kotlin v1.2 with Intellij IDEA v2017.3.
I implemented an annotation processor in Kotlin, which writes a resource file under META-INF, when a class is annotated with the supported annotation type.
I can see that the annotation processor is working with another Maven project, which is using the implementation as a dependency. If I run mvn clean compile, the file under META-INF is generated correctly in target/classes/META-INF.
My problem is that Intellij does not start the annotation processor when a source file is changed. For example, if I rename the annotated Kotlin class. The resource file is not regenerated or updated. (I haven't seen the annotation processor working yet from Intellij...)
I also enabled annotation processing and configured "obtain processors from project classpath" within the IDE like described here.
I imported the project as a Maven project here is my pom.xml - like I said: It is working when building with Maven:
<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>org.example</groupId>
<artifactId>usage</artifactId>
<version>1</version>
<properties>
<kotlin.version>1.2.0</kotlin.version>
</properties>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
<executions>
<execution>
<id>kapt</id>
<phase>generate-sources</phase>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessors>
<annotationProcessor>org.example.MyProcessor</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- Dependency containing the annotation processor -->
<dependency>
<groupId>org.example</groupId>
<artifactId>processor</artifactId>
<version>1</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Pass port number from docker-maven-plugin to spring property

I'm developing Spring Data JPA project that targets a MySQL database, and I want to run end-to-end integration tests from Maven.
So far, I've configured io.fabric8.docker-maven-plugin to spin up a MySQL container during pre-integration-test phase. It will use a random available port, which I need to pass to my application.properties file.
I've tried Automatic property expansion using Maven but I suspect that the mysql.port maven property is only getting resolved after the spring properties are getting updated.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>example</groupId>
<artifactId>pass-port-number-from-docker-maven-plugin-to-spring-property</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- other jpa dependencies ... -->
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>docker-test</id>
<properties>
<docker-maven.version>0.21.0</docker-maven.version>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<portNames>
<portName>mysql.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven.version}</version>
<configuration>
<images>
<image>
<alias>mysql</alias>
<name>mysql:5.7</name>
<run>
<env>
<MYSQL_ROOT_PASSWORD>my-secret-pw</MYSQL_ROOT_PASSWORD>
</env>
<ports>
<port>mysql.port:3306</port>
</ports>
<wait>
<log>ready for connections</log>
<!-- <time>20000</time> -->
</wait>
<log>
<prefix>mysql</prefix>
<date>ISO8601</date>
<color>blue</color>
</log>
</run>
</image>
</images>
</configuration>
<!-- Connect start/stop to pre- and
post-integration-test phase, respectively if you want to start
your docker containers during integration tests -->
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
application.properties
mysql.port = #mysql.port#
When I run my test I get a connection error, and when I inspect target/classes/application.properties I see that #mysql.port# hasn't been updated.
Any suggestions would be much appreciated.
# only works if you extend from spring-boot-starter-parent; you didn't show the relevant portions of your pom.xml. Assuming you did that, try attaching reserve-network-port to process-sources phase, before process-resources. It's very possible that when Maven copies the resources, the reserve-network-port hasn't ran yet.
What happens if you hardcode 3306 in application.properties?

How to run maven test with mysql running in docker

I have a maven java project. I need to run a mysql docker image in maven test stage to run tests and when its done i can remove mysql docker image.
One example would be to use the Docker Maven Plugin (https://dmp.fabric8.io/). Here is an example pom that would start a MySQL container, do your integration tests using the Maven Failsafe Plugin, then stop the MySQL container. It also would pass the property mysql.jdbc.url to the tests so they have the right JDBC URL to the MySQL container running on the specific Docker host (which could be different depending how you are running Docker).
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.1</version>
<extensions>true</extensions>
<configuration>
<images>
<image>
<alias>database</alias>
<name>mysql:5.7</name>
<run>
<wait>
<log>mysqld: ready for connections</log>
<time>20000</time>
</wait>
<env>
<MYSQL_ROOT_PASSWORD>abc123</MYSQL_ROOT_PASSWORD>
<MYSQL_DATABASE>testdb</MYSQL_DATABASE>
<MYSQL_USER>mysql</MYSQL_USER>
<MYSQL_PASSWORD>mysql</MYSQL_PASSWORD>
</env>
<ports>
<port>3306:3306</port>
</ports>
</run>
</image>
<image>
<name>mvndemo</name>
<build>
<from>java:8-jre</from>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker:start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker:stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<mysql.jdbc.url>jdbc:mysql://${docker.host.address}/testdb</mysql.jdbc.url>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
You can also opt for Testcontainers you will need to change the driver to a specific JDBC driver from testcontainer that will do the spinning up and spinning down of your required service. They also support other databases and versions. It is quite easy to do. You also get the option to startup and stop the container yourself from within a junit test if you need advanced stuff like initialization scripts.

JMS config settings for jetty deployment using cargo

We have a current web application that is deployed to OAS (Oracle Application Server).
I am trying to implement some functional tests using selenium for this application. I created a new maven project specifically for functional testing, which uses cargo to deploy the application war file (webapp-site.war) to the default container provided by cargo (Jetty). pom.xml attached at the end.
The problem I am facing is in trying to configure jms properties. The current setting in the web application uses OAS specific values from an environment specific jms.properties file (shown below):
java.naming.factory.initial=oracle.j2ee.rmi.RMIInitialContextFactory
java.naming.provider.url=opmn:ormi://localhost:6003:OC4J_DEV/default
java.naming.security.principal=username
java.naming.security.credentials=password
jms.queue.connection.factory.jndi=jms/QueueConnectionFactory
When I start up jetty using cargo, the deployment of the application war fails when it looks for the "RMIInitialContextFactory" and does not find it. This is an OAS specific jar which is not available in the global maven repository. I managed to download and install this jar in the local maven repo, but then it showed a missing class from another oracle specific jar not present in the global maven repo. Also, even I resolved all such dependencies to external jar, I am unsure of how it would perform with Jetty.
It would be really helpful to know how to configure these properties in cargo specific to jetty and have it picked up by the deployable application war.
Attaching the pom.xml of the functional test module below:
<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>
<artifactId>webapp-automation</artifactId>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<parent>
<groupId>com.webapp</groupId>
<artifactId>webapp</artifactId>
<version>11.0.5</version>
</parent>
<name>Functional tests for webapp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<servlet.port>9090</servlet.port>
<seleniumHost>localhost</seleniumHost>
<seleniumPort>4444</seleniumPort>
<selenium.version>2.3</selenium.version>
<selenium.background>true</selenium.background>
</properties>
<dependencies>
<dependency>
<groupId>com.webap</groupId>
<artifactId>webapp-site</artifactId>
<type>war</type>
<version>${project.version.number}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>${selenium.version}</version>
</plugin>
<!-- CARGO is used to deploy the RAPS application for functional testing -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.2</version>
<configuration>
<container>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<properties>
<cargo.servlet.port>${servlet.port}</cargo.servlet.port>
<cargo.datasource.datasource.ojdbc14>
cargo.datasource.driver=oracle.jdbc.driver.OracleDriver|
cargo.datasource.url=jdbc:oracle:thin:#deirbned01.deir.citec.qld.gov.au:1521:RAPSDEV|
cargo.datasource.jndi=jdbc/RAPSDS|
cargo.datasource.username=RAPS_9|
cargo.datasource.password=sm4u
</cargo.datasource.datasource.ojdbc14>
</properties>
</configuration>
<deployables>
<deployable>
<groupId>com.webapp</groupId>
<artifactId>webapp-site</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<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>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-cargo</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-cargo</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<id>start-selenium</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
</execution>
<execution>
<id>stop-selenium</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
<configuration>
<background>${selenium.background}</background>
<port>${selenium.port}</port>
<logOutput>true</logOutput>
</configuration>
</plugin>
</plugins>
</build>
Any help would be great !!
Cheers,
Rahul
I found a way of solving the problem.
We use some environment specific settings in the project. I created a new environment profile in the build for functional tests and created a new jms.properties with the initial context factory pointing to the one provided by jetty.
It worked.
Cheers,
Rahul

Maven deploy multiple wars to embedded server for integration tests

I have had no issue running a maven war project on an embedded server for its own integration tests, but now I need to run multiple wars and test from a different project.
I would like to setup the following scenario...
I have two Maven war projects in my local workspace called War1 and War2. I would like to have a 3rd Maven project, WarIntegration, that contains only integration tests and does the following:
Packages War1
Packages War2
Starts an embedded server
Deploys both wars to same embedded server
Runs integration tests contained within WarIntegration (which will make http calls to War1 and War2)
Stops embedded server
Is this possible? What plugin setup will achieve this? What kind of project should WarIntergration be (packaging)? Should War1 and War2 be modules in WarIntegration or dependencies? Can all of the configuration be aded to the WarIntegration project or would it have to be spread across the projects?
This is similar to this question, except we must use an embedded server that is started and stopped by the project (probably when we run verify) and we need a separate project for integration tests:
I have a multi-module Maven 2 POM that has two WARs, how can I configure it to deploy both wars prior to running tests?
I was able to achieve this using the cargo-maven2-plugin.
Here are the relevant pieces of the pom for anyone who is interested...
...
<groupId>com.test</groupId>
<artifactId>webapp-integration</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
...
<dependencies>
...
<dependency>
<artifactId>webapp1</artifactId>
<groupId>com.test</groupId>
<version>1.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>webapp2</groupId>
<artifactId>com.test</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<container>
<containerId>jetty6x</containerId>
<type>embedded</type>
</container>
<configuration>
<type>standalone</type>
<properties>
<cargo.servlet.port>8085</cargo.servlet.port>
</properties>
<deployables>
<deployable>
<artifactId>webapp1</artifactId>
<groupId>com.test</groupId>
<type>war</type>
<pingURL>http://localhost:8085/testapp/</pingURL>
<properties>
<context>testapp</context>
</properties>
</deployable>
<deployable>
<artifactId>webapp2</artifactId>
<groupId>com.test</groupId>
<type>war</type>
<pingURL>http://localhost:8085/testapp2/</pingURL>
<properties>
<context>testapp2</context>
</properties>
</deployable>
</deployables>
</configuration>
</configuration>
<executions>
<execution>
<id>start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.12</version>
</dependency>
</dependencies>
<configuration>
<groups>com.test.integration.IntegrationTestMarker</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
<skipTests>false</skipTests>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Watch out, the DEPLOYABLES element is a child of plugin/configuration, NOT plugin/configuration/configuration.
The example above should be :
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.2</version>
<configuration>
<container>...</container>
<configuration>
<type>standalone</type>
<properties>
<cargo.servlet.port>8085</cargo.servlet.port>
</properties>
</configuration>
<deployables>
<deployable>
<artifactId>webapp1</artifactId>
<groupId>com.test</groupId>
<type>war</type>
<pingURL>http://localhost:8085/testapp/</pingURL>
<properties>
<context>testapp</context>
</properties>
</deployable>
<deployable>
<artifactId>webapp2</artifactId>
<groupId>com.test</groupId>
<type>war</type>
<pingURL>http://localhost:8085/testapp2/</pingURL>
<properties>
<context>testapp2</context>
</properties>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
Hope that helps !

Resources