I have a maven project which creates a war file and this should be deployed to a bundled wildfly server via wildfly:run.
That works so far, but I need to create a datasource before deploying.
I have tried to bind the add-resource goal to different phases like deploy, install or package. None of them worked.
What is wrong?
An idea would be to use the wildfly:start attach an execution to add the datasource and deploy the application, but I don't know how.
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources,data-source=java:jboss/testDB</address>
<resources>
<resource>
<properties>
<jndi-name>java:jboss/testDB</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
<driver-class>org.h2.Driver</driver-class>
<driver-name>h2</driver-name>
<user-name>sa</user-name>
<password>sa</password>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
My solution is to use the run goal and the beforeDeployment goal:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<beforeDeployment>
<commands>
<command>data-source add --jndi-name=java:jboss/datasources/OracleDS --name=testDB --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --driver-name=h2 --user-name=sa --password=sa</command>
</commands>
</beforeDeployment>
</configuration>
</plugin>
Related
I am running Appium tests with JUnit on AWS device farm. Is there a way to upload additional test files and access them from within my code? So basically, can I access the file system of the container that runs the Appium tests?
I have the necessary files within my JAR file (which is inside a zip as per AWS requirements) but I'm not sure if and where AWS extracts the files from this JAR during the test run (probably not).
There is an option called Add extra data which can be used to upload files but I'm not sure how to access them from within my code. The documentation states:
For iOS, the extra data is actually inside the app installation
directory [...] On Android, we unarchive it in a root directory of the
sdcard.
Does this mean I would need to pull the files from the phone (Appium could do that) and put them in some temp folder? I could also try to pull the files from a git repo or a web share but I was hoping there would be a simpler way to access the file system. Another concern is whether there is some restriction which wouldn't allow me to write to the file system at all.
Does anyone have any experience with this?
There are two way that I know of to access additional files on the device host.
Include it in the jar(as you're already doing) and then access the files using the current thread. SO Post where I did this
InputStream input = null;
//load in the properties file from src/test/resources
try {
input = Thread.currentThread().getContextClassLoader().getResourceAsStream("myproperties.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("devicefarm"));
} catch (IOException ex) {
ex.printStackTrace();
}
Include it in the zip uploaded to Device Farm using the copy resources plugin.
POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-resources</outputDirectory>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>zip-with-dependencies</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
ZIP.xml:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>/dependency-jars/</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>/dependency-resources/</include>
</includes>
</fileSet>
</fileSets>
</assembly>
We can then access the additional files that are packaged in the zip uploaded to Device Farm using the path ./dependency-resources/somefilename
Device Farm's SDK will unzip the test package to the Device host machine to the /tmp directory. If you export the /tmp directory on the specify device state page you can export the same test package you uploaded using custom artifacts.
The extra data feature you mentioned will only put additional files in the device and not the device host running the tests. Also using appium to pull and push files I believe only works on simulators and not real device currently.
https://discuss.appium.io/t/pull-file-from-ios-device/1541/3
-James
I'm using the properties-maven-plugin to load properties from a custom properties file. The properties file name depends on the selected build profile.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/main/vpn/vpn-${environment}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
Each vpn-${environment}.properties file contains two properties, e.g. for dev environment:
vpn.username=dev_user
vpn.password=dev_password
Two profiles default and dev have been defined:
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment>default</environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<environment>dev</environment>
</properties>
</profile>
</profiles>
What I'm trying to do now is to use the maven-resources-plugin to replace the vpn property placeholders used within a unix template file with the property values of the corresponding active profile and to copy this file to another location.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions> <execution>
<id>copy-script</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/vpn/bin</outputDirectory>
<resources>
<resource>
<directory>${basedir}/unix-template</directory>
<filtering>true</filtering>
<includes>
<include>customUnixTemplate</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
The customUnixTemplate file contains something like vpn-connect ${vpn.username} ${vpn.password}.
After I build the project with mvn clean install -Pdev and open the output file in the src/main/vpn/bin directory I can see for a split second that the properties were taken from the correct properties file, i.e. vpn-dev.properties, but the file gets overwritten by the default properties file and I can't figure out why. I suspect that it has something to do with the build phases/orders in which the plugins are executed. Can anybody help?
Edit in response to Andrei's comment:
The maven resource plugin uses a second execution:
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}/conf</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>log4j2.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
I am using the onejar-maven-plugin to generate the jar for my project and it all goes well. But, when I try to change it to a sub-folder, for eg. dist, the jar from maven-jar-plugin gets generated, not the jar from onejar.
The onejar plugin does not have an output directory option.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/dist</outputDirectory>
<archive>
<manifest>
<mainClass>com.ss.itempriceclient.ItemPriceUploader</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
How do I change the output directory of the onejar generated file to a subfolder, eg. dist?
I finally went with maven-assembly-plugin. Has lots of configuration options.
I'm having issues with a filtered context.xml file being packaged in a mvn grails:war execution.
I have it working when you do mvn war:war but doing that doesn't create my grails application war. When running mvn grails:war I don't get the context.xml file. Is this a case of the grails:war target not running the maven-war-plugin? I'm getting no errors. Any help is appreciated. Here are my relevant pom settings:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>**/context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.3.4</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
...
<filters>
<filter>${basedir}/src/main/filters/dev.properties</filter>
</filters>
grails:war uses grails command so generate war, so it will ignore anything you configured in the "maven war plugin". You will have to configure it within grails.
I'm trying to install a wsdl file into a remote Maven repository so I can reference it in a CXF project as per this blog post.
I'm sure it could be done manually, but I want an actual maven project so I can make use of the release plugin for tagging etc.
Has anybody got experience with this?
You can use the build helper maven plugin to do this. Here is an indicative code snippet
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${wsdlLocation}/project.wsdl</file>
<type>wsdl</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build.