Howto test with arquillian and Thorntail without #DefaultDeployment - junit5

Thorntail doc says to use #DefaultDeployment in order to test a class. I don't want to use this because it generates a deployment which includes a persistence.xml which describes a connection to a production database. In the context of a test the connection fails then the test can't be driven.
So I tried to use #Deployment with the ShrinkWrap tool.
#RunWith(Arquillian.class)
//#DefaultDeployment
//#RunAsClient
public class ApplicationScopedForTestTest {
#Deployment(testable = true)
public static Archive createDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "jdbManagerTEST.jar");
archive.addPackages(true, "org.avm.business.jdb_manager");
archive.addAsResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
archive.addAsResource("META-INF/persistence-test.xml", "project-tests.yml");
// print all included packages
System.out.println(archive.toString(true));
return archive;
}
Then, next lines :
#Inject
ApplicationScopedForTest services;
#Test
public void print() {
assertNotNull(services);
}
No way ; always a java.lang.RuntimeException: Could not inject members ; the root cause is Original exception caused: class java.lang.ClassNotFoundException...
services is never known, CDI fails.
All my classes are included in my archive (system.out tells me so). It's like weld or something is missing to make it work, but what and how?
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/maven-v4_0_0.xsd">
<parent>
<groupId>org.avm.business</groupId>
<artifactId>geo3d-services</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jdbManager</artifactId>
<name>Managing JDB</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>datasources</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jpa</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>cdi</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.microprofile.openapi/microprofile-openapi-api -->
<dependency>
<groupId>org.eclipse.microprofile.openapi</groupId>
<artifactId>microprofile-openapi-api</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs</artifactId>
</dependency>
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>jaxrs-multipart</artifactId>
</dependency>
<!-- TESTS -->
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>arquillian</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.arquillian.junit/arquillian-junit-container -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.5.0.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
and parent 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.avm.business</groupId>
<artifactId>geo3d-services</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<version.thorntail>2.5.0.Final</version.thorntail>
<version.arquillian>1.5.0.Final</version.arquillian>
<version.microprofile>3.2</version.microprofile>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openapi.base.package>org.avm.business.openapi</openapi.base.package>
<!-- <swagger-core-version>2.0.10</swagger-core-version> -->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>${version.microprofile}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.arquillian/arquillian-bom -->
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>bom</artifactId>
<version>${version.thorntail}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>io.thorntail</groupId>
<artifactId>thorntail-maven-plugin</artifactId>
<version>${version.thorntail}</version>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>install</phase>
<configuration>
<target>
<copy file="target/${project.artifactId}-thorntail.jar"
todir="../" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Output:
mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< org.avm.business:jdbManager >---------------------
[INFO] Building Managing JDB 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # jdbManager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # jdbManager ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # jdbManager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # jdbManager ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # jdbManager ---
[INFO] Surefire report directory: /home/lbroque/Projects/GEO3D-services/docker/services/jdbManager/workspace/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.avm.business.jdb_manager.jdb.parser.services.ApplicationScopedForTestTest
jdbManagerTEST.jar:
/org/
/org/avm/
/org/avm/business/
/org/avm/business/jdb_manager/
/org/avm/business/jdb_manager/jdb/
/org/avm/business/jdb_manager/jdb/parser/
/org/avm/business/jdb_manager/jdb/parser/services/
/org/avm/business/jdb_manager/jdb/parser/services/ApplicationScopedForTestTest.class
(...)
/beans.xml
/project-tests.yml
Resolving 0 out of 625 artifacts
Fri Nov 22 16:13:45 CET 2019 INFO [org.wildfly.swarm.bootstrap] (main) Dependencies not bundled; resolving from M2REPO.
2019-11-22 16:13:48,285 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Remoting - STABLE io.thorntail:remoting:2.5.0.Final
2019-11-22 16:13:48,292 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Datasources - STABLE io.thorntail:datasources:2.5.0.Final
2019-11-22 16:13:48,292 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: CDI Configuration - STABLE io.thorntail:cdi-config:2.5.0.Final
2019-11-22 16:13:48,292 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Transactions - STABLE io.thorntail:transactions:2.5.0.Final
2019-11-22 16:13:48,292 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: JMX - STABLE io.thorntail:jmx:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: JPA - STABLE io.thorntail:jpa:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: JAX-RS - STABLE io.thorntail:jaxrs:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Logging - STABLE io.thorntail:logging:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Infinispan - STABLE io.thorntail:infinispan:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: JCA - STABLE io.thorntail:jca:2.5.0.Final
2019-11-22 16:13:48,293 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: CDI - STABLE io.thorntail:cdi:2.5.0.Final
2019-11-22 16:13:48,294 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Arquillian - STABLE io.thorntail:arquillian:2.5.0.Final
2019-11-22 16:13:48,294 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Bean Validation - STABLE io.thorntail:bean-validation:2.5.0.Final
2019-11-22 16:13:48,294 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Undertow - STABLE io.thorntail:undertow:2.5.0.Final
2019-11-22 16:13:48,294 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: Elytron - STABLE io.thorntail:elytron:2.5.0.Final
2019-11-22 16:13:48,294 INFO [org.wildfly.swarm] (main) THORN0013: Installed fraction: JAX-RS with Multipart - STABLE io.thorntail:jaxrs-multipart:2.5.0.Final
2019-11-22 16:13:49,438 INFO [org.wildfly.swarm.datasources] (main) THORN1003: Auto-detected JDBC driver for postgresql
2019-11-22 16:13:49,499 INFO [org.wildfly.swarm.jmx] (main) JMX not configured for remote access
2019-11-22 16:13:49,866 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.5.Final
2019-11-22 16:13:49,872 INFO [org.jboss.threads] (main) JBoss Threads version 2.3.2.Final
2019-11-22 16:13:49,951 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Thorntail 2.5.0.Final (WildFly Core 7.0.0.Final) starting
2019-11-22 16:13:49,989 INFO [org.wildfly.swarm] (MSC service thread 1-2) THORN0019: Install MSC service for command line args: []
2019-11-22 16:13:50,107 INFO [org.wildfly.swarm.arquillian.daemon.server.Server] (MSC service thread 1-3) Arquillian Daemon server started on localhost:12345
2019-11-22 16:13:50,425 INFO [org.wildfly.security] (ServerService Thread Pool -- 12) ELY00001: WildFly Elytron version 1.7.0.Final
2019-11-22 16:13:50,747 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 20) WFLYNAM0001: Activating Naming Subsystem
2019-11-22 16:13:50,748 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 23) WFLYCLINF0001: Activating Infinispan subsystem.
2019-11-22 16:13:50,750 INFO [org.jboss.as.security] (ServerService Thread Pool -- 22) WFLYSEC0002: Activating Security Subsystem
2019-11-22 16:13:50,754 INFO [org.jboss.as.jaxrs] (ServerService Thread Pool -- 24) WFLYRS0016: RESTEasy version 3.8.1.Final
2019-11-22 16:13:50,757 INFO [org.jboss.as.security] (MSC service thread 1-7) WFLYSEC0001: Current PicketBox version=5.0.3.Final
2019-11-22 16:13:50,769 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 34) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.
2019-11-22 16:13:50,782 INFO [org.jboss.as.naming] (MSC service thread 1-2) WFLYNAM0003: Starting Naming Service
2019-11-22 16:13:50,797 INFO [org.jboss.as.connector] (MSC service thread 1-3) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.11.Final)
2019-11-22 16:13:50,804 INFO [org.xnio] (ServerService Thread Pool -- 36) XNIO version 3.6.5.Final
2019-11-22 16:13:50,841 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0003: Undertow 2.0.15.Final starting
2019-11-22 16:13:50,858 INFO [org.xnio.nio] (ServerService Thread Pool -- 36) XNIO NIO Implementation Version 3.6.5.Final
2019-11-22 16:13:50,860 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 42.2)
2019-11-22 16:13:50,863 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = postgresql
2019-11-22 16:13:50,879 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 36) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
2019-11-22 16:13:50,929 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0010: Unbound data source [java:jboss/datasources/ExampleDS]
2019-11-22 16:13:50,971 INFO [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 5.0.8.Final
2019-11-22 16:13:50,993 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0012: Started server default-server.
2019-11-22 16:13:51,040 INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006: Undertow HTTP listener default listening on 0.0.0.0:8080
2019-11-22 16:13:51,083 WARN [org.jboss.as.remoting] (MSC service thread 1-5) ****** All authentication is ANONYMOUS for org.jboss.as.remoting.RemotingHttpUpgradeService
2019-11-22 16:13:51,149 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
2019-11-22 16:13:51,250 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-3) ISPN000128: Infinispan version: Infinispan 'Infinity Minus ONE +2' 9.4.3.Final
2019-11-22 16:13:51,525 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 37) WFLYCLINF0002: Started default cache from server container
2019-11-22 16:13:51,525 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0002: Started passivation cache from web container
2019-11-22 16:13:51,584 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
2019-11-22 16:13:51,586 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: Thorntail 2.5.0.Final (WildFly Core 7.0.0.Final) started in 1748ms - Started 253 of 382 services (231 services are lazy, passive or on-demand)
2019-11-22 16:13:52,062 INFO [org.wildfly.swarm.runtime.deployer] (main) deploying jdbManagerTEST.jar
2019-11-22 16:13:52,085 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "jdbManagerTEST.jar" (runtime-name: "jdbManagerTEST.jar")
2019-11-22 16:13:52,583 WARN [org.jboss.as.dependency.private] (MSC service thread 1-1) WFLYSRV0018: Deployment "deployment.jdbManagerTEST.jar" is using a private module ("org.infinispan") which may be changed or removed in future versions without notice.
2019-11-22 16:13:52,584 WARN [org.jboss.as.dependency.private] (MSC service thread 1-1) WFLYSRV0018: Deployment "deployment.jdbManagerTEST.jar" is using a private module ("org.infinispan.commons") which may be changed or removed in future versions without notice.
2019-11-22 16:13:52,585 WARN [org.jboss.as.dependency.private] (MSC service thread 1-1) WFLYSRV0018: Deployment "deployment.jdbManagerTEST.jar" is using a private module ("org.jboss.ironjacamar.jdbcadapters") which may be changed or removed in future versions without notice.
2019-11-22 16:13:52,585 WARN [org.jboss.as.dependency.private] (MSC service thread 1-1) WFLYSRV0018: Deployment "deployment.jdbManagerTEST.jar" is using a private module ("org.jboss.jts") which may be changed or removed in future versions without notice.
2019-11-22 16:13:52,600 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) WFLYWELD0003: Processing weld deployment jdbManagerTEST.jar
2019-11-22 16:13:52,642 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 6.0.14.Final
2019-11-22 16:13:52,778 INFO [org.jboss.weld.Version] (MSC service thread 1-4) WELD-000900: 3.0.5 (Final)
2019-11-22 16:13:53,252 INFO [org.jboss.as.server] (main) WFLYSRV0010: Deployed "jdbManagerTEST.jar" (runtime-name : "jdbManagerTEST.jar")
2019-11-22 16:13:53,258 INFO [org.wildfly.swarm] (main) THORN99999: Thorntail is Ready
Sorry for the length of the post; I tried to put everything useful.

The problem is on this line:
archive.addAsResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
You're adding a beans.xml file to the root of the JAR, as can also be seen in the log you print:
/beans.xml
This is wrong. In case of a JAR, beans.xml should be present in META-INF. See this answer https://stackoverflow.com/a/9250108/742081 for where beans.xml should be located. To put it into META-INF in a JAR, you should use archive.addAsManifestResource(...).

Related

Connecting GlassFish/Payara to MySQL 8.x

I had a maven JSF/JPA web application that was connected to MySQL 5.x developed using Netbeans 12. The application was running fine until I updated the MySQL version from 5.x to 8.x. Since that update, I can not configure the database to connect to the JSF application. The connection to MySQL 8.x is working within Netbeans, but not working when deploying the application.
The current configuration include EclipseLink 2.7.7, MySQL 8.0.23, and GlassFish 5(5.0.1) / Payara 5(5.2021.1). It is not possible to make a successful connection to MySQL. I also failed to establish connection inside JDBS Connection Pool of GlassFish and Payara admin consoles. Can someone please direct me to a source where MySQL version 8 is linked to Payara or GlassFish?
The error displayed in the Payara admin console is as follows.
An error has occurred Ping Connection Pool failed for pooConnection.
Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Please check the server.log for more details.
The log file contains the following.
[javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service] [tid: _ThreadID=161 _ThreadName=admin-thread-pool::admin-listener(3)] [timeMillis: 1613549343463] [levelValue: 900] [[
RAR8054: Exception while creating an unpooled [test] connection for pool [ pooConnection ], Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.]]
[2021-02-17T13:39:03.472+0530] [Payara 5.2021.1] [SEVERE] [] [org.glassfish.admingui] [tid: _ThreadID=139 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1613549343472] [levelValue: 1000] [[
RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=pooConnection}']]
In order to connect to Payara Server, the only effective way I found was creating a Connection Pool directly in the Domain Admin Console.
It may seem a long way now, but after completing it will become second nature:
Download MySQL8 Java Connector available at https://dev.mysql.com/downloads/connector/j/
and unzip to any folder:
It will extract to something like:
mysql-connector-java-8.0.23 2/mysql-connector-java-8.0.23.jar
1) Make sure you have Payara Server up and running:
cd PATH_TO_PAYARA/bin
2) Start/Restart it
./asadmin start-domain
Note: This will start domain1 by default
3) Install the MySQL8 Connector
./asadmin add-library PATH_TO_MYSQL_CONNECTOR.jar
4) (required) Restart Payara
./asadmin restart-domain
5) Access Admin Console at http://localhost:4848/common/index.jsf
6) In the sidebar navigate to "JDBC" -> "JDBC Connection Pools" menu
7) From there, click "New" to add new Connection Pool
You can have as many as you want. So if you have tried before, you may keep your pools there.
8) In: New JDBC Connection Pool (Step 1 of 2)
Pool Name: MySQL8Pool (or whatever you want)
Resource Type: javax.sql.DataSource
Database Driver Vendor: MySQL8
Click "Next"
9) Scroll down to "Adicional Properties"
Select all and "Delete Properties"
10) Add 6 Properties with the keys/values as:
DatabaseName YOUR_DB_NAME
User YOUR_DB_USER
Password YOUR_DB_PASSWORD
ServerName localhost
PortNumber 3306
UseSSL false
Click "Save"
11) In the sidebar navigate to "JDBC" -> "JDBC Resources" menu
12) From there, click "New" to add new JDBC Resource
And fill:
JNDI Name: jdbc/MySQL8App
PoolName: MySQL8Pool
Click "Save"
From now own I assume you are using Maven.
13) In you pom.xml make sure you have Eclipse Persistence
In you tag:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.asm</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.jpql</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.1</version>
</dependency>
14) Create a persistence unit in
In persistence.xml file:
<persistence-unit name="mysql8PU" transaction-type="JTA">
<jta-data-source>jdbc/MySQL8App</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<!--properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create OR create OR complete remove this line"/-->
</properties>
</persistence-unit>
Note that in jta-data-source it points to jdbc/MySQL8App and from now own it can be used any where in your code so that after built Payara is able to now we injected it.
PersistenceService.java
package com.your.package.services
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#ApplicationScoped
public class PersistenceService {
#PersistenceContext(unitName = "mysql8PU")
EntityManager entityManager;
}
Now rebuild and rerun you project and everything should be fine!
Configure your connecion just in four steps:
Copy Mysql JDBC driver JAR to $PAYARA_HOME/glassfish/domains/$YOUR_DOMAIN/lib/ e. g.
cp mysql-connector-java-8.0.22.jar /opt/payara5/glassfish/domains/domain1/lib/
Create XML resources descriptor file, name it glassfish-resources.xml. Specify apprpriate params:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool connection-creation-retry-interval-in-seconds="30" connection-validation-method="auto-commit" datasource-classname="com.mysql.cj.jdbc.MysqlDataSource" wrap-jdbc-objects="false" res-type="javax.sql.DataSource" name="mysql_mydb_rootPool" is-connection-validation-required="true" connection-creation-retry-attempts="10" validate-atmost-once-period-in-seconds="60">
<property name="User" value="root"/>
<property name="Password" value="secret"/>
<property name="URL" value="jdbc:mysql://localhost:3306/voyager?zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&useSSL=false"/>
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"/>
<property name="characterEncoding" value="utf-8"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="jdbc/mydb" object-type="user" pool-name="mysql_mydb_rootPool"/>
</resources>
Add resources to Payara
$PAYARA_HOME/bin/asadmin add-resources glassfish-resources.xml
Restart your domain
$PAYARA_HOME/bin/asadmin restart-domain

Configuring Nutch 2.3 with HSQL 2.3.3 - ClassNotFoundException : org/apache/avro/ipc/ByteBufferOutputStream

I'm getting ClassNotFoundException : org/apache/avro/ipc/ByteBufferOutputStream when I run apache Nutch with HSQLDB although I have all the avro related jar files under lib
avro-1.7.6.jar
avro-compiler-1.7.6.jar
avro-ipc-1.7.6.jar
avro-mapred-1.7.6.jar
This is what I did:
Got HSQLDB up and running
root#elephant hsqldb# sudo java -cp /home/hsqldb/hsqldb-2.3.3/hsqldb/lib/hsqldb.jar org.hsqldb.server.Server --props /home/hsqldb/hsqldb-2.3.3/hsqldb/conf/server.properties
[Server#372f7a8d]: [Thread[main,5,main]]: checkRunning(false) entered
[Server#372f7a8d]: [Thread[main,5,main]]: checkRunning(false) exited
[Server#372f7a8d]: Startup sequence initiated from main() method
[Server#372f7a8d]: Loaded properties from [/home/hsqldb/hsqldb-2.3.3/hsqldb/conf/server.properties]
[Server#372f7a8d]: Initiating startup sequence...
[Server#372f7a8d]: Server socket opened successfully in 28 ms.
[Server#372f7a8d]: Database [index=0, id=0, db=file:/home/hsqldb/hsqldb-2.3.3/hsqldb/data/nutch, alias=nutchdb] opened sucessfully in 1406 ms.
[Server#372f7a8d]: Startup sequence completed in 1438 ms.
[Server#372f7a8d]: 2015-12-26 18:30:13.841 HSQLDB server 2.3.3 is online on port 9001
[Server#372f7a8d]: To close normally, connect and execute SHUTDOWN SQL
[Server#372f7a8d]: From command line, use [Ctrl]+[C] to abort abruptly
Configured ivy/ivy.xml
uncommented below lines in ivy.xml
<dependency org="org.apache.gora" name="gora-core" rev="0.5" conf="*->default"/>
and
<dependency org="org.apache.gora" name="gora-sql" rev="0.1.1-incubating"
conf="*->default" />
uncommented the below lines conf/gora.properites
###############################
# Default SqlStore properties #
###############################
gora.sqlstore.jdbc.driver=org.hsqldb.jdbc.JDBCDriver
gora.sqlstore.jdbc.url=jdbc:hsqldb:hsql://localhost/nutchdb
gora.sqlstore.jdbc.user=sa
gora.sqlstore.jdbc.password=
Ran ant build
ant runtime
Added configuration for nutch-site.xml
root#elephant conf# cat nutch-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>storage.data.store.class</name>
<value>org.apache.gora.sql.store.SqlStore</value>
</property>
<property>
<name>http.agent.name</name>
<value>NutchCrawler</value>
</property>
<property>
<name>http.robots.agents</name>
<value>NutchCrawler,*</value>
</property>
</configuration>
Created seed.txt under urls folder
Executed the nutch by injecting the urls
[root#elephant local]# bin/nutch inject urls/
InjectorJob: starting at 2015-12-26 19:11:24
InjectorJob: Injecting urlDir: urls
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/avro/ipc/ByteBufferOutputStream
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at org.apache.nutch.storage.StorageUtils.getDataStoreClass(StorageUtils.java:93)
at org.apache.nutch.storage.StorageUtils.createWebStore(StorageUtils.java:77)
at org.apache.nutch.crawl.InjectorJob.run(InjectorJob.java:218)
at org.apache.nutch.crawl.InjectorJob.inject(InjectorJob.java:252)
at org.apache.nutch.crawl.InjectorJob.run(InjectorJob.java:275)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at org.apache.nutch.crawl.InjectorJob.main(InjectorJob.java:284)
Caused by: java.lang.ClassNotFoundException: org.apache.avro.ipc.ByteBufferOutputStream
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
Gora-sql is not supported. Due some licenses issues (if I am not wrong), it became disabled around Gora 0.2.
So I suggest you to use other storage like, for example, HBase.
How to get HBase up&running fast: read answer at https://stackoverflow.com/a/39837926/582789

Services with missing/unavailable dependencies error in JBoss EAP 6.2.0.GA

I am trying to migrate my project war from Tomcat 6 to JBoss EAP 6.2.0. When trying to deploy the war I am getting the following exception:
16:58:58,493 WARN [org.jboss.as.ee] (MSC service thread 1-4) JBAS011001: Could not resolve resource-env-ref java:/mwdb
16:58:58,568 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010403: Deploying JDBC-compliant driver class com.microsoft.sqlserver.jdbc.SQLServerDriver (version 4.0)
16:58:58,787 ERROR [org.jboss.as.server] (HttpManagementService-threads - 1) JBAS015870: Deploy of deployment "csc.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.csc.csc.env.jdbc.mwdb is missing [jboss.naming.context.java.jboss.resources.jdbc.mwdb]"]}
I am using MSSQL server as database and following is the configuration in my standalone.xml file.
<datasources>
<datasource jta="true" jndi-name="java:/mwdb" pool-name="jdbc/mwdb" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sqlserver://<ServerIP>\\<Instance>:<port>;Database=MWDB</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqlserver</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>admin</user-name>
<password>admin</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
</validation>
</datasource>
<drivers>
<driver name="sqlserver" module="com.microsoft.sqlserver.jdbc">
<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
</driver>
</drivers>
</datasources>
I have placed sqljdbc4.jar and module.xml at jboss-as\modules\com\microsoft\sqlserver\jdbc\main.
My module.xml reads as follows:
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver.jdbc">
<resources>
<resource-root path="sqljdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
I have searched a lot about this issue in last two days and tried many things but nothing seems to work.

Using cargo to deploy war to remote Jboss7 server

I would like to use Cargo to deploy my maven generated war file to a remote JBoss Server that is already running.
I have configured my pom.xml like this:
...
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.1.0.Final</version>
</dependency>
</dependencies>
<configuration>
<!-- Container configuration -->
<container>
<timeout>300000</timeout> <!-- 5 minutes -->
<containerId>jboss71x</containerId>
<type>remote</type>
</container>
<!-- Configuration to use with the container -->
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname><myIP></cargo.hostname>
<cargo.jboss.management.port>9999</cargo.jboss.management.port>
<cargo.remote.username><myUser></cargo.remote.username>
<cargo.remote.password><myPass></cargo.remote.password>
</properties>
</configuration>
<!-- Deployer configuration -->
<deployer>
<type>remote</type>
</deployer>
<!-- Deployables configuration -->
<deployables>
<deployable>
<groupId>de.<myGroup></groupId>
<artifactId><myArtifact></artifactId>
<type>war</type>
<pingURL>http://<myIP>:8080/<myContextPath></pingURL>
<pingTimeout>60000</pingTimeout>
</deployable>
</deployables>
</configuration>
</plugin>
...
Of course all variables of the form <my...> are filled out with the real values.
If I run this with the maven command:
mvn -X cargo:deploy
The maven console says:
...
Sep 12, 2012 5:06:12 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
Sep 12, 2012 5:06:12 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.2.GA
[DEBUG] [swordCallbackHandler] Responded to a RealmCallback
[DEBUG] [swordCallbackHandler] Responded to a NameCallback
[DEBUG] [swordCallbackHandler] Responded to a PasswordCallback
[INFO] [Boss7xRemoteDeployer] The deployment has failed: org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[myWar.war]
...
On the running JBoss server I can see a logging message in the console like this:
17:07:24,197 ERROR [org.jboss.remoting.remote.connection] (Remoting "pc09:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen.
(sorry for the german inside of the log. It basically says: An existing connection was closed by the remote host.)
Does anybody have an idea what could be wrong or how I could get more debug info from cargo to find out what exactly the problem is?
BTW: I have used the JBoss CLI access to that Jboss Server for Arquillian tests so I am pretty confident that the access to that Jboss server via CLI should be ok.
EDIT:
Seems like I have to undeploy first. To reassure that the access to the CLI works I just connected to it using the jboss-cli.bat. Then I just coincidentally undeployed the existing war and after that the deployment via cargo started to work.
(Can I close this question or mark it as resolved in any way?)

Trying to run a pack of selenium tests written in java using Jenkins

After reading nearly all the posts that it suggests under "Questions with similar titles" (I will continue reading after sending this post) and reading
centripetal.ca/blog/2011/02/07/getting-started-with-selenium-and-jenkins/
oliverpolden.com/content/setting-automated-selenium-testing-jenkinshudson
and some other posts (I note these two because I think they may be useful to someone) I haven't found an answer to what I need. And now I get to that:
I'm working in a company that uses Jenkins for CI and maven. They have three types of tests ran for the sotware: junit, cactus and selenium. Jenkins has a job to run junit tests. Now they've decided to run the other two types of tests (Cactus and Selenium) using Jenkins. And that's my task. Cactus would be another question I'll ask later (have been banging my head with that one for too long right now). The Selenium tests are written in java and there's a java file that has all the tests as it follows:
package com.mycompany.test.dailySanity;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
#RunWith(Suite.class)
#Suite.SuiteClasses({
Test1.class,
Test2.class,
Test3.class,
})
public class AllTests {
/**
* This is just a place holder.
* Add All your TestClass one to the list above.
* NOTE, the TestClasses should be "," separated
*/
}
All the information I've found talks about an htmlsuite, but nothing about if the tests are in java (no, exporting them to HTML is not an option). I've tried
export DISPLAY=":99" && java -jar /path/to/selenium-server.jar
-browserSessionReuse -htmlSuite *firefox http://localhost
/path/to/my/testsfile/AllTests.java
/path/to/my/logfile/SeleniumLog.html
as an "Execute Shell" in "Build" step in Jenkins job, but it just stays trying something.
Console output
09:29:48.508 INFO - Java: Sun Microsystems Inc. 14.2-b01
09:29:48.518 INFO - OS: Linux 2.6.18.8-xenU amd64
09:29:48.654 INFO - v2.4.0, with Core v2.4.0. Built from revision 13337
09:29:49.263 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:29:49.264 INFO - Version Jetty/5.1.x
09:29:49.269 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
09:29:49.271 INFO - Started HttpContext[/selenium-server,/selenium-server]
09:29:49.271 INFO - Started HttpContext[/,/]
09:29:49.337 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#7a187814
09:29:49.337 INFO - Started HttpContext[/wd,/wd]
09:29:49.343 INFO - Started SocketListener on 0.0.0.0:4444
09:29:49.343 INFO - Started org.openqa.jetty.jetty.Server#67ad77a7
10:51:00.038 INFO - Shutting down...
10:51:00.040 INFO - Stopping Acceptor ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=4444]
I assume it does nothing else (waited for 2 hours before aboting it) beacause it's a java file and it requires an html file (-htmlsuite is a clue).
To sum up: I need a way to run Selenium tests written in Java and packaged in a java suite on Jenkins.
EDITING
Ok, I'm not getting anywhere and running out of time. I'm adding more information just in case someone can give me a hand (not that I'm not thankful to Ross). Here goes my selenium_pom.xml:
<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>my.company</groupId>
<artifactId>selenium-test</artifactId>
<version>0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium.client-drivers</groupId>
<artifactId>selenium-java-client-driver</artifactId>
<version>1.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</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>
<includes>
<include>/path/to/my/tests/AllTests.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I run
mvn -f selenium_pom.xml integration-test
I get the following output
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.kana.sem:selenium-test:jar:0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. # line 44, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-test 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # selenium-test ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /path/to/resources/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # selenium-test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) # selenium-test ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # selenium-test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO]
[INFO] --- selenium-maven-plugin:2.1:start-server (default) # selenium-test ---
Launching Selenium Server
Waiting for Selenium Server...
[WARNING] OS appears to be Unix and no DISPLAY environment variable has been detected. Browser maybe unable to function correctly. Consider using the selenium:xvfb goal to enable headless operation.
[INFO] User extensions: /localhome/kana/p4/dev/BOT/target/selenium/user-extensions.js
08:05:07,166 INFO [org.openqa.selenium.server.SeleniumServer] Java: IBM Corporation 2.3
08:05:07,173 INFO [org.openqa.selenium.server.SeleniumServer] OS: Linux 2.6.18.8-xenU x86
08:05:07,184 INFO [org.openqa.selenium.server.SeleniumServer] v2.9.0, with Core v2.9.0. Built from revision 14289
08:05:07,273 INFO [org.openqa.selenium.server.SeleniumServer] RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
08:05:07,277 INFO [org.openqa.jetty.http.HttpServer] Version Jetty/5.1.x
08:05:07,686 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.servlet.ServletHandler#51fe51fe
08:05:07,687 INFO [org.openqa.jetty.util.Container] Started HttpContext[/wd,/wd]
08:05:07,687 INFO [org.openqa.jetty.util.Container] Started HttpContext[/,/]
08:05:07,688 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server,/selenium-server]
08:05:07,689 INFO [org.openqa.jetty.util.Container] Started HttpContext[/selenium-server/driver,/selenium-server/driver]
08:05:07,705 INFO [org.openqa.jetty.http.SocketListener] Started SocketListener on 0.0.0.0:4444
08:05:07,705 INFO [org.openqa.jetty.util.Container] Started org.openqa.jetty.jetty.Server#40e640e6
08:05:07.916 INFO - Checking Resource aliases
Selenium Server started
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default) # selenium-test ---
[INFO] No tests to run.
[INFO] Surefire report directory: /path/to/surefire-reports/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30.387s
[INFO] Finished at: Fri Jan 13 08:05:08 CST 2012
[INFO] Final Memory: 12M/30M
[INFO] ------------------------------------------------------------------------
I'm using perforce, Jenkins, maven3 and Red Hat Enterprise Linux Server release 5.5 (Tikanga). I'm sure my pom is one of the problems, but got it from internet samples...
Thanks (and congratulations to all that have finished reading this post!)
PS: If you also know how to get a report from the Selenium tests that would be great.
The -htmlsuite option is for something completely different from what you're trying to do. Don't let it distract you :-)
Your Java code appears to be written so that the tests are executed via JUnit. That's a very common technique. I expect all you need to do is make sure the Selenium RC server is running before the tests begin. Just java -jar /path/to/selenium-server.jar and leave it running until at least the end of the last test. Your tests will contact the server by creating a connection to it, probably by calling new DefaultSelenium(...).
Jenkins is very well integrated with Maven, so I suggest you concentrate on running the tests using Maven rather than Jenkins. You can use the failsafe plugin to run integration tests such as your selenium tests. Jenkins will automatically find the failsafe reports and show a pretty HTML summary. Also, you can test this more easily on your local machine.
Please can you update your post to clarify whether you're using Selenium 1 or 2. RemoteWebDriver looks like v2, but your POM shows selenium-java-client-driver from 1.0