I have a problem with packing my maven selenium project in a standalone jar-file. There is no cp for testclasses despite being in jar file - selenium

I try to pack my maven selenium autotest project into a standalone jar. I use the next main class to start test classes:
public static void main(String[] args) {
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File("pom.xml"));
request.setGoals(Collections.singletonList("install"));
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(System.getenv("MAVEN_HOME")));
try {
invoker.execute(request);
} catch (MavenInvocationException e) {
e.printStackTrace();
}
}
I have no problem with this, the tests are perfectly running from the mainclass. The next step is to pack the project into a jar-file. So I use maven-jar-plugin and maven-assembly-plugin for that purpose:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>common.MainClass</mainClass>
</manifest>
</archive>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/test/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
and my assembly:
<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>test-jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<!-- we're creating the test-jar as an attachement -->
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.class</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
I manage to pack both common and test classes in a jar-file. I manually put the pom file and the testing file in the same directory as the jar file, so I have no trouble with starting the project. But the tests don't run, because the test-classes are not found, despite being inside the project.
I will be very appreciative if anyone gives me a clue about what I do wrong.
P.S. I put here a refer to my project: https://bitbucket.org/Max1203/donatiton-script.git

Test class not found may be misconfiguration
Can you reimport maven dependencies it will solve
Maven cycle-Reload All maven projects

In case anybody needs the answer. Just change the code in MainClass to the next one:
TestNG testNG = new TestNG();
testNG.setTestSuites(Arrays.asList("testng.xml"));
testNG.setPreserveOrder(true);
testNG.run();
It is gonna solve the problem.

Related

How using parameter "-Dsurefire.skipAfterFailureCount=1" to skip tests after the first crash

I have a Maven test project. In which I use context-related tests. I use maven-surefire-plugin to run tests.
I need to make the test stop running after the first failed test. I found a way to do this through -Dsurefire.skipAfterFailureCount=1, but it doesn't work. Maybe I'm doing something wrong? Below is my pom.xml:
<properties>
<selenide.version>5.3.0</selenide.version>
<junit.jupiter.version>5.5.1</junit.jupiter.version>
<selenium.java.version>3.141.59</selenium.java.version>
<allure.junit5.version>2.12.1</allure.junit5.version>
<aspectj.version>1.8.10</aspectj.version>
<maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
<junit.platform.launcher>1.5.2</junit.platform.launcher>
<junit.jupiter.engine>5.5.2</junit.jupiter.engine>
<junit.vintage.engine>5.5.2</junit.vintage.engine>
<allure.maven.version>2.10.0</allure.maven.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
-Dsurefire.skipAfterFailureCount=1
</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Also I tried this option:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
<argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>
<systemProperties>
<property>
<name>allure.results.directory</name>
<value>${project.build.directory}/allure-results</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Does anyone know how to solve this problem? Why is my code not working? Did I make a mistake somewhere?
This works in jUnit 4. I don't know why your code isn't working, but maybe this will help.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
</plugin>
</plugins>
</build>
add the plugin.
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<type>maven-plugin</type>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipAfterFailureCount>1</skipAfterFailureCount>
</configuration>
</plugin>
</plugins>
don't use #TestMethodOrder in your code.
import java.util.HashMap;
import jp.co.nisshinsci.saas.framework.dto.Member;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
// #TestMethodOrder(MethodOrderer.DisplayName.class)
public class test {
#Test
void test01() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
#Test
void test02() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
#Test
void test03() throws Exception {
HashMap stringHashMap = new HashMap();
long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
}
}
test by maven, not by Intellij Idea.

Has anyone used proguard to obfuscation of .war file and succeed?

Has anyone used proguard to obfuscation of .war file and succeed? if yes then please tell me the exact steps to obfuscation of war.
I am not finding any ideal document on web for my requirement.
I have created my web application in spring boot and jsp.
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>5.3.3</proguardVersion>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}.jar</outjar>
<obfuscate>true</obfuscate>
<options>
<option>-dontshrink</option>
<option>-dontoptimize</option>
<option>-adaptclassstrings</option>
<option>-keepattributes
Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
<option>-keepnames interface **</option>
<option>-keepparameternames</option>
<option>-keep class
!com.slm.proguard.example.spring.boot.domain.**
{ *; }</option>
<option>-keep class com.slm.proguard.example.spring.boot.service {
*; }</option>
<option>-keep interface * extends * { *; }</option>
<option>-keepclassmembers class * {
#org.springframework.beans.factory.annotation.Autowired *;
#org.springframework.beans.factory.annotation.Value *;
}
</option>
</options>
<libs>
Include main JAVA library required.
<lib>${java.home}/lib/rt.jar</lib>
Include crypto JAVA library if necessary.
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.3.3</version>
</dependency>
</dependencies>
</plugin>
I had problems with a JAR created by proguard, it seemed ok but tomcat didn't find anything inside. After a long search I found that unzipping and re-zipping with an ant-task the exact same file make a working one.
Here is the added configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>fixzip</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- ******************** ********* ******************** -->
<!-- ******************** IMPORTANT ******************** -->
<!-- ******************** ********* ******************** -->
<!-- It may seems strange to unzip and re-jar the file -->
<!-- but the JAR made by Proguard is somehow not readable -->
<!-- by Tomcat and Spring beans aren't recognized -->
<!-- *************************************************** -->
<!-- Fixing JAR. -->
<move file="target/${project.build.finalName}/WEB-INF/lib/${project.artifactId}-${project.version}.jar"
tofile="target/${project.artifactId}-${project.version}_proguard_base.jar" />
<jar destfile="target/${project.build.finalName}/WEB-INF/lib/${project.artifactId}-${project.version}.jar">
<zipfileset
src="target/${project.artifactId}-${project.version}_proguard_base.jar"
includes="**/*.*" />
</jar>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

error in the pom file netbeans 8

I have this error:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project weka-dev: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
Following is my POM:
<?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>nz.ac.waikato.cms.weka</groupId>
<artifactId>weka-dev</artifactId>
<version>3.7.14-SNAPSHOT</version><!-- weka-version -->
<packaging>jar</packaging>
<name>weka-dev</name>
<description>The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This version represents the developer version, the
"bleeding edge" of development, you could say. New functionality gets added
to this version.
</description>
<url>http://www.cms.waikato.ac.nz/ml/weka/</url>
<organization>
<name>University of Waikato, Hamilton, NZ</name>
<url>http://www.waikato.ac.nz/</url>
</organization>
<licenses>
<license>
<name>GNU General Public License 3</name>
<url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>wekateam</id>
<name>The WEKA Team</name>
<email>wekalist#list.waikato.ac.nz</email>
</developer>
</developers>
<mailingLists>
<mailingList>
<name>wekalist</name>
<subscribe>https://list.waikato.ac.nz/mailman/listinfo/wekalist</subscribe>
<unsubscribe>https://list.waikato.ac.nz/mailman/listinfo/wekalist</unsubscribe>
<archive>https://list.waikato.ac.nz/mailman/htdig/wekalist/</archive>
</mailingList>
</mailingLists>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<scm>
<connection>scm:svn:https://svn.cms.waikato.ac.nz/svn/weka/trunk/weka</connection>
<developerConnection>scm:svn:https://svn.cms.waikato.ac.nz/svn/weka/trunk/weka</developerConnection>
<url>https://svn.cms.waikato.ac.nz/svn/weka/trunk/weka</url>
</scm>
<profiles>
<profile>
<id>release-sign-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- used for skipping tests -->
<id>no-tests</id>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
<artifactId>java-cup-11b</artifactId>
<version>2015.03.26</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
<artifactId>java-cup-11b-runtime</artifactId>
<version>2015.03.26</version>
</dependency>
<dependency>
<groupId>nz.ac.waikato.cms.weka.thirdparty</groupId>
<artifactId>bounce</artifactId>
<version>0.18</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.10</version>
<optional>true</optional>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<weka.main.class>weka.gui.GUIChooser</weka.main.class>
</properties>
<build>
<directory>dist</directory>
<outputDirectory>build/classes</outputDirectory>
<testOutputDirectory>build/testcases</testOutputDirectory>
<resources>
<resource>
<targetPath>${project.build.outputDirectory}</targetPath>
<directory>${project.build.sourceDirectory}</directory>
<includes>
<include>**/*.arff</include>
<include>**/*.cost</include>
<include>**/*.cup</include>
<include>**/*.default</include>
<include>**/*.excludes</include>
<include>**/*.flex</include>
<include>**/*.gif</include>
<include>**/*.icns</include>
<include>**/*.ico</include>
<include>**/*.jflex</include>
<include>**/*.jpeg</include>
<include>**/*.jpg</include>
<include>**/*.kfml</include>
<include>**/*.matrix</include>
<include>**/*.png</include>
<include>**/*.properties</include>
<include>**/*.props</include>
<include>**/*.txt</include>
<include>**/*.xml</include>
<include>**/DatabaseUtils.props.*</include>
<include>weka/gui/beans/README</include>
</includes>
</resource>
<resource>
<targetPath>${project.build.testOutputDirectory}</targetPath>
<directory>${project.build.testSourceDirectory}</directory>
<includes>
<include>**/*.arff</include>
<include>**/*.cost</include>
<include>**/*.cup</include>
<include>**/*.default</include>
<include>**/*.excludes</include>
<include>**/*.flex</include>
<include>**/*.gif</include>
<include>**/*.icns</include>
<include>**/*.ico</include>
<include>**/*.jflex</include>
<include>**/*.jpeg</include>
<include>**/*.jpg</include>
<include>**/*.kfml</include>
<include>**/*.matrix</include>
<include>**/*.png</include>
<include>**/*.properties</include>
<include>**/*.props</include>
<include>**/*.txt</include>
<include>**/*.xml</include>
<include>**/DatabaseUtils.props.*</include>
<include>weka/gui/beans/README</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<disableXmlReport>true</disableXmlReport>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemPropertyVariables>
<weka.test.Regression.root>src/test/resources/wekarefs</weka.test.Regression.root>
<weka.test.maventest>true</weka.test.maventest>
<user.timezone>Pacific/Auckland</user.timezone>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
<configuration>
<tagBase>https://svn.cms.waikato.ac.nz/svn/weka/tags</tagBase>
<useReleaseProfile>false</useReleaseProfile>
<!-- tests are performed with the ant build file, hence skipped here. -->
<preparationGoals>clean verify -P no-tests</preparationGoals>
<goals>deploy -P no-tests</goals>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>.</directory>
<includes>
<include>**/*~</include>
<include>**/.attach_pid*</include>
<include>**/hs_err_pid*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<mainClass>${weka.main.class}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludeResources>true</excludeResources>
</configuration>
</execution>
<execution>
<id>attach-test-sources</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<maxmemory>256m</maxmemory>
<subpackages>weka:org</subpackages>
<show>public</show>
<outputDirectory>${project.basedir}/doc</outputDirectory>
<!-- when using Java 8, use this setting to avoid overly strict javadoclet -->
<!--additionalparam>-Xdoclint:none</additionalparam-->
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Commons Logging - ClassNotFoundException

For whatever reason I can't seem to run my jar file without receiving a ClassNotFound Exception. I am new to Maven, so I believe the issue could be caused by my POM.XML file. Allow me to elaborate. I have isolated the problem to an example HelloWorld log.
package com;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class HelloLog {
public static Log log = LogFactory.getLog(HelloLog.class);
public static void main(String[] args){
log.info("Hello World!");
}
}
I have also simplified my pom.xml to only two dependencies.
<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>--MygroupId--</groupId>
<artifactId>--MyArtID--</artifactId>
<version>--MyVer--</version>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib</classpathPrefix>
<mainClass>com.HelloLog</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<compilerVersion>1.6</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/dependency-jars/
</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.5.1,)
</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I run the HelloLog class in Eclipse all is good and I get the expected output. However, when I execute java -jar on the Jar file I receive the ClasNotFoundException on LogFactory at line 7. The jar file is accompanied in the target folder with the dependency-jars folder. The dependency-jars folder holds these two dependencies.
Found the problem, it was Maven related. Hadn't noticed my classpathPrefix was set as lib. Where as I outputted the dependencies to dependency-jars.

Start hsqldb server through maven exec plugin failed

I try to start an hsqldb server for developpement use. I had hsqldb dependency :
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.4</version>
</dependency>
I had in build exec-maven-build :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.hsqldb.server.Server</mainClass>
<arguments>
<argument>--database.0 file:target/monitoring</argument>
</arguments>
</configuration>
</plugin>
And I launch mvn exec:java, server starts and i have this error :
[Server#6e9770a3]: [Thread[org.hsqldb.server.Server.main(),5,org.hsqldb.server.Server]]: Failed to set properties
org.hsqldb.HsqlException: no valid database paths: maformed database enumerator: server.database.0 mem:monitoring
I search through the code, what this error means, and i found in hsqldb code the error on this page => http://hsqldb.svn.sourceforge.net/viewvc/hsqldb/base/tags/2.2.5/src/org/hsqldb/server/Server.java?revision=4369&view=markup
private IntKeyHashMap getDBNameArray() {
final String prefix = ServerProperties.sc_key_dbname + ".";
final int prefixLen = prefix.length();
IntKeyHashMap idToAliasMap = new IntKeyHashMap();
Enumeration en = serverProperties.propertyNames();
for (; en.hasMoreElements(); ) {
String key = (String) en.nextElement();
if (!key.startsWith(prefix)) {
continue;
}
int dbNumber;
try {
dbNumber = Integer.parseInt(key.substring(prefixLen));
} catch (NumberFormatException e1) {
**printWithThread("maformed database enumerator: " + key);**
continue;
}
String alias = serverProperties.getProperty(key).toLowerCase();
if (!aliasSet.add(alias)) {
printWithThread("duplicate alias: " + alias);
}
Object existing = idToAliasMap.put(dbNumber, alias);
if (existing != null) {
printWithThread("duplicate database enumerator: " + key);
}
}
return idToAliasMap;
}
So hsqldb use as a key all argument : "no valid database paths: maformed database enumerator: server.database.0 mem:monitoring"
So it looks like a bug, or did I make something wrong ?
OK i found the solution, I changed the way i give arguments to exec maven plugin.
from this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.hsqldb.server.Server</mainClass>
<arguments>
<argument>--database.0 file:target/monitoring</argument>
</arguments>
</configuration>
</plugin>
to this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.hsqldb.server.Server</mainClass>
<arguments>
<argument>--database.0</argument>
<argument>file:target/monitoring</argument>
</arguments>
</configuration>
</plugin>
And it works
I changed the way i pass arguments to exec maven plugin
from this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.hsqldb.server.Server</mainClass>
<arguments>
<argument>--database.0 file:target/monitoring</argument>
</arguments>
</configuration>
</plugin>
to this :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.hsqldb.server.Server</mainClass>
<arguments>
<argument>--database.0</argument>
<argument>file:target/monitoring</argument>
</arguments>
</configuration>
</plugin>
And it works
I found out that in case you need to start HSQL in server mode from maven and continue running your integration tests you have to use maven-antrun-plugin and ant Java task as exec-maven-plugin doesn't support forked mode:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<dependencies>
</dependencies>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<target>
<property name="test_classpath" refid="maven.test.classpath" />
<java classname="org.hsqldb.server.Server"
fork="yes" spawn="yes">
<arg
line="--database.0 mem:test --dbname.0 test" />
<classpath>
<pathelement path="${test_classpath}" />
</classpath>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
it assumes your hsqldb dependency is of test scope.