How to deploy mysql datasource using jboss-as-maven-plugin - mysql

This question is here to give an answer to once i find a solution, I have found documentation on Postgresql and H2 databases from the jboss website and have seen how it is done manually through this website, however I cannot seem to find much information on how to deploy a mysql datasource using the jboss-as-maven-plugin.
What is the minimum configuration properties required to properly register a mysql datasource with jboss-as 7 server through their maven plugin?
I have this dependency:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
And this configuration for the maven plugin
<build>
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<execute-commands/>
<executeCommands/>
<properties>
<enable-welcome-root>false</enable-welcome-root>
</properties>
</configuration>
<executions>
...
<!-- deploy the mysql connectorj -->
<execution>
<id>deploy-mysql-driver</id>
<phase>install</phase>
<goals>
<goal>deploy-artifact</goal>
</goals>
<configuration>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<name>mysql.jar</name>
</configuration>
</execution>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>add-datasource</id>
<phase>deploy</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources</address>
<resources>
<resource>
<address>xa-data-source=java:global/datasources/tncDS</address>
<enable-resource>true</enable-resource>
<properties>
<jndi-name>java:jboss/datasources/tncDS</jndi-name>
<enabled>true</enabled>
<connection-url>jdbc:mysql://localhost:3306/tnc</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-name>mysql.jar</driver-name>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
...
</plugin>
</plugins>
</build>
running the command mvn jboss-as:run causes this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.241s
[INFO] Finished at: Tue Sep 24 21:37:28 EST 2013
[INFO] Final Memory: 16M/308M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy-artifact (deploy-mysql-driver) on project ear: Could not execute goal deploy-artifact on null. Reason: I/O Error could not execute operation '{
[ERROR] "address" => [],
[ERROR] "operation" => "read-attribute",
[ERROR] "name" => "launch-type"
[ERROR] }': java.net.ConnectException: JBAS012144: Could not connect to remote://localhost:9999. The connection timed out
[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/MojoExecutionException
UPDATE:
I have developed a plugin that injects the required file (META-INF/services/java.sql.Driver) into the jar before deployment:
<plugin>
<groupId>com.thenaglecode</groupId>
<artifactId>mysql-jdbc-compliance-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</configuration>
<executions>
<execution>
<goals>
<goal>modify-connector</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
However i'm still getting could not connect to remote message. Is there a step that i'm missing or doing in the wrong sequence as i understand that the run command should start up the server.
UPDATE 2:
After some fiddling and reading of the jboss-as plugin website, I realized that the jboss-as:run goal also invokes the package phase. I was mostly receiving this error when I tried to run any of the deploying goals bound to the package phase.
Anything that needs to be deployed should be bound to the install phase.
I am now getting a seperate error regarding my persistence unit not existing

The problem is the MySQL driver is not JDBC 4 compliant. You need to add a META-INF/services/java.sql.Driver file to the JAR with the fully qualified JDBC driver class name or install it as a module. See https://community.jboss.org/wiki/DataSourceConfigurationInAS7 for more details.

solution here:
conf : jboss as7, maven 3.3.3, mysql java connector 5.1.29 28 27 26...,
starting from mysql java connector 5.1.30, the file Meta-INF/serivces/java.sql.driver contain this line "com.mysql.jdbc.Driver
com.mysql.fabric.jdbc.FabricMySQLDriver", if I change it to "com.mysql.jdbc.Driver" the datasource is created and the project deployed fine.
with mysql java connector 5.1.29 28 27 26 ..., that file contain only "com.mysql.jdbc.Driver", the deployement work fine.
check my pom.xml here
https://github.com/anouarattn/GestionAbsence

Related

Cannot connect to database with flyway through Maven

I am trying to setup flyway for a project with maven and i am unable to make it work. I have the correct configuration (db url, username, password) and i tried connecting to the DB with MySQL Workbench, PhPMyAdmin and also used the flyway command line tool and everything works except maven.
This is the error i am getting:
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:8.5.5:migrate (default-cli) on project flyway-fitinpulse: org.flywaydb.core.api.FlywayException: No database found to handle jdbc:mariadb://placeholderip:3306/db_name -> [Help 1]
And my 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.fitinpulse</groupId>
<artifactId>flyway-fitinpulse</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<configuration>
<url>jdbc:mariadb://placeholderip:3306/db_name</url>
<user>user</user>
<password>password</password>
</configuration>
</plugin>
</plugins>
</build>
Does anyone has any insight?
Have you tried adding <driver> </driver>
inside <configuration>?
Because otherwise the driver is auto-detected based on the url and this might lead to a connection problem I guess.
I finally found the problem. In newer version of the flyway for mysql you need to provide another flyway dependency along with the connection driver:
<dependencies>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
<version>8.5.5</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.0.4</version>
</dependency>
</dependencies>

Unable to suppress excessive logs from scalatest-maven-plugin

Background
I am facing excessive logging from default Logger when I run scala tests from maven because it is not picking up the logback.xml on the classpath with the correct logging definitions
So my maven config is fairly generic (as per scalatest-maven-plugin docs)
Looks like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>MyProj_TestSuite.txt</filereports>
<forkMode>never</forkMode>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
I have a logback.xml in my src/main/resources which gets copied over to target/classes
Things I tried so far
Have spent a whole day to figure out why this is not being picked up -- using the following configuration optional entries
<runpath>
${project.basedir}/target/classes
</runpath>
<systemProperties>
<logback.configurationFile> ${project.basedir}/src/main/resources/logback.xml</logback.configurationFile>
</systemProperties>
<argLine>
-Dlogback.configurationFile=src/main/resources/logback.xml
</argLine>
If I run it like this (from command line) from ${project.basedir}
mvn test -Dlogback.configurationFile=./src/test/resources/logback.xml
it works
I have looked at similar issues on stack and even tried adding this
<build>
<testResources>
<testResource>
<directory>${project.basedir}/target/classes</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
</build>
This did not work - I think it is because I am using scala-maven-test plugin which has its own configuration block.
Any help on how to do this from inside the pom.xml will be much appreciated.
Try to have /src/test/resources/logback-test.xml logback configuration file.
It works for me with scalatest-maven-plugin of 2.0.2 version.

IntelliJ Error when running unit test: Could not find or load main class ${surefireArgLine}

I get the following error when running Unit tests in IntelliJ:
Error: Could not find or load main class ${surefireArgLine}.
I am using maven and in pom.xml I have:
<properties>
...
<surefire.argLine />
</properties>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!--Sets the VM argument line used when unit tests are run.-->
<argLine>${surefire.argLine}</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!--Sets the path to the file which contains the execution data.-->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
...
Did anyone have similiar problem? How to set value for surefireArgLine?
I had the same problem and i think i found the solution on the vertx-issue tracker.
In short you have to configure your IntelliJ Maven (surefire plugin) integration to behave differently.
This works for me in IntelliJ 14.1.6 with mvn 3.3.9
Preferences -> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
For IntelliJ 2019 and above
Settings-> Build,Execution,Deployment -> Build Tools -> Maven -> Running Tests
Uncheck argLine
I was able to fix this error in Netbeans by changing the surefire-plugin version to 2.10 and removing
<argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
from the maven-surefire-plugin configuration. Instead i have created a property argLine that is picked automatically by surefire.
<properties>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
</plugin>
Now, i can run and debug single files and test methods. And Code Coverage is working as expected.
Update of pom.xml solved my problem.
<argLine>${surefire.argLine}</argLine>
Complete plugin info in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
<workingDirectory>${project.build.directory}</workingDirectory>
<jvm>${env.JDK1_8_HOME}\bin\java</jvm>
<argLine>${surefire.argLine}</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin> -->
Was looking for this and found this project "fix" it in this thread
Basically define your jacocoArgLine var name as empty project property. Then in surefire configuration use #{jacocoArgLine} instead of dollar prefix.
I found out that I have to run my test case from maven with
mvn -Dtest=TestCircle test
not directly from IDE.
For a more permanent fix for every new project add the following to your IntelliJ IDEA Custom VM Options:
Help > Edit Custom VM options
Add: -Didea.maven.surefire.disable.argLine=true
This will deactivate surefire for all new projects you open.

jaxb2 maven plugin and configuration inside execution tag

I try to use JAXB2 maven plugin to generate java code from a bunch of .xsd files. If I try to generate from all xsds in a single execution I'll get org.xml.sax.SAXParseException: 'root' is already defined. I cannot modify the xsd files so I need to generate each independently. I found the following pom configuration to achieve that:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>jaxb-Execution1</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution1</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings1.xml</bindingFiles>
<schemaFiles>schema1.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>jaxb-Execution2</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution2</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings2.xml</bindingFiles>
<schemaFiles>schema2.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
But this is not working. The problem is that configurations are not read from inside of the execution block. Why is that? I am using maven 2.2.1.
I had the same issue when I tried to run the plugin using:
mvn jaxb2:xjc
A workaround for me was using:
mvn generate-sources

Send test reports to different directory using maven-surefire-plugin

I want to generate my reports so I used maven-surefire-plugin.
This is my pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>test-reports</id>
<phase>install</phase>
<configuration>
<tasks>
<junitreport todir="./reports">
<fileset dir="./reports">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="./report/html"/>
</junitreport>
</tasks>
</configuration>
<goals>
<goal>test </goal>
</goals>
</execution>
</executions>
</plugin>
But I'm getting this error when I run maven test:
Tests run: 6, Failures: 2, Errors: 2, Skipped: 0
[INFO] --------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] --------------------------------------------------------------------
[INFO] Total time: 10.403s
[INFO] Finished at: Wed Oct 12 08:35:10 CEST 2011
[INFO] Final Memory: 17M/126M
[INFO] --------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.10:test (default-test) on project jebouquine: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\Amira\workspace1\jebouquine\target\surefire-reports for the individual test results.
[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/MojoFailureException
When I open C:\Users\Amira\workspace1\jebouquine\target\surefire-reports I find repotrts but I want them under ./reports.
Any idea how to do it? Or is there any alternative to generate my tests reports?
Look, here's the bottom line: you need to read more about Maven because what you have written does not make sense. You have tried to stuff ant configuration elements into the surefire plugin config, which is not right at all. And you have tried to bind it to the install phase, but then you are running mvn test.
Finally, it might help if you explained why you want them in a different directory in the first place ... there might be a better way to achieve your real goals.
However, this will fix your problem for the next 5 seconds or so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<reportsDirectory>${project.build.directory}/reports</reportsDirectory>
</configuration>
</plugin>