HtmlUnitDriver seems to be missing HTTP Components? - java

To get started with Selenium2 and the HtmlUnitDriver I created a test project. As long as I'm using the FirefoxDriver, everything is working perfectly. But as soon as I switch to HtmlUnitDriver I get the following exception. Am I missing some dependencies? I found no documentation telling me which Maven dependencies I have to include, to get this working.
Exception:
java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingClientConnectionManager
at com.gargoylesoftware.htmlunit.HttpWebConnection.createHttpClient(HttpWebConnection.java:536)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getHttpClient(HttpWebConnection.java:500)
at com.gargoylesoftware.htmlunit.HttpWebConnection.setUseInsecureSSL(HttpWebConnection.java:711)
at com.gargoylesoftware.htmlunit.WebClient.setUseInsecureSSL(WebClient.java:1096)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:129)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:172)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:168)
at GoogleTest.testMe(GoogleTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1203)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1128)
at org.testng.TestNG.run(TestNG.java:1036)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingClientConnectionManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 33 more
The project setup, 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>de.test</groupId>
<artifactId>ui-tests</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<selenium.version>2.26.0</selenium.version>
<testNG.version>6.1.1</testNG.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testNG.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
<build>
<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>selenium-maven-plugin</artifactId>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop-selenium</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
</plugins>
</build>
A simple Test class:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class GoogleTest {
private static final String SEARCH_BUTTON = "gbqfb";
public final static String SEARCH_BAR = "gbqfq";
public final static String RESULT_STATS = "resultStats";
#Test
public void testMe() {
// does not work:
// java.lang.NoClassDefFoundError:
// org/apache/http/impl/conn/PoolingClientConnectionManager
HtmlUnitDriver wd = new HtmlUnitDriver();
// FirefoxDriver wd = new FirefoxDriver();
wd.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
wd.get("http://www.google.de/");
WebElement searchBar = wd.findElement(By.id(SEARCH_BAR));
WebElement searchButton = wd.findElement(By.id(SEARCH_BUTTON));
searchBar.click();
searchBar.clear();
searchBar.sendKeys("Selenium Test");
searchButton.click();
WebElement resultsText = wd.findElement(By.id(RESULT_STATS));
String resultsFound = resultsText.getText();
wd.close();
Assert.assertTrue(resultsFound.startsWith("Ungefähr 34.100.000 Ergebnisse"));
}
}
EDIT: fixed missing dependency!

Try moving this block:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>${selenium.version}</version>
</dependency>
from the <dependencyManagement> section into the <dependencies> section of the POM (which is where you have the FireFox driver included).

I got same error and here is how I solved - This error will come if your httpclient.jar, httpcore, httpmime jar files versions are not matching the parent 3rd party classes. I had httpclient-4.0.3.jar versions. Downloaded and added httpclient-4.2.jar to lib of my NetBeans. Similarly added httpcore-4.2.jar and httpmime-4.2.jar. The class executed!!
Download from following repository:
http://mvnrepository.com/artifact/org.apache.httpcomponents

Related

Failed to instantiate Hooks class in Appium Cucumber

This question is my first on stackoverflow. I don't know English so I use translate. Sorry if I did something wrong. I want to work with Appium in Cucumber framework. I have a ready-made framework. However, when I want to run my tests, it gives an error in the Hooks class. It shows the error on the following line in the Hooks class:
private AppiumDriverLocalService appiumServer = AppiumDriverLocalService.buildDefaultService();
I couldn't figure it out. Could you please help?
Thank you from now.
Error message in console:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Step failed
io.cucumber.core.exception.CucumberException: Failed to instantiate class stepDefinitions.Hooks
at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.cacheNewInstance(ObjectFactoryServiceLoader.java:140)
at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.getInstance(ObjectFactoryServiceLoader.java:124)
at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
at io.cucumber.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
at io.cucumber.core.runner.CoreHookDefinition.execute(CoreHookDefinition.java:46)
at io.cucumber.core.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:21)
at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:92)
at io.cucumber.core.runner.TestStep.run(TestStep.java:64)
at io.cucumber.core.runner.TestCase.run(TestCase.java:98)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:71)
at io.cucumber.core.runtime.Runtime.lambda$execute$5(Runtime.java:110)
at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:117)
at io.cucumber.core.runtime.Runtime.lambda$execute$6(Runtime.java:110)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at io.cucumber.core.runtime.Runtime$SameThreadExecutorService.execute(Runtime.java:233)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at io.cucumber.core.runtime.Runtime.lambda$run$2(Runtime.java:86)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.SliceOps$1$1.accept(SliceOps.java:204)
at java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1361)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
at io.cucumber.core.runtime.Runtime.run(Runtime.java:87)
at io.cucumber.core.cli.Main.run(Main.java:92)
at io.cucumber.core.cli.Main.main(Main.java:34)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at io.cucumber.core.runtime.ObjectFactoryServiceLoader$DefaultJavaObjectFactory.cacheNewInstance(ObjectFactoryServiceLoader.java:132)
... 31 more
Caused by: io.appium.java_client.service.local.InvalidServerInstanceException: NodeJS is either not installed or its executable not present in PATH
at io.appium.java_client.service.local.AppiumServiceBuilder.validatePath(AppiumServiceBuilder.java:127)
at io.appium.java_client.service.local.AppiumServiceBuilder.findBinary(AppiumServiceBuilder.java:137)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:180)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:87)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.java:83)
at stepDefinitions.Hooks.<init>(Hooks.java:16)
... 36 more
Hooks class:
package stepDefinitions;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import utils.Driver;
import java.io.IOException;
import java.util.logging.Logger;
public class Hooks {
private AppiumDriverLocalService appiumServer = AppiumDriverLocalService.buildDefaultService();
final Runtime runtime = Runtime.getRuntime();
#Before
public void setUp() {
forceStopAppiumServer();
appiumServer.start();
}
#After
public void tearDown(Scenario scenario) {
final byte[] screenshot = ((TakesScreenshot) Driver.getAppiumDriver()).getScreenshotAs(OutputType.BYTES);
if (scenario.isFailed()) {
scenario.attach(screenshot, "image/png", "screenshots");
}
Driver.quitAppiumDriver();
appiumServer.stop();
}
public void forceStopAppiumServer() {
try {
runtime.exec("killall node");
runtime.exec("pkill -i xcodebuild");
System.out.println("Kill all nodes");
} catch (IOException e) {
e.printStackTrace();
}
}
}
pom.xml file :
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jvm.options>--add-opens java.base/java.lang=ALL-UNNAMED</jvm.options>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.9.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.9.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<skipTests>false</skipTests>
<includes>
<include>**/runners/*TestRunner*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<parallel>classes</parallel>
<forkMode>perthread</forkMode>
<threadCount>4</threadCount>
<reuseForks>false</reuseForks>
<argLine>-Duser.language=en</argLine>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
<useFile>false</useFile>
<includes>
<include>**/runners/*Runner*.java</include>
</includes>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<outputDirectory>${project.build.directory}</outputDirectory>
<inputDirectory>${project.build.directory}</inputDirectory>
<jsonFiles>
<param>**/json-reports/*.json</param>
</jsonFiles><classificationFiles>->
<param>sample.properties</param>
<param>other.properties</param>
</classificationFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
JDK version on my computer 11 :
enter image description here
JDK version in project 1.8 :
enter image description here
I changed the JDK versions, I changed the versions of the dependencies in the pom.xml file, I even formatted the computer but I could not solve the problem.

Error when using the logs in Quarkus with logger jboss

Good afternoon, I have a query, I am starting in Quarkus and I have a problem with the use of logs in it, I am working with a simple service that uses the GET verb, when placing the line of logs it throws me an error of java.lang.NullPointerException. This is my main code:
package com.tmve.subscriber;
import com.tmve.subscriber.repository.FindPrepaidSubscriberICCIDRepository;
import io.agroal.api.AgroalDataSource;
import org.jboss.logging.Logger;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
#Path("/api")
public class FindPrepaidSubscriberICCID {
#Inject
AgroalDataSource defaultDataSource;
Logger log;
FindPrepaidSubscriberICCIDRepository repository= new FindPrepaidSubscriberICCIDRepository();
private final String movil="142910399";
#GET
#Produces(MediaType.TEXT_PLAIN)
public HashMap<String,String> hello() {
HashMap<String,String> map=new HashMap<>();
map=repository.getResources(defaultDataSource,movil);
log.info("movil: "+movil);
return map;
}
}
My application.properties
quarkus.datasource.db-kind=oracle
#quarkus.datasource.jdbc.driver=oracle.jdbc.driver.OracleDriver
#quarkus.datasource.jdbc.driver=io.opentracing.contrib.jdbc.TracingDriver
quarkus.datasource.jdbc.url=jdbc:oracle:thin:#172.xx.2.xxx:1522/IVR
quarkus.datasource.username=${USERNAME_CONNECTION_BD:psp}
quarkus.datasource.password=${PASSWORD_CONNECTION_BD:xxxxxxxxx}
quarkus.http.port=${PORT:8080}
quarkus.log.level=INFO
quarkus.log.category."org.hibernate".level=DEBUG
# Send output to a trace.log file under the /tmp directory
quarkus.log.file.path=/tmp/trace.log
quarkus.log.console.format=%d{HH:mm:ss} %-5p [%c{2.}] (%t) %s%e%n
# Configure a named handler that logs to console
quarkus.log.handler.console."STRUCTURED_LOGGING".format=%e%n
# Configure a named handler that logs to file
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".enable=true
quarkus.log.handler.file."STRUCTURED_LOGGING_FILE".format=%e%n
# Configure the category and link the two named handlers to it
quarkus.log.category."io.quarkus.category".level=INFO
quarkus.log.category."io.quarkus.category".handlers=STRUCTURED_LOGGING,STRUCTURED_LOGGING_FILE
My pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tmve.subscriber</groupId>
<artifactId>find-prepaid-subscriber-iccid</artifactId>
<version>1.0.0</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.10.0.Final</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-oracle</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Error:
14:28:22 ERROR [io.qu.ve.ht.ru.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /api failed, error id: 85c7bf48-6300-4c29-b93a-74f3532832d8-3: org.jboss.resteasy.spi.UnhandledExcepti
on: java.lang.NullPointerException: Cannot invoke "org.jboss.logging.Logger.info(Object)" because "this.log" is null
at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:105)
at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:359)
at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:151)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:91)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:554)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Cannot invoke "org.jboss.logging.Logger.info(Object)" because "this.log" is null
at com.tmve.subscriber.FindPrepaidSubscriberICCID.hello(FindPrepaidSubscriberICCID.java:29)
at com.tmve.subscriber.FindPrepaidSubscriberICCID_Subclass.hello$$superforward1(Unknown Source)
at com.tmve.subscriber.FindPrepaidSubscriberICCID_Subclass$$function$$3.apply(Unknown Source)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:53)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:40)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
at com.tmve.subscriber.FindPrepaidSubscriberICCID_Subclass.hello(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
... 15 more
What could be happening, I don't understand
You are not injecting the logger. You can change the code to:
#Inject
AgroalDataSource defaultDataSource;
#Inject
Logger log;
By the way, Quarkus offers an additional way to get the logger without injection:
package com.example;
import io.quarkus.logging.Log;
class MyService {
public void doSomething() {
Log.info("Simple!");
}
}
#Davide answer is totally right, I just wanted to add that you can use constructor injection:
private final AgroalDataSource ds;
private final Logger log;
public FindPrepaidSubscriberICCID(AgroalDataSource ds, Logger log) {
this.ds = ds;
this.log = log;
}
Constructor injection tends to ease testability (because you can create instances of your objects passing spies or mocks). It also makes sure you do not write to the managed fields (as the fields are final).

ClassNotFoundException when running an executable JAR

I'm using JRAW (A Java Reddit API) and JDA (Java Discord API) with Maven, in order to make a discord bot for a server.
When I run my code in my IDE (IntelliJ IDEA) it works as intended although if I try to compress and run the code in an artifact (more precisely, a .jar file), it throws a ClassNotFoundException (kotlin.Pair).
Log:
java.lang.NoClassDefFoundError: kotlin/Pair
at net.dean.jraw.oauth.OAuthHelper.scriptOAuthData$lib(OAuthHelper.kt:60)
at net.dean.jraw.oauth.OAuthHelper.automatic(OAuthHelper.kt:32)
at net.dean.jraw.oauth.OAuthHelper.automatic$default(OAuthHelper.kt:27)
at net.dean.jraw.oauth.OAuthHelper.automatic(OAuthHelper.kt)
at javaCode.Tools.Reddit.<clinit>(Reddit.java:22)
at javaCode.Listeners.CommandListener.onGuildMessageReceived(CommandListener.java:205)
at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:345)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:64)
at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:152)
at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:97)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:37)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:843)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:739)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:718)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:881)
at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:368)
at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:270)
at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:990)
at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:749)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
Caused by: java.lang.ClassNotFoundException: kotlin.Pair
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more
POM.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>
<packaging>jar</packaging>
<groupId>1.0.0</groupId>
<artifactId>TDCBot</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<kotlin.version>1.3.70</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.jflac</groupId>
<artifactId>jflac-codec</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>3.7.1_386</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>1.3.70</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.3.70</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<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>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Reddit Class Code:
package javaCode.Tools;
import net.dean.jraw.RedditClient;
import net.dean.jraw.http.NetworkAdapter;
import net.dean.jraw.http.OkHttpNetworkAdapter;
import net.dean.jraw.http.UserAgent;
import net.dean.jraw.models.Listing;
import net.dean.jraw.models.Submission;
import net.dean.jraw.models.TimePeriod;
import net.dean.jraw.oauth.Credentials;
import net.dean.jraw.oauth.OAuthHelper;
import net.dean.jraw.pagination.DefaultPaginator;
import net.dv8tion.jda.api.EmbedBuilder;
import java.util.Collections;
import java.util.concurrent.ThreadLocalRandom;
public class Reddit {
private static final Credentials credentials = Credentials.script("[USERNAME]", "[password]", "
[CLIENT_ID]", "[CLIENT_SECRET]");
private static final UserAgent agent = new UserAgent("bot", "javaCode.Tools.Reddit", "v1.0",
"Bot");
private static final NetworkAdapter adapter = new OkHttpNetworkAdapter(agent);
private static final RedditClient client = OAuthHelper.automatic(adapter, credentials);
private static int prev = 0; //Saves the previous post index.
/**
* Returns an embed with a random meme from r/dankmemes or r/memes.
*/
public static EmbedBuilder getRandomMemeEmbed() {
EmbedBuilder builder = new EmbedBuilder();
DefaultPaginator<Submission> paginator = client.subreddits("dankmemes", "memes").posts()
.timePeriod(TimePeriod.MONTH) //Only memes posted this week.
.limit(100)
.build();
Listing<Submission> page = paginator.next(); //Gets a page filled with reddit posts.
int randomNum = ThreadLocalRandom.current().nextInt(0, page.size()); //Generates a randomNumber.
if (randomNum == prev) {
randomNum = ThreadLocalRandom.current().nextInt(0, page.size());
}
prev = randomNum;
Collections.shuffle(page); //randomises the list.
builder.setTitle(page.get(randomNum).getTitle());
if (page.get(randomNum).getThumbnail() != null) { //If the meme has got an image.
builder.setImage(page.get(randomNum).getThumbnail());
} else {
getRandomMemeEmbed(); //Find another one.
}
return builder;
}
}
Hope someone can help me with this.
Thanks.

Elasticsearch - Search fails after upgrading to 2.1.1

I am working on a Java EE 7 WebApplication (running in wildfly 10) using an embedded Elasticsearch.
After upgrading to elasticsearch 2.1.1 searching is not working anymore. (indexing seems to work)
Dependencies that worked:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>5.2.1</version>
</dependency>
Upgraded dependencies:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>5.3.1</version>
</dependency>
After indexing a very basic document (indexing seems to work), searching fails with the following exception:
org.elasticsearch.action.search.SearchPhaseExecutionException : all shards failed [Proxied because : Original exception caused: class java.io.NotSerializableException: org.elasticsearch.action.search.ShardSearchFailure]
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:228)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$1.onFailure(TransportSearchTypeAction.java:174)
at org.elasticsearch.action.ActionListenerResponseHandler.handleException(ActionListenerResponseHandler.java:46)
at org.elasticsearch.transport.local.LocalTransport.handleException(LocalTransport.java:354)
at org.elasticsearch.transport.local.LocalTransport.handlerResponseError(LocalTransport.java:345)
at org.elasticsearch.transport.local.LocalTransport.messageReceived(LocalTransport.java:241)
at org.elasticsearch.transport.local.LocalTransportChannel$2.run(LocalTransportChannel.java:99)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper: _byteSymbolCanonicalizer
at com.fasterxml.jackson.dataformat.smile.SmileFactory._createParser(SmileFactory.java:404)
at com.fasterxml.jackson.dataformat.smile.SmileFactory.createParser(SmileFactory.java:327)
at org.elasticsearch.common.xcontent.smile.SmileXContent.createParser(SmileXContent.java:107)
at org.elasticsearch.common.xcontent.smile.SmileXContent.createParser(SmileXContent.java:113)
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:817)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:651)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:617)
at org.elasticsearch.search.SearchService.executeDfsPhase(SearchService.java:262)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:360)
at org.elasticsearch.search.action.SearchServiceTransportAction$SearchDfsTransportHandler.messageReceived(SearchServiceTransportAction.java:357)
at org.elasticsearch.transport.local.LocalTransport$2.doRun(LocalTransport.java:280)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
This is how my search looks like:
QueryStringQueryBuilder qb = QueryBuilders.queryStringQuery(queryString);
SearchResponse searchResponse = this.client.prepareSearch(INDEX_NAME)
.setTypes(typeName)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(qb)
.setFrom(offset)
.setSize(limit)
.execute()
.actionGet();
I got around that problem by shading elasticsearch dependencies
1. I created a separate maven-module:
<project>
...
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.3.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>shaded.elasticsearch.jackson</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
2. And then used that module as a dependency in my main project
<dependency>
<groupId>drivve</groupId>
<artifactId>elasticsearch-shaded</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>5.5.0</version><!-- be sure to match the version required by elasticsearch-shaded -->
</dependency>
Everything works fine now and is not that hard to managed.
More info on shading es dependencies can be found here.

Cannot find class from jar in maven plugin

I'm making a maven plugin to start, stop and clear a database. I'm using hsqldb for it. I have a class (called ServerStart) to start the database:
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hsqldb.Server;
import org.hsqldb.util.SqlFile;
public static void main(String[] args) {
System.out.println("Starting server...");
createServer();
try {
createADatabase(dbName);
System.out.println("Server started!");
} catch (Exception e) {
e.printStackTrace();
}
}
When I run the main class in Eclipse (right click and run as JavaApplication), it works. But when I try to run it from the cmd line with my mvn command, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hsqldb/Server
at sample.plugin.hello_maven_plugin.ServerStart.createServer(ServerStart
.java:50)
at sample.plugin.hello_maven_plugin.ServerStart.main(ServerStart.java:37)
Caused by: java.lang.ClassNotFoundException: org.hsqldb.Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 2 more
When I run the mvn command, he tries to start ServerClass externally, by doing this:
startOptions = new String[] {"java", "-cp", System.getProperty("user.dir") + "/target/classes/", ServerStart.class.getName()};
new ProcessBuilder(startOptions).start();
I guess I forgot something to add on my pom.xml file, so he includes the hsqldb.jar, but I don't have any idea what. This is my pom file:
<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>sample.plugin</groupId>
<artifactId>hsqldb-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>hsqldb-maven-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hsqldb-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I hope my question is clear enough, and I also hope that someone can help me.
Kind regards,
Walle
a) ??? You define the plugin:
<groupId>sample.plugin</groupId>
<artifactId>hsqldb-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
And reference itself as a plugin in the build section?
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hsqldb-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
That's not how it works! A plugin is meant for other projects, not for itself!
b)
startOptions = new String[] {"java", "-cp", System.getProperty("user.dir") + "/target/classes/", ServerStart.class.getName()};
new ProcessBuilder(startOptions).start();
You are going to need a lot more than target/classes in your classpath. The easiest way to get a proper classpath is to let Maven build it for you:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>build-test-classpath</id>
<phase>generate-test-sources</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<outputFile>${project.build.testOutputDirectory}/cp.txt</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Now you'll find a file named cp.txt on your test classpath which contains the classpath you need. Alternatively, you could just use the contents of System.getProperty("java.class.path").
The groupId in your hsqldb dependency is wrong. I had the same problem. Using the following dependency fixed it.
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.0.0</version>
</dependency>

Categories