Connecting to db2 from java client - maven

I am trying to connect to db2 from a java client running the application as a jar. The jar is a super-jar with all dependencies generated by the shade plugin.
When I run the program from my ide(Netbeans) it runs fine, but when I run it from commandline like this it fails:
java -jar target/locationImporter.jar
The exception I get is:
Exception in thread "main" java.lang.NullPointerException
at com.ibm.as400.access.PortMapper.getServerSocket(PortMapper.java:216)
at com.ibm.as400.access.AS400ImplRemote.signonConnect(AS400ImplRemote.java:2363)
at com.ibm.as400.access.AS400ImplRemote.signon(AS400ImplRemote.java:2278)
at com.ibm.as400.access.AS400.sendSignonRequest(AS400.java:3142)
at com.ibm.as400.access.AS400.promptSignon(AS400.java:2706)
at com.ibm.as400.access.AS400.signon(AS400.java:4035)
at com.ibm.as400.access.AS400.connectService(AS400.java:1184)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:3338)
at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1419)
at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1256)
at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:395)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dataprep.ConnectionSupplier.getConnection(ConnectionSupplier.java:18)
at dataprep.SqlFileRunner.runScript(SqlFileRunner.java:65)
at dataprep.SqlFileRunner.runSqlFile(SqlFileRunner.java:26)
at dataprep.PrepareDatabase.main(PrepareDatabase.java:26)
The code that fails is:
Class.forName("com.ibm.as400.access.AS400JDBCDriver").newInstance();
return DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PASSWORD);
Since it runs in my ide, I know that the url, user and password is correct.
My shade plugin is configured like this in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
<finalName>locationImporter</finalName>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>

After hours of debugging a colleague of mine pointed me in the right direction. Removing the minimizeJar fixes the problem since the shade plugin removed the file "SocketContainerInet" since it was not directly instantiated but via a string-value..

Related

How to pass add-module to spring boot application?

I am using a maven dependency which require me to pass add-module during compilation and runtime as mentioned here.
Can someone let me know how can I pass --add-module option to a spring boot application during compilation and runtime? It will be good if I can control both compilation and runtime behaviour from the pom.xml.
For compilation you can use the maven-copmiler-plugin in your build of your pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<parameters>true</parameters>
</configuration>
</execution>
</executions>
<configuration>
<source>14</source>
<target>14</target>
<compilerReuseStrategy>reuseSame</compilerReuseStrategy>
<compilerArgs>
<arg>--enable-preview</arg>
<arg>--add-modules=jdk.incubator.foreign</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
As you see I have included also the --enable-preview. In JDK14 as reported in JEPS 370 it is not needed since this is not a preview feature. But keep an eye on it since it might be needed in other jdk versions since in some versions this belongs in preview features.
As for runntime a spring-boot application is normally just a .jar executable file which you start with the normal java -jar myApp.jar command.
According to oracle documentation, the format of the command line is
To execute a JAR file:
java [options] -jar jarfile [args...]
So the command you want would be
java --add-modules jdk.incubator.foreign -jar myApp.jar

java.lang.OutOfMemoryError: PermGen (GWT + NetBeans + Maven)

I am working on GWT + NetBeans + Maven project and I keep getting out of memory error. I am running the project simply by executing gwt:debug goal.
I tried to set higher memory limits in pom.xml like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwt.version}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
</goals>
<configuration>
<modules>
<module>cz.bull.iui.User</module>
<!--<module>cz.bull.iui.Login</module>-->
</modules>
<localWorkers>4</localWorkers>
<extraJvmArgs>-Xmx1024M -Xss1024k -XX:MaxPermSize=1024M</extraJvmArgs>
<localWorkers>4</localWorkers>
<draftCompile>true</draftCompile>
<logLevel>INFO</logLevel>
<failOnError>false</failOnError>
<hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
<style>OBF</style>
</configuration>
</execution>
</executions>
</plugin>
But the problem still occurs:
Could some advise me, where do I have to set it, so GWT gets enough memory? By checking Task manager I can see Development Mode console is using about 500MB at the occurrence of crash, which is less than defined.
Please have a look at below link where a lots of the ways are suggested to set the vm arguments in Jetty.
maven jetty plugin - how to control vm arguments?
The only good answer is to switch to Eclipse, it just doesn't work with NetBeans.

How to download JDK installer by maven?

I try to download Oracle (Sun) Java JDK via maven without success:
<dependency>
<groupId>com.sun</groupId>
<artifactId>jdk</artifactId>
<version>6u45</version>
<classifier>dlj-linux-i586</classifier>
<type>bin</type>
</dependency>
What maven repository should I use to download Oracle (Sun) Java JDK?
Added
I want to find a way to download DLJ version of jdk-6u45-linux-i586.bin JDK installer by maven, without manually download.
Now i have standard maven error when dependency is not configured well or a maven repository is missed:
Missing:
----------
com.sun:jdk:bin:dlj-linux-amd64:6u45
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.sun -DartifactId=jdk -Dversion=6u45 -Dclassifier=dlj-linux-amd64 -Dpackaging=bin -Dfile=/path/to/file
How to download JDK installer by maven?
You can't. The JDK installer is not in any public Maven repository. If it was, the Oracle lawyers would be sending "cease and desist" letters.
I am aware that you could use the Maven exec plugin (or similar) to "work around" Oracle's click through license agreement. However, this is arguably illegal under US law. Consider what happened to "weev" when prosecutors decided to make an example of him.
When you're running on a linux machine, you can download the jdk using maven-exec-plugin calling curl/wget :
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<!-- using curl -->
<execution>
<id>download oracle jdk (curl)</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>curl</executable>
<arguments>
<argument>-L</argument>
<argument>--header</argument>
<argument>Cookie: s_nr=1359635827494; s_cc=true; gpw_e24=blub; s_sq=[[]]; gpv_p24=novalue</argument>
<argument>http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-i586.bin</argument>
<argumen>-o</argumen>
<argument>${project.build.directory}/curl-jdk-6u45-linux-i586.bin</argument>
</arguments>
</configuration>
</execution>
<execution>
<!-- using wget -->
<id>download oracle jdk (wget)</id>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>wget</executable>
<arguments>
<argument>--no-cookies</argument>
<argument>--header</argument>
<argument>Cookie: s_nr=1359635827494; s_cc=true; gpw_e24=blub; s_sq=[[]]; gpv_p24=no value</argument>
<argument>http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin</argument>
<argument>-O</argument>
<argument>${project.build.directory}/wget-jdk-6u45-linux-x64.bin</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
...
I have developed maven plugin which can download and unpack OpenJDK from different providers (Liberica, Adopt, SapMachine), it is useful for preparing cross-platform JDK images in distributives
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink-wrapper</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<id>cache-jdk-8</id>
<goals>
<goal>cache-jdk</goal>
</goals>
<configuration>
<jdkPathProperty>jlink.jdk.path</jdkPathProperty>
<jdkCachePath>${project.build.directory}${file.separator}jdkCache</jdkCachePath>
<provider>ADOPT</provider>
<providerConfig>
<release>jdk8u192-b12</release>
<arch>x64</arch>
<type>jdk</type>
<impl>hotspot</impl>
</providerConfig>
</configuration>
</execution>
</executions>

Issue with stopping weblogic server using wls-maven-plugin

This is part of my pom.xml of my .ear file
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-maven-plugin</artifactId>
<version>12.1.1.0</version>
<configuration>
<adminurl>${adminURL}</adminurl>
<user>${username}</user>
<password>${pswrd}</password>
<upload>true</upload>
<remote>false</remote>
<verbose>true</verbose>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<name>${project.build.finalName}</name>
<targets>${serverName}</targets>
<noExit>true</noExit>
<middlewareHome>${middlewareH}</middlewareHome>
<domainHome>${domainH}</domainHome>
</configuration>
<executions>
<execution>
<id>stopserver</id>
<phase>install</phase>
<goals>
<goal>stop-server</goal>
</goals>
<configuration>
<action>stopserver</action>
<workingDir>${stopScriptDirectory}</workingDir>
<command>stopScript.sh</command>
</configuration>
</execution>
</executions>
</plugin>
I am trying to stop the server by running the stopScript.sh
This is the error I am getting when it is trying to execute the stop-server goal:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server (stopserver) on project OventusEAR2: Unable to parse configuration of mojo com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server for parameter command: Cannot assign configuration entry 'command' with value 'stopScript.sh' of type java.lang.String to property of type java.lang.String[]
Any ideas?
Though I am not familiar with this particular plugin, however I have seen similar issues before, I guess command parameter is expecting an array instead.
Please try replacing
<command>stopScript.sh</command>
with
<command>
<value>stopScript.sh</value>
</command>
and test again.

"parent.lock" for firefox profile when running selenium maven plugin

When my integration tests are run with selenium plugin for maven
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
</configuration>
</execution>
<execution>
<id>stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
the following message is received:
Lock file still present! C:\Users\ADM\AppData\Local\Temp\customProfileDirbb53fd86ecaf4236bf538b7a1171814b\parent.lock
If I delete parent.lock file immediately after the firefox profile is created the tests are working properly.
Does anyone know how to avoid creation of parent.lock file? or any other solution
I'm using selenium 2.33.0
the whole exception is
ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: Firefox refused shutdown while preparing a profile
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:367)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.populateCustomProfileDirectory(FirefoxChromeLauncher.java:120)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launch(FirefoxChromeLauncher.java:90)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.launchRemoteSession(FirefoxChromeLauncher.java:412)
at org.openqa.selenium.server.browserlaunchers.FirefoxLauncher.launchRemoteSession(FirefoxLauncher.java:114)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:381)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:125)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:86)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:810)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:437)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:407)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:151)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher$FileLockRemainedException: Lock file still present! C:\Users\ADM\AppData\Local\Temp\customProfileDirbb53fd86ecaf4236bf538b7a1171814b\parent.lock
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFileLockToGoAway(FirefoxChromeLauncher.java:318)
at org.openqa.selenium.server.browserlaunchers.FirefoxChromeLauncher.waitForFullProfileToBeCreated(FirefoxChromeLauncher.java:365)
... 20 more
please ensure the following has been configured correctly
http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/

Resources