Passing the JDBC URL to openjpa-maven-plugin to refresh data in PostgreSQL - postgresql

In pom.xml I have (taken from http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/):
<properties>
<openjpa.sql.action>refresh</openjpa.sql.action>
<database.driver.name>org.postgresql.Driver</database.driver.name>
<database.connection.url>jdbc:postgresql://myURL</database.connection.url>
<database.user>user</database.user>
<database.password>password</database.password>
</properties>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>${openjpa-version}</version>
<configuration>
<includes>**/entity/*.class</includes>
<excludes>**/entity/Q*.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
<sqlAction>${openjpa.sql.action}</sqlAction>
<connectionDriverName>${database.driver.name}</connectionDriverName>
<connectionProperties>
jdbcUrl=${database.connection.url},
user=${database.user},
password=${database.password},
</connectionProperties>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
<goal>sql</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>${openjpa-version}</version>
</dependency>
</dependencies>
</plugin>
For some reason, the URL isn't passed correctly and I get
Execution enhancer of goal org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql failed: A connection could not be obtained for driver class "org.postgresql.Driver" and URL "null". You may have specified an invalid URL. (org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql:enhancer:process-classes)
I've tried replacing jdbcUrl in connectionProperties with url, URL, etc. Nothing helps. However, I can put the URL in persistence.xml and this does work:
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://myURL" />
Driver, user, and password are obtained from Maven properties. However, since this URL is only used to generate DDL (data source is created in a different way at the runtime), I'd prefer to have it in pom.xml as well without polluting persistence.xml. Is there a way to do this?

I used commons-dbcp BasicDataSource for getting the connection like this:
<connectionDriverName>org.apache.commons.dbcp.BasicDataSource</connectionDriverName>
<connectionProperties>
driverClassName=${database.driver.name},
url=${database.connection.url},
username=${database.user},
password=${database.password},
</connectionProperties>

Related

How can i setup the postgres dialect of jooq-codegen-maven plugin with liquibase and without db connection properties

I use the liquibase and jooq and i need to generate my pojo's directly from liquibase xml files, but i have a problem to override the default "H2" dialect with Postgres. Actually, i've tried to setup dialect via property within plugin "configuration" section but it still uses H2. Can someone ask me please how can i make jooq use postgres dialect when reading xml files and generating java classes.
Here is the used libraries versions
<properties>
<jooq.version>3.13.4</jooq.version>
<vertx-jooq.version>5.1.1</vertx-jooq.version>
<postgres.version>42.2.12</postgres.version>
</properties>
Here is the my plugin configuration
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>jooq-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
<dependency>
<groupId>io.github.jklingsporn</groupId>
<artifactId>vertx-jooq-generate</artifactId>
<version>${vertx-jooq.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>
<configuration>
<generator>
<name>io.github.jklingsporn.vertx.jooq.generate.classic.ClassicReactiveVertxGenerator</name>
<database>
<name>org.jooq.meta.extensions.liquibase.LiquibaseDatabase</name>
<properties>
<property>
<key>scripts</key>
<value>src/main/resources/liquibase/tenant/changelog.xml</value>
</property>
<property>
<key>changeLogParameters.contexts</key>
<value>!test</value>
</property>
<-- unfortunately this property doesn't work -->
<property>
<key>dialect</key>
<value>POSTGRES</value>
</property>
</properties>
<outputSchemaToDefault>true</outputSchemaToDefault>
<unsignedTypes>false</unsignedTypes>
<forcedTypes />
</database>
<generate>
<daos>true</daos>
<fluentSetters>true</fluentSetters>
</generate>
<target>
<packageName>org.folio.rest.jooq</packageName>
</target>
<strategy>
<name>io.github.jklingsporn.vertx.jooq.generate.VertxGeneratorStrategy</name>
</strategy>
</generator>
</configuration>
</plugin>
As of jOOQ 3.14, the org.jooq.meta.extensions.liquibase.LiquibaseDatabase data source for the jOOQ code generator uses H2 behind the scenes to simulate a migration, instead of actually running the migration on your target database. This allows for working with jOOQ and your liquibase migration scripts without an actual database instance and connection. In the future, it might be possible to spin up a PostgreSQL instance, transparently, using testcontainers: https://github.com/jOOQ/jOOQ/issues/6551
Here's an example how to set it up:
https://github.com/jOOQ/jOOQ/tree/main/jOOQ-examples/jOOQ-testcontainers-example (not too hard)
If you wish to work with an actual PostgreSQL database, just run the liquibase migration using the liquibase maven plugins before you run the jOOQ code generation, having both connect to the same database server.

Unable to connect Cloud SQL mySql instance from Data Fusion. Exception "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory"

Facing exception "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception."
when trying to connect with mysql instance in google cloud data fusion.
created cloud data fusion instance
From Wrangler-->Add connection --> Added the jar build(created from pom.xml given below) as a driver
In Add connection used the connection string as "dbc:mysql://google/mysql?cloudSqlInstance=socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false"
While Testing the connection, it throws error, "Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception."
This is my pom.xml and I build the fat jar using mvn package.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mysql-with-cloud-sql-socket-factory</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory-connector-j-8</artifactId>
<version>1.0.15</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration> <!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jar-with-dependencies</id>
<properties>
<lane>jar-with-dependencies</lane>
</properties>
</profile>
</profiles>
</project>
Use MySQL instead:
From the Add Connection> Database Search for MySQL
Download the MySQL Driver from dev.mysql.com. Unzip.
On the hub again this time click Deploy Upload mysql-connector-java-5.x.xx-bin.jar
Go back to Add Connection> Database, you should see green tick against MySQL driver
Click on MySQL driver and setup the connection parameter.
Make sure you have added the relevant network in the Cloud SQL screen to allow Datafusion instance to make connection to Cloud SQL. If Datafusion is running in the same project then you dont need to do anything else.

maven codehaus.mojo could not be resolved

I'm trying to build a JavaFX project with NetBeans but when i run it i have a this :
Plugin org.codehaus.mojo:exec-maven-plugin:1.2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.mojo:exec-maven-plugin:jar:1.2.1: Could not transfer artifact org.codehaus.mojo:exec-maven-plugin:pom:1.2.1 from/to HTTP (http://repo.maven.apache.org/maven2): Access denied to: http://repo.maven.apache.org/maven2/org/codehaus/mojo/exec-maven-plugin/1.2.1/exec-maven-plugin-1.2.1.pom , ReasonPhrase:Forbidden. -> [Help 1]
I work behind proxy but i configured Netbeans with my proxy and i tried "Test connection" and that's work.
I had also configured the ".m2/settings.xml" directory with this proxy
<?xml version="1.0" encoding="UTF-8"?> <settings> <proxies>
<proxy>
<active />
<protocol>http</protocol>
<username>username</username>
<password>password</password>
<port>8080</port>
<host>proxyhost</host>
<id/>
</proxy> </proxies>
<mirrors>
<mirror>
<id>HTTP</id>
<name>HTTP Central</name>
<url>http://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror> </mirrors> </settings>
my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bega</groupId>
<artifactId>Chronos</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Chronos</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>com.bega.chronos.MainApp</mainClass>
</properties>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>Your Organisation</name>
</organization>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeScope>system</excludeScope>
<excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/../bin/javafxpackager</executable>
<arguments>
<argument>-createjar</argument>
<argument>-nocss2bin</argument>
<argument>-appclass</argument>
<argument>${mainClass}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.build.finalName}.jar</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${java.home}/bin/java</executable>
<commandlineArgs>${runfx.args}</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.9</version>
</dependency>
</dependencies>
</project>
if anyone have a idea why that doesn't work ?
I assume the repository server was temporary not working correctly. At least I was able to download the file mentioned in the error message.
Unfortunately Maven caches not-found errors. There are a lot of questions on SO about resetting the cached state and force a re-download.
IMHO the easiest way is to delete all data of the problematic artifact from the local Maven repo which is located in the subdirectory .m2/repository in your user home directory.
Open the .m2/repository and proceed to the path org/codehaus/mojo/exec-maven-plugin/. There delete the subdirectory 1.2.1 and all contained files. Maven will automatically download them the next time they are required.
Sometimes is just about synchronization
just click the button refresh and the problem is fixed
For me, I waiting a few minutes and tried the mvn package command again and it worked. Seems to be down once in a while, for some reason.
go to the local maven repostory, delete the corespondent folder. As D:\MAVENrepo\org\codehaus\mojo\exec-maven-plugin\1.2.1,
use Alt+f5 to update maven project.
Open the C:\Users\your user\\.m2\repository\org\codehaus\mojo\exec-maven-plugin, there delete the subdirectory 1.2.1, if maven doesn't download it automatically, you can use this command:
mvn dependency:purge-local-repository
Well i got the same error so i'm putting this here just for the sake of it somebody having the same issue. Using wagon-plugin: the dependency version got an extra digit for 2.0.0
my version was set to 2.0 and this error popped (y ofc what else d'uh)
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>**2.0.0**</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>**1.0**</version>
</dependency>
Also for future reference they might change the reponame from codehaus to mojohaus (as of now still the old reponame). Hope this helps someone !
Build failure for visiting https://repo.maven.apache.org/maven2/org/codehaus/mojo/exec-maven-plugin/1.2.1/exec-maven-plugin-1.2.1.pom from netbeans
I visited the url from browser then it showed network error .
Again refresh url it loaded the response to browser
I rebuild and run it loaded the project without previous problem
It seems it was network error or network proxy failure from netbeans.
Currently it is resolved
As you can see in the stack trace the issue was that http://repo.maven.apache.org/maven2/org/codehaus/mojo/exec-maven-plugin/1.2.1/exec-maven-plugin-1.2.1.pom was forbidden, probably because it's HTTP and not HTTPS and your proxy blocks unsecured connections. (You can test it in the browser).
Solution: Use a newer version of Netbeans where they fixed it should use by default HTTPS, see Maven dependencies are failing with a 501 error.
For me, it fixed this issue.

Error importing cxf projects into eclipse using m2e: Couldn't find that class org.apache.cxf.pmd.UnsafeStringConstructorRule

I check out the cxf sources and try to import a project into eclipse using "import as maven project".
I then get the error: Couldn't find that class org.apache.cxf.pmd.UnsafeStringConstructorRule
from m2e.
So it seems like cxf defines a rule there and the pmd plugin does not find it.
Any ideas?
Regarding to the Apache CXF parent pom, it mentions about the profile named m2eclipse which defines maven-pmd-plugin with the dependency as the following: -
<profile>
<id>m2eclipse</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<dependencies>
<dependency>
<groupId>org.apache.cxf.build-utils</groupId>
<artifactId>cxf-buildtools</artifactId>
<version>${cxf.build-utils.version}</version>
</dependency>
</dependencies>
<configuration>
<rulesets>
<ruleset>
${cxf.resources.base.path}cxf-pmd-ruleset.xml
</ruleset>
</rulesets>
<sourceEncoding>UTF-8</sourceEncoding>
<targetJdk>1.6</targetJdk>
<linkXRef>false</linkXRef>
<includeTests>true</includeTests>
<verbose>true</verbose>
<excludeRoots>
<excludeRoot>${basedir}/src/main/generated</excludeRoot>
</excludeRoots>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
You may be noticed that there is no any activation in this profile.
After download the org.apache.cxf.build-utils:cxf-buildtools:2.5.0:jar form Maven Central Repository, I also have found the class named org.apache.cxf.pmd.UnsafeStringConstructorRule as well.
This may be the root cause of your problem. IMHO, you may try to activate this profile by missing some properties e.g.
<profile>
<id>m2eclipse</id>
<activation>
<property>
<name>!skipM2E</name>
</property>
</activation>
....
</profile>
I hope this may help.

Automate the process of generating webservice clients

I am using RAD 7.5 (based on Eclipse) to generate client code from webservice WSDLs. There are actually 2 or 3 that need to be generated together to produce one client. Is there a way to automate the process of stepping through the webservice client wizard, selecting the JAX-WS binding files for all WSDLs? Ideally, this process would also create the Jar file after the Java code has been generated.
Is it possible to automate this in RAD/Eclipse?
You can use Maven with Eclipse.
There is a plugin for Maven
http://jax-ws-commons.java.net/jaxws-maven-plugin/examples/using-wsdlLocation.html
<project>
...
<dependencies>
...
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.6</version>
</dependency>
...
</dependencies>
...
<build>
...
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<!-- Following configuration will invoke wsimport once for each wsdl. -->
<configuration>
<wsdlLocation>http://example.com/mywebservices/*</wsdlLocation>
<wsdlDirectory>src/mywsdls</wsdlDirectory>
<wsdlFiles>
<wsdlFile>a.wsdl</wsdlFile> <!-- produces wsdlLocation = http://example.com/mywebservices/a.wsdl -->
<wsdlFile>b/b.wsdl</wsdlFile> <!-- produces wsdlLocation = http://example.com/mywebservices/b/b.wsdl -->
<wsdlFile>${basedir}/src/mywsdls/c.wsdl</wsdlFile> <!-- produces wsdlLocation = /path/to/basedir/src/mywsdls/c.wsdl -->
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
<build>
...
</project>