Having issue building TestG maven project in Jenkins - maven

I have an issue with building TestNG based Maven project via Jenkins. The issue is that if I have less number of test to run (up to 30) everything runs fine, but as soon as I increase the number, the build fails consistently. The problem I see is that, tests doesn't start until all the browser instance are open (eg, browser opens 30 windows first then start execution for suite of 30 tests) and when the test gets complete(not entire test suite), the browser window doesn't close (even after adding driver.quit() method) and it remains open till the TestSuite run is complete.
Below is snippet of my code.
Main Java class:
public class AccountManagement {
public WebDriver driver = new FirefoxDriver();
public WebDriverWait wait = new WebDriverWait(driver, 20);
public void login(String uid, String pass) throws Throwable {
driver.manage().window().maximize();
driver.get(URL);
driver.findElement(By.id("Email")).sendKeys(uid);
driver.findElement(By.id("Password")).sendKeys(pass);
driver.findElement(By.id("btnLogin")).click();
<!-- REST OF THE CODE-->
}
}
Sample test class:
public class TC_AC408 extends AccountManagement {
#Test(retryAnalyzer=Retry.class)
public void accountActionLinks() {
login("auto.admin#test.com", "test#123");
<!-- REST OF THE CODE-->
}
#AfterTest
public void end() {
driver.quit();
}
}
Here is my testng.xml:
<suite name="Smoke Test" preserve-order="true" thread-count="1" verbose="1" parallel="false">
<test name="Accounts">
<classes>
<class name="SmokeTests.TC_AC408"></class>
<class name="SmokeTests.TC_AC409"></class>
<class name="SmokeTests.TC_AC410"></class>
<class name="SmokeTests.TC_AC411"></class>
<class name="SmokeTests.TC_AC412"></class>
<class name="SmokeTests.TC_AC413"></class>
<class name="SmokeTests.TC_AC414"></class>
<class name="SmokeTests.TC_AC416"></class>
</classes>
</test>
<test name="Organization">
<classes>
<class name="SmokeTests.TC_AC470"></class>
<class name="SmokeTests.TC_AC474"></class>
<class name="SmokeTests.TC_AC475"></class>
<class name="SmokeTests.TC_AC477"></class>
<class name="SmokeTests.TC_AC478"></class>
</classes>
</test>
<test name="Project Management">
<classes>
<class name="SmokeTests.TC_AC186"></class>
<class name="SmokeTests.TC_AC191"></class>
<class name="SmokeTests.TC_AC193"></class>
<class name="SmokeTests.TC_AC194"></class>
<class name="SmokeTests.TC_AC195"></class>
<class name="SmokeTests.TC_AC196"></class>
<class name="SmokeTests.TC_AC200"></class>
<class name="SmokeTests.TC_AC785"></class>
<class name="SmokeTests.TC_AC786"></class>
<class name="SmokeTests.TC_AC788"></class>
<class name="SmokeTests.TC_AC790"></class>
</classes>
</test>
<test name="Registration">
<classes>
<class name="SmokeTests.TC_AC381"></class>
<class name="SmokeTests.TC_AC385"></class>
<class name="SmokeTests.TC_AC387"></class>
<class name="SmokeTests.TC_AC398"></class>
<class name="SmokeTests.TC_AC386"></class>
<class name="SmokeTests.TC_AC388"></class>
</classes>
</test>
<test name="Product">
<classes>
<class name="SmokeTests.TC_AC482"></class>
<class name="SmokeTests.TC_AC483"></class>
<class name="SmokeTests.TC_AC486"></class>
<class name="SmokeTests.TC_AC487"></class>
<class name="SmokeTests.TC_AC489"></class>
<class name="SmokeTests.TC_AC491"></class>
<class name="SmokeTests.TC_AC492"></class>
<class name="SmokeTests.TC_AC1777"></class>
<class name="SmokeTests.TC_AC1823"></class>
<class name="SmokeTests.TC_AC1949"></class>
</classes>
</test>
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
<listener class-name="SmokeTests.RetryListener"/>
</listeners>
</suite>
Here is my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress ALL -->
<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 h
ttp://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project_selenium_mvn</groupId>
<artifactId>project_selenium_mvn</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<suiteXmlFile>testng.xml</suiteXmlFile>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
</dependency>
<!-- Adding Selenium dependency -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.48.2</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.40</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<compilerVersion>1.8</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
And below is the error I am getting:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project acutiy_selenium_mvn: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test failed: There was an error in the forked process
[ERROR] org.testng.TestNGException:
[ERROR]
[ERROR] Cannot instantiate class SmokeTests.TC_AC193
[ERROR] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:37)
[ERROR] at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:372)
[ERROR] at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:284)
[ERROR] at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:109)
[ERROR] at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:181)
[ERROR] at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:120)
[JENKINS] Archiving C:\AutomatedTest\project_selenium_mvn\pom.xml to project_selenium_mvn/project_selenium_mvn/1.0-SNAPSHOT/project_selenium_mvn-1.0-SNAPSHOT.pom
[ERROR] at org.testng.TestRunner.initMethods(TestRunner.java:402)
[ERROR] at org.testng.TestRunner.init(TestRunner.java:228)
[ERROR] at org.testng.TestRunner.init(TestRunner.java:198)
[ERROR] at org.testng.TestRunner.<init>(TestRunner.java:147)
[ERROR] at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:525)
[ERROR] at org.testng.SuiteRunner.init(SuiteRunner.java:156)
[ERROR] at org.testng.SuiteRunner.<init>(SuiteRunner.java:110)
[ERROR] at org.testng.TestNG.createSuiteRunner(TestNG.java:1235)
[ERROR] at org.testng.TestNG.createSuiteRunners(TestNG.java:1222)
[ERROR] at org.testng.TestNG.runSuitesLocally(TestNG.java:1074)
[ERROR] at org.testng.TestNG.run(TestNG.java:999)
[ERROR] at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:282)
[ERROR] at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:83)
[ERROR] at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:114)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:286)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:240)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
[ERROR] Caused by: java.lang.reflect.InvocationTargetException
[ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[ERROR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[ERROR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[ERROR] at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
[ERROR] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:28)
[ERROR] ... 22 more
[ERROR] Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7079; process output follows:
[ERROR]
[ERROR] Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'
[ERROR] System info: host: 'WIN-O8VQ2P3P2GD', ip: '172.31.62.242', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79'
[ERROR] Driver info: driver.version: FirefoxDriver
[ERROR] at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:135)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
[ERROR] at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:117)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
[ERROR] at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
[ERROR] at Automation.ProjectManagementPage.<init>(ProjectManagementPage.java:17)
[ERROR] at SmokeTests.TC_AC193.<init>(TC_AC193.java:15)
[ERROR] ... 27 more
[ERROR] Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7079 after 45000 ms. Firefox console output:
[ERROR]
[ERROR] at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:123)
[ERROR] ... 35 more
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

You are creating driver instance whenever for every class inside a test and quitting driver only once per test.Instead of instantiating WebDriver directly in class do it in #BeforeTest. It will ensure only one driver is created per test.
Your class whould look like below after upation.
public class AccountManagement {
public WebDriver driver;
public WebDriverWait wait;
#BeforeTest
public void beforeTest(){
driver = new FirefoxDriver();
wait = new WebDriverWait(driver, 20);
}
public void login(String uid, String pass) throws Throwable {
driver.manage().window().maximize();
driver.get(URL);
driver.findElement(By.id("Email")).sendKeys(uid);
driver.findElement(By.id("Password")).sendKeys(pass);
driver.findElement(By.id("btnLogin")).click();
<!-- REST OF THE CODE-->
}
}

Related

Jlink can't put Derby into the runtime?

UPDATE:
Maybe it is better if I rephrase the question: How to tell Jlink to put the java.sql or derby into the runtime?
Meantime I tried it with a 'jlinkVerbose' option in the pom file and as a result I can see this after a 'mvn clean javafx:jlink':
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AdventureGameEngine 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # AdventureGameEngine ---
[INFO] Deleting /home/sysadmin/NetBeansProjects/AdventureGameEngine/target
[INFO]
[INFO] --- javafx-maven-plugin:0.0.3:jlink (default-cli) # AdventureGameEngine ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 45 resources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /home/sysadmin/NetBeansProjects/AdventureGameEngine/target/classes
[INFO] /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java: /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java uses unchecked or unsafe operations.
[INFO] /home/sysadmin/NetBeansProjects/AdventureGameEngine/src/main/java/com/mycompany/adventuregameengine/FXMLDocumentController.java: Recompile with -Xlint:unchecked for details.
com.mycompany.adventuregameengine file:///home/sysadmin/NetBeansProjects/AdventureGameEngine/target/classes/
java.base file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.base.jmod
java.datatransfer file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.datatransfer.jmod
java.desktop file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.desktop.jmod
java.logging file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.logging.jmod
java.prefs file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.prefs.jmod
java.scripting file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.scripting.jmod
java.sql file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.sql.jmod
java.transaction.xa file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.transaction.xa.jmod
java.xml file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.xml.jmod
javafx.base file:///home/sysadmin/.m2/repository/org/openjfx/javafx-base/11/javafx-base-11-linux.jar
javafx.controls file:///home/sysadmin/.m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-linux.jar
javafx.fxml file:///home/sysadmin/.m2/repository/org/openjfx/javafx-fxml/11/javafx-fxml-11-linux.jar
javafx.graphics file:///home/sysadmin/.m2/repository/org/openjfx/javafx-graphics/11/javafx-graphics-11-linux.jar
jdk.unsupported file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/jdk.unsupported.jmod
Providers:
java.desktop provides java.net.ContentHandlerFactory used by java.base
java.base provides java.nio.file.spi.FileSystemProvider used by java.base
java.desktop provides javax.print.PrintServiceLookup used by java.desktop
java.desktop provides javax.print.StreamPrintServiceFactory used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiDeviceProvider used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiFileReader used by java.desktop
java.desktop provides javax.sound.midi.spi.MidiFileWriter used by java.desktop
java.desktop provides javax.sound.midi.spi.SoundbankReader used by java.desktop
java.desktop provides javax.sound.sampled.spi.AudioFileReader used by java.desktop
java.desktop provides javax.sound.sampled.spi.AudioFileWriter used by java.desktop
java.desktop provides javax.sound.sampled.spi.FormatConversionProvider used by java.desktop
java.desktop provides javax.sound.sampled.spi.MixerProvider used by java.desktop
java.logging provides jdk.internal.logger.DefaultLoggerFinder used by java.base
java.desktop provides sun.datatransfer.DesktopDatatransferService used by java.datatransfer
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.176 s
[INFO] Finished at: 2020-06-17T11:01:49+02:00
[INFO] Final Memory: 22M/84M
[INFO] ------------------------------------------------------------------------
It still gives the 'BUILD SUCCESS' result and despite it says 'java.sql file:///usr/lib/jvm/java-11-openjdk-amd64/jmods/java.sql.jmod
', the java.sql is missing from the 'Providers:' section.
END of UPDATE.
I am working on a game in Java11 + JavaFX. The building tool is Maven. The IDE is Netbeans 11.
It is a modular project.
I use this manual: https://openjfx.io/openjfx-docs/#IDE-NetBeans
The game compiles and runs smoothly, it can create/read/update the Derby DB when I start it in Netbeans via maven by 'clean javafx:run'.
When I want to create the runtime from terminal by 'mvn clean javafx:jlink' I get a 'BUILD SUCCESS' result too.
But when I try to start the launcher by 'target/adventuregame/bin/adventuregamelauncher' I get an error message:
Connection error: java.sql.SQLException: No suitable driver found for jdbc:derby:advDB;create=true
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javafx.fxml.LoadException:
/com.mycompany.adventuregameengine/com/mycompany/adventuregameengine/FXMLDocument.fxml:15
at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.AdventureGame.start(AdventureGame.java:17)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
... 1 more
Caused by: java.lang.NullPointerException
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.DB.<init>(DB.java:46)
at com.mycompany.adventuregameengine#1.0-SNAPSHOT/com.mycompany.adventuregameengine.FXMLDocumentController.<init>(FXMLDocumentController.java:888)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.lang.Class.newInstance(Class.java:584)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
... 17 more
Exception running application com.mycompany.adventuregameengine.AdventureGame
I checked the target/adventuregame/lib/classlist file and it seems to me that the problem is that the jdbc / derby classes are not included. It seems to me that the Jlink can not put the jdbc into the runtime, despite that this manual
https://github.com/openjfx/javafx-maven-plugin#javafxjlink-options
writes that 'The plugin includes by default: --module-path, --add-modules and -classpath options.'
Here is my module-info.java file:
module com.mycompany.adventuregameengine {
requires javafx.controls;
requires javafx.fxml;
requires java.sql;
requires java.desktop;
// requires java.naming;
// requires java.management;
opens com.mycompany.adventuregameengine to javafx.fxml; //java.desktop, java.sql
exports com.mycompany.adventuregameengine;
}
Before I posted I've checked the similar topics here on stackoverflow, and one suggested that including java.naming and java.management could help, I tried it but it doesn't.
Here 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>AdventureGameEngine</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.sql</arg>
</compilerArgs>
<launcher>adventuregamelauncher</launcher>
<jlinkImageName>adventuregame</jlinkImageName>
<mainClass>com.mycompany.adventuregameengine.AdventureGame</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
I tried the 'compilerArgs' section, but it did not help.
Here is the section of my DB file what the error message refers to, but it must be OK since it runs properly via Netbeans, the problem is with the runtime.
public class DB {
final String JDBC_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
final String URL = "jdbc:derby:advDB;create=true";
Connection conn = null;
Statement createStatement = null;
DatabaseMetaData dbmd = null;
public DB(){
try {
conn = DriverManager.getConnection(URL);
System.out.println("There is a connection.");
} catch (SQLException ex) {
System.err.println("Connection error: " + ex);
}
if (conn != null){
try {
createStatement = conn.createStatement(); //create a statement (auto)
} catch (SQLException ex) {
System.err.println("Statement error: " + ex);
}
}
//is the database empty, so the program runs first time?
try {
dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTables(null, "APP", "HERO", null); //capital letter!
if(!rs.next()){
createStatement.execute("create table hero(hp INT, score INT, currentRoom INT, vanBackpack boolean)");
createStatement.execute("create table rooms(description varchar(200), eszakra INT, keletre INT, delre INT, nyugatra INT, fel INT, le INT, id INT)");
createStatement.execute("create table items(roomnumber INT, name varchar(30), description varchar(200), felveheto boolean, vizsgal varchar(200), pozX INT, pozY INT)");
}
} catch (SQLException ex) {
System.err.println("ResultSet getTables/create table error: " + ex);
}
}
If I create a simple sample project on the same way as the above manual suggests, then the runtime runs properly. It seems it can not include only the jdbc/derby.
I thank you in advance for every suggestion to solve this really annoying issue.
Zed

TestNg - Exclude a class(testrunner) via mvn command line

Description :
As a user, I would like to exclude a class ( Test Runner ) when I am running mvn clean test
Pseudo Code :
~ mvn clean verify -Dexclude=SampleTest
How I run my build :
~ mvn clean verify; this triggers a surefire plugin that targets the testng.xml
XML: ( TESTNG )
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Automated UI Tests">
<test name = "Cucumber Test" verbose="2">
<classes>
<class name="com.testrunners.SampleTest"/>
<class name="com.testrunners.Sample2Test"/>
<class name="com.testrunners.Sample3Test"/>
</classes>
</test>
</suite>
I tried grouping ( #Test groups=sample ), but that doesn't seem to work with my case.
Not sure if it matters, but here's a snippet of my test runner.
package com.testrunners;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {
"src/test/java/com/features/",
},
glue = {
"com.stepdefinitions"
},
monochrome = true,
tags = {
"#smoke"
},
plugin = {"pretty",
"html:target/cucumber/sample",
"json:target/cucumber-report/sample/cucumber.json",
"json:target/sample/cucumber.json",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter: target/sample/report.html"}
)
public class SampleTest extends AbstractTestNGCucumberTests {
}
Any help would be appreciated.
Thank you.
From your question, it seems to me you are using maven failsafe plugin for execution.
2 approaches can be used:
From Maven Failsafe plugin:
You can can use excludes property in POM.xml. Please see the configuration to do it. Reference from Maven failsafe official doc plugin.
1 <project>
2 [...]
3 <build>
4 <plugins>
5 <plugin>
6 <groupId>org.apache.maven.plugins</groupId>
7 <artifactId>maven-failsafe-plugin</artifactId>
8 <version>3.0.0-M4</version>
9 <configuration>
10 <excludes>
11 <exclude>**/CircleIT.java</exclude>
12 <exclude>**/SquareIT.java</exclude>
13 </excludes>
14 </configuration>
15 </plugin>
16 </plugins>
17 </build>
18 [...]
19 </project>
You can check this here:
https://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html
This way you can run test cases using
mvn clean verify
From TestNG:
Test classes and class cannot be directly excluded; however, you can exclude classes through groups:
#Test(groups = { "ClassTest1" })
public class Test1 {
public void testMethod1() {
}
public void testMethod2() {
}
}
Then you will define the testng.xml:
<suite>
<test>
<groups>
<run>
<exclude name="ClassTest1"/>
</run>
</groups>
<classes>
<class name="Test1">
</classes>
</test>

Getting test file resource with maven

I'm trying to get a json file resource in order to use it to build a java object. When I try to run my code in the Intellij I don't have any problem, but when I run with mvn test I get the follow error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project cadastur-backend-business: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: There was an error in the forked process
[ERROR] java.lang.RuntimeException: Unable to create test class 'guiaVOTemplate.json'
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.loadClass(DefaultScanResult.java:135)
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:95)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:222)
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:107)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] Caused by: java.lang.ClassNotFoundException: guiaVOTemplate.json
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.loadClass(DefaultScanResult.java:131)
[ERROR] ... 6 more
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :cadastur-backend-business
The project has the follow structure:
Project Structure Image
And above has the code where I'm trying to read the file and convert the json to java object.
package br.gov.mtur.cadastur.builder;
import br.gov.mtur.cadastur.vo.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
public class GuiaVOBuilder {
private GuiaVO guia;
public GuiaVOBuilder() {
this.guia = new GuiaVO();
}
public GuiaVOBuilder comId(Integer id) {
guia.setId(id);
return this;
}
public GuiaVOBuilder comPessoaFisica(PessoaFisicaVO pessoaFisica) {
guia.setPessoaFisica(pessoaFisica);
return this;
}
... //Builder methods
public GuiaVO build(){
return guia;
}
public GuiaVO buildGuiaCompleto() throws IOException {
return new ObjectMapper().readValue(GuiaVOBuilder.class.getResource("/guiaVOTemplate.json"), GuiaVO.class);
}
}
I find my mistake, in the main pom.xml, the maven-surefire-plugin was including all files, so because this I was getting Unable to create test class 'guiaVOTemplate.json'. So I could resolve this putting files with extension .json in the exclude list, as bellow. And my guiaVOTemplate.json remains in src/test/resources.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.json</exclude>
</excludes>
</configuration>
</plugin>
Copy the guiaVOTemplate.json file to src\main\resources and it should work.

org.codehaus.mojo : jaxb2-maven-plugin : 1.6 --> API incompatibility was encountered

when using
jaxb2-maven-plugin from codehaus i get the following problem marker in eclipse
the content of this marker contains the following:
Description Resource Path Location Type
Execution configuration of goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc failed: An API incompatibility was encountered while executing org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc: java.lang.NoSuchMethodError: org.codehaus.plexus.util.DirectoryScanner.setupMatchPatterns()V
-----------------------------------------------------
realm = plugin>org.codehaus.mojo:jaxb2-maven-plugin:1.6
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/develop/maven/repository/org/codehaus/mojo/jaxb2-maven-plugin/1.6/jaxb2-maven-plugin-1.6.jar
urls[1] = file:/C:/develop/maven/repository/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar
urls[2] = file:/C:/develop/maven/repository/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar
urls[3] = file:/C:/develop/maven/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar
urls[4] = file:/C:/develop/maven/repository/org/apache/maven/reporting/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar
urls[5] = file:/C:/develop/maven/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.jar
urls[6] = file:/C:/develop/maven/repository/org/apache/maven/doxia/doxia-logging-api/1.1/doxia-logging-api-1.1.jar
urls[7] = file:/C:/develop/maven/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
urls[8] = file:/C:/develop/maven/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
urls[9] = file:/C:/develop/maven/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
urls[10] = file:/C:/develop/maven/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
urls[11] = file:/C:/develop/maven/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
urls[12] = file:/C:/develop/maven/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
urls[13] = file:/C:/develop/maven/repository/com/sun/xml/bind/jaxb-xjc/2.2.7/jaxb-xjc-2.2.7.jar
urls[14] = file:/C:/develop/maven/repository/com/sun/xml/bind/jaxb-core/2.2.7/jaxb-core-2.2.7.jar
urls[15] = file:/C:/develop/maven/repository/javax/xml/bind/jaxb-api/2.2.7/jaxb-api-2.2.7.jar
urls[16] = file:/C:/develop/maven/repository/com/sun/istack/istack-commons-runtime/2.16/istack-commons-runtime-2.16.jar
urls[17] = file:/C:/develop/maven/repository/com/sun/xml/bind/jaxb-jxc/2.2.7/jaxb-jxc-2.2.7.jar
urls[18] = file:/C:/develop/maven/repository/com/sun/xml/bind/jaxb-impl/2.2.7/jaxb-impl-2.2.7.jar
urls[19] = file:/C:/develop/maven/repository/com/sun/xml/fastinfoset/FastInfoset/1.2.12/FastInfoset-1.2.12.jar
urls[20] = file:/C:/develop/maven/repository/org/codehaus/plexus/plexus-compiler-api/1.9.1/plexus-compiler-api-1.9.1.jar
urls[21] = file:/C:/develop/maven/repository/org/codehaus/plexus/plexus-utils/3.0.16/plexus-utils-3.0.16.jar
Number of foreign imports: 4
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
-----------------------------------------------------
(org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc:configuration:generate-sources) pom.xml
the configuration of the plugin looks like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>data</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<schemaFiles>WebServiceDataSchema.xsd</schemaFiles>
<packageName>my.cool.package.jaxb.data</packageName> <!-- The name of your generated source package -->
<outputDirectory>${project.basedir}/src/gen/java</outputDirectory>
<target>2.1</target>
</configuration>
</execution>
<execution>
<id>configuration</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<schemaFiles>WebServiceConfigurationSchema.xsd</schemaFiles>
<packageName>my.cool.package.jaxb.config</packageName> <!-- The name of your generated source package -->
<outputDirectory>${project.basedir}/src/gen/java</outputDirectory>
<target>2.1</target>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
</plugin>
does anyone have similar problems?
I got a similar error. I solved it using version 1.5 (instead of 1.6) of jaxb2-maven-plugin.
m2e doesn't seem to handle multiple execution blocks with the 1.6 plugin. Command line maven runs these forms correctly, though. If you back up to the 1.5 jaxb plugin, m2e is happy, but the plugin only runs the first of the execution blocks, leaving you with a different broken build.
My solution (so far) is to not use m2e, though that is obviously non-optimal.
I had the same problem. I solved it by updating to the newest Eclipse Luna 4.4 (Java Developer version which includes m2e-wtp, not the Java EE version). I guess it includes a newer version of m2e-wtp which fixes this issue(?!)

Error: The type byte[] cannot be used here. (In Proxy Class of Request Factory)

I have a maven + spring + gwt(2.4.0) project. When I am running mvn gwt:run i get the following error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project star: Compilation failure: Compilation failure:
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\customer\CDocumentProxy.java:[19,8] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\customer\CDocumentProxy.java:[21,25] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\dealer\DealerTargetAgreementProxy.java:[35,36] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\proxies\dealer\DealerTargetAgreementProxy.java:[40,15] error: The type byte[] cannot be used here
[ERROR] C:\Users\radu_chilom\Eclipse Workspaces\Spring3\star\src\main\java\com\base\star\shared\services\dealer\TreeNodeTargetAgreementRequest.java:[29,33] error: Could not find domain method similar to java.util.List<com.base.star.server.dto.dealer.FileTextDTO> getTreeNodeTargetAgreementsList(java.lang.Long)
My CDocumpentProxy.java looks like :
#ProxyFor(value = com.base.star.server.domain.CDocument.class, locator=
com.base.star.server.locators.customer.CDocumentLocator.class)
public interface CDocumentProxy extends EntityProxy {
byte[] getDocument(); //line 19
void setDocument(byte[] document); //line 21
If i build the project with STS 2.9.2 the project builds up. So i think the problem is bad configuration to maven-compiler-plugin.
In my .pom file i have configure maven-compiler-plugin like :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Can't i use byte[] as a return type for a method in a request factory proxy ? I just can't understand the error..
You cannot use arrays in Request Factory: https://developers.google.com/web-toolkit/doc/latest/DevGuideRequestFactory#transportable
That being said, for a byte[] equivalent, I'd rather use a String than a List<Byte>, and GWT emulates String#getBytes for the UTF-8 and ISO-8859-1 charsets.

Resources