I'm getting
org.jboss.arquillian.container.spi.ConfigurationException: jbossHome 'null' must exist
when I try to run my Arquillian test from maven. What should I do?
You can also try to point the required property in arquillian.xml.
For instance in my arquillian.xml:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0" />
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">c:\dev\jboss-eap-6.3\</property>
<property name="serverConfig">standalone-test.xml</property>
<property name="javaVmArguments">-Xrunjdwp:transport=dt_socket,address=5505,server=y,suspend=n -Xmx1024m -XX:MaxPermSize=256m</property>
</configuration>
</container>
</arquillian>
You need to set the JBOSS_HOME environment variable pointing to your Jboss/EAP server before running your integration tests. You do it either from command line:
set JBOSS_HOME=c:\jboss-eap-6.4 (on Windows)
export JBOSS_HOME=/home/jboss-eap-6.4 (on Linux)
or set in your pom.xml file:
<build><plugins><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<environmentVariables>
<JBOSS_HOME>c:\jboss-eap-6.4</JBOSS_HOME>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin></plugins></build>
Related
I'm trying to create a zip file containing, among other stuff of my Java project, a .NET x64 EXE + its manifest + a .NET DLL dependency. It looks like maven assembly plugin corrupts the EXE and the DLL. In fact if I try to execute the file once extracted I get "This app can't run on this PC" (invalid x64 windows application), but if I copy the original files they work normally.
I've tried to google for a solution without success. Am I missing something in maven files?
Plugin declaration in pom.xml is:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/windows.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>${bundle.name}</finalName>
</configuration>
</execution>
</executions>
</plugin>
while windows.xml content is:
<?xml version="1.0"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>windows</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${launcher.dir}/GetMachineId.exe</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>GetMachineId.exe</destName>
</file>
<file>
<source>${launcher.dir}/GetMachineId.exe.config</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>GetMachineId.exe.config</destName>
</file>
<file>
<source>${launcher.dir}/MessagingToolkit.QRCode.dll</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>MessagingToolkit.QRCode.dll</destName>
</file>
</files>
</assembly>
Found the issue.
I was actually using also maven-resources-plugin on ${launcher.dir} with filtering.
Excluding binary files from filtering solved the problem.
UPDATE:
In my pom.xml the maven-resources-plugin was configured like in the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filtering-launcher-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${launcher.dir}</outputDirectory>
<resources>
<resource>
<directory>src/main/launcher</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
With src/main/launcher erroneously containing both text file (that actually required filtering) and binary ones (GetMachineId.exe, GetMachineId.exe.config, MessagingToolkit.QRCore.dll).
In order to solve the problem I've moved those binaries in a different folder (utils) and modified the assembly file like this:
<?xml version="1.0"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>windows</id>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>utils/GetMachineId.exe</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>GetMachineId.exe</destName>
</file>
<file>
<source>utils/GetMachineId.exe.config</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>GetMachineId.exe.config</destName>
</file>
<file>
<source>utils/MessagingToolkit.QRCode.dll</source>
<outputDirectory>bin/utils</outputDirectory>
<destName>MessagingToolkit.QRCode.dll</destName>
</file>
<file>
<source>${launcher.dir}/config.xml</source>
<outputDirectory>bin</outputDirectory>
<destName>config.xml</destName>
</file>
</files>
</assembly>
This way maven-resources-plugin does not process with filtering the binaries, so they do not get corrupted. It looks like the filtering process treats always the files like they are text ones, so it modifies binaries in such a way that prevents their execution.
Another, more recent, strategy could be this one: https://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html
I've found an easier solution modifying the pom.xml just using the excludes and includes tags at resources -> resource.
Example:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.dll</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.dll</include>
</includes>
</resource>
</resources>
I am more a database person than OO (even that I can do). So, I have a database as sql strings, and a lot of queries (also of course the content). I do not, actually, want to "type that down" to an OO model (e.g. class Person int id get/set(int id) etc) - SQL is so quick instead of that. It is a client requirement to use ORM.
Is there a tool that can do that for me? (I would rather write my own parser to do that procedure than to "code" that all). Also, if mybatis can't do it, is there another ORM software that can do so? (any ORM software will do, actually, just that mybatis is said to be lightweight and sql-similar).
You can use Mybatis generator plugin pretty bit simple.
If you are using maven in your project here is basic plugin configuration
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<versionRange>[1.3.2,)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/kp-mybatis-generator.xml</configurationFile>
<outputDirectory>${basedir}/src/main/java</outputDirectory>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
And the generator xml configuration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry location="C:\down\ojdbc6.jar" />
<context id="kpOracleGens" targetRuntime="MyBatis3Simple">
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:#localhost:1521:KPORACLE" userId="******"
password="******">
</jdbcConnection>
<javaModelGenerator targetPackage="com.kp.swasthik.db.domain"
targetProject="MAVEN">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="false" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.kp.swasthik.db.persistence"
targetProject="MAVEN">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.kp.swasthik.db.mapper" targetProject="MAVEN"
implementationPackage="com.kp.swasthik.db.service">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="%KPC%" catalog="*" schema="kprasad">
<property name="useActualColumnNames" value="true" />
</table>
<table tableName="FOO" catalog="*" schema="kprasad">
<property name="useActualColumnNames" value="true" />
</table>
</context>
</generatorConfiguration>
I'd like to use a random port for arquillian.
So in arquillian.xml
I do:
<arquillian>
<container qualifier="tomcat7" default="true">
<configuration>
...
<property name="bindHttpPort">0</property>
...
</configuration>
</container>
</arquillian>
In my unit test:
#ArquillianResource
private URL base;
I hope to have the real port (localPort) used by Apache Tomcat (because yes it start with a random port) but this URL is with 0 port the one from configuration not random one.
So how to have access to this?
Are you using Apache Maven to run such tests ?
Here is how I did. On Maven side I'm using the buildhelper plugin and surefire to define the random port and pass it to tests as a system property
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<phase>initialize</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Port used for Tomcat HTTP connector -->
<tomcat.http.port>${tomcat.http.port}</tomcat.http.port>
</systemProperties>
</configuration>
</plugin>
</plugins>
And then I configured arquillian with
<arquillian>
<container qualifier="tomcat" default="true">
<configuration>
<property name="bindHttpPort">${tomcat.http.port:9090}</property>
</configuration>
</container
</arquillian>
Note : I'm using a default value for the port for when I'm launching the test from my IDE to avoid to have to manually configure it.
HTH
Cheers,
You can use the arquillian-available-port-extension.
Simply add the dependency in your pom
<dependency>
<groupId>com.github.mryan43</groupId>
<artifactId>arquillian-available-port-extension</artifactId>
<version>${arquillian-available-port-extension.version}</version>
</dependency>
and put in your arquillian.xml :
<property name="bindHttpPort">${available.port}</property>
This has the advantage of working both when running in maven and when running in your IDE.
https://github.com/mryan43/arquillian-available-port-extension
I've embedded the following code within my POM:
<plugin name="test">
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<tasks>
<pathconvert targetos="unix" property="project.build.directory.portable">
<path location="${project.build.directory}"/>
</pathconvert>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I then reference ${project.build.directory.portable} from the run project action but it comes back as null. Executing <echo> within the Ant block shows the correct value. What am I doing wrong?
For completeness, the mentioned feature was implemented in the maven-antrun-plugin in October 2010.
The configuration parameter you are looking for is exportAntProperties.
Example of use:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7-SNAPSHOT</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec outputproperty="svnversion"
executable="svnversion">
<arg value=".." />
</exec>
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
</plugin>
As a side note, at the time of this post (2011-10-20), the official plugin documentation didn't have this option documented. To get the help for 'versionXYZ' of the plugin:
mvn help:describe -Dplugin=org.apache.maven.plugins:maven-antrun-plugin:versionXYZ -Ddetail
The version 1.7 of the maven-antrun-plugin worked for me to pass a property from ant to maven (and from mvn to ant). Some sample code that calculates an md5 checksum of a file and later stores it into a property that is accessed by mvn at a later time:
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>ant-md5</id>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="outputDir" value="${project.build.outputDirectory}"/>
<property name="sourceDir" value="${project.build.sourceDirectory}"/>
<checksum file="${sourceDir}/com/blah/db/blah.java" property="blah.md5db"/>
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
The property is accessible in later with ${blah.md5db} in a java file.
From the plugin documentation here:
Try to add the maven prefix, so you have
<path location="${maven.project.build.directory}"/> instead
If that doesn't work, you may need to explictly redefine the property yourself:
<property name="maven.project.build.dir" value="${project.build.directory}"/>
<path location="${maven.project.build.directory}"/>
I don't think you can set a property from Ant that will be visible from Maven. You should write a Mojo.
I have a project of persistence with spring and hibernate built with maven, I'm running the testing using Junit and a test database HSQLDB, when I do a test first initialize the database HSQLDB in server mode, is there some way to make hudson initializes the database, or with maven ?
I'd use DbUnit and the DbUnit Maven Plugin for that. You can use it to Clear database and insert a dataset before test phase and/or to setup data for each test cases (see the Getting Started for JUnit 3, see this blog post for example for JUnit 4).
Another option would be to use the SQL Maven Plugin. The examples section has a configuration that shows how to drop/create a database and schema, then populate it before the test phase, and drop the database after the test phase).
The later approach gives you less control on data setup between tests which is why I prefer DbUnit.
I add the folowing to pom.
<build>
<extensions>
<extension>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</extension>
<extension>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>/src/main/java</outputDirectory>
</component>
</components>
<componentProperties>
<jdk5>true</jdk5>
<export>false</export>
<drop>true</drop>
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<executions>
<execution>
<id>generate-ddl</id>
<phase>process-classes</phase>
<goals>
<!--Genera Esquema-->
<goal>hbm2ddl</goal>
<!--Genera Clases -->
<!-- <goal>hbm2java</goal> -->
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>create-schema</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<srcFiles>
<srcFile>target/hibernate3/sql/schema.sql</srcFile>
</srcFiles>
</configuration>
</execution>
<execution>
<id>drop-db-after-test</id>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<autocommit>true</autocommit>
<sqlCommand>DROP SCHEMA public CASCADE</sqlCommand>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<username>sa</username>
<password></password>
<url>jdbc:hsqldb:file:etc/out/test.db;shutdown=true</url>
<autocommit>true</autocommit>
<skip>${maven.test.skip}</skip>
</configuration>
</plugin>
</plugins>
</build>
and the folowing to my datasource:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" lazy-init="true"
destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:etc/out/test.db;shutdown=true" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
We do that with Maven under Hudson, with a profile that triggers the maven-antrun-plugin in the process-test-resources phase. In our case the maven-antrun-plugin runs a Java class that generates the schema, but of course there are other options. It looks like this:
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-database-schema-new</id>
<phase>process-test-resources</phase>
<configuration>
<tasks>
...
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>