Test broken on jenkins but running locally - linux

we are having such a weird error. Our Tests are running in the local machines (windows) but not running on jenkins (linux).
We get a
Caused by: java.lang.RuntimeException: There was an error in the forked process
java.lang.NoClassDefFoundError:
I'm being looking for solution and got this info on bugzilla
or archive.
Has anybody an idea about this issue and how to solve it?
Thanks
UPDATE
maven-surefire-plugin is also defined in the parent pom.xml for using with cobertura. The Tests are running twice but the second time the tests fails as described above.
I'm defining 2 profiles that are using the surefire-plugin and a surefire plugin definition in the section.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*SoapUiTest.java</exclude>
</excludes>
<excludes>
<!--exclude>**/*.java</exclude -->
</excludes>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/java</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>soapUi</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*EntityTest.java</exclude>
</excludes>
<includes>
<include>**/*SoapUiTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*EntityTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
What I'm doing wrong?

I remember having similar issue. It might be related to ulimit - number of allowed opened files. ClassLoader needs to open file for loading. Since class is not loaded/available NoClassDefFoundError is thrown on method call.
Check how many files can be opened:
ulimit -a
To increase number of opened files:
ulimit -n NEW_NUMBER
In order to change it permanently follow instructions from this link
Follow the steps:
vi /etc/security/limits.conf and add below the mentioned
soft nofile 65535
hard nofile 65535

It was an ussue with cobertura itself (-Dcobertura.test=true). Activating it resolved the Problem.

Related

Springboot maven plugin to build and deploy images to gitlab is showing published 42 years ago

I am using spring-boot-maven-plugin with the following profile
<profiles>
<profile>
<id>ci</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<goals>
<goal>build-info</goal>
<goal>build-image</goal>
</goals>
<configuration>
<image>
<name>${env.DOCKER_IMAGE_PATH}/core:${env.CI_COMMIT_SHORT_SHA}</name>
<publish>true</publish>
</image>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
The image could be built and uploaded to gitlab. However, it is always showing Published 42 years ago.
Any idea?
It looks it is related to Reproduible Builds
https://github.com/GoogleContainerTools/jib/blob/master/docs/faq.md#why-is-my-image-created-48-years-ago

How to run a plugin only on a particular platform

I have a maven plugin that only needs to execute on linux. I found this configuration that seems to work
How do I make this plugin run only on non-Windows platforms?
<profiles>
<profile>
<activation>
<os>
<family>!mac</family>
</os>
</activation>
<build>
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
...
</profile>
</profiles>
How do I modify it so that it executes only on linux?
There is no OS <family> value that distinguishes Linux from Unixes, but you can use <name> instead.
<profiles>
<profile>
<activation>
<os>
<name>Linux</name>
</os>
</activation>
<build>
<plugins>
<plugin>
...
</plugin>
</plugins>
</build>
...
</profile>
</profiles>
FYI, to double-check the value for <name> on your Linux machine, execute java -XshowSettings:properties and look for the os.name property. (On all Linux distributions I have checked, this is just Linux.)

How to disable hostname verification or allow all certificates when using maven-jaxb2-plugin?

Currently, I'm using the maven-jaxb2-plugin to generate Java artefacts while consuming a soap web services via SSL. I configured my pom.xml per the answer here. But the certificate I used didn't contain any DNS/IP subjects of server. Then there will be some javax ssl exceptions for no alternative name for IP address if my wsdl url is like 'https://XXX.XXX.XXX.XXX:9443/services/testWS?wsdl' in pom.xml. Is there any way to configure jaxb to disable the hostname verification? Thanks.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
<configuration>
<properties>
<property>
<name>javax.net.ssl.keyStore</name>
<value>${basedir}/src/test/key.jks</value>
</property>
<property>
<name>javax.net.ssl.keyStorePassword</name>
<value>changeit</value>
</property>
</properties>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<id>testproxy.wsdl</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>my.wsdl.testproxy</generatePackage>
<schemas>
<schema>
<url>http://XXX.XXX.XXX.XXX:9443/services/testWS?wsdl</url>
</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I generally don't recommend builds which depend on online resources of any kind. Consider making a local copy of the WSDL you want to compile and use a catalog file to rewrite the URI of the online resource to a local resource.
Disclaimer: I'm the author of the maven-jaxb2-plugin.

jaxb2 goal is not invoked

I am using maven-jaxb2-plugin to generate some classes from xsd.
It is defined in child pom as follows:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>jaxb2-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<forceRegenerate>true</forceRegenerate>
<!-- Generate classes from XSD (XML Schema) using JAXB -->
<schemaDirectory>src/main/resources/com/reportcenter/settings/</schemaDirectory>
<generatePackage>com.reportcenter.settings</generatePackage>
<schemaIncludes>
<include>**/*.xsd</include>
</schemaIncludes>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
<arg>-Xcopyable</arg>
</args>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The problem is the jaxb2 is not called from mvn install or mvn compile or mv generate-sources.
If I call mvn jaxb2:generate (as the name of the goal) the classes are created OK.
I looked at some questions here and used the answers provided, but I am still missing something.
Thank you.
Disclaimer: I am the author of the maven-jaxb2-plugin.
Seems like you only configure the plugin in pluginManagement but don't actualy use it in your build part.
This is how it should look like:
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
Few other comments on your configuration:
0.8.0 is a very old version, 0.12.3 is the actual one.
With modern Maven you no longer need to configure maven-compiler-plugin with source/target version 1.6.
Do not use forceRegenerate.
Consider using binding files instead of generatePackage.
Current version of jaxb2-basics is 0.9.2.
I ran into an error related to this plugin, and the Eclipse Maven integration.
Most searches for an answer were fruitless, but often lead to this thread. So, I'm going to post the issue, and a workaround here, for any others that run into it.
While using the maven-jaxb2-plugin:0.12.3 plugin correctly in maven on the command line - in Eclipse, source generation would fail with the following error:
Execution default of goal
org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate failed: A
required class was missing while executing
org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.12.3:generate:
com/sun/xml/bind/api/ErrorListener
Various attempts at adding jar files that contain the class it was looking for would just result in another class missing, going to a rabbit hole of jar file hell and mis-matched classes that wasn't resolvable.
I don't know if the problem here is something that is broken in the Eclipse / M2E integration, or if the problem is in the dependency stack of maven-jaxb2-plugin.
But the solution is to launch Eclipse itself (not the JREs / JDKs installed into eclipse) with a JDK, instead of a JRE.
The easiest way to do that is to add -vm parameter to your eclipse.ini file:
-startup plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
-vm C:\Program Files\Java\jdk1.8.0_31\bin\javaw.exe
--launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20150204-1316
-product
...snip...
Upgrade to version 0.13.2 +
Kudos to #lexicore for the comment below

How to set an environment variable in maven depending on the OS

I am fairly new to maven. I have setup a pom.xml which defines a profile for running my unit tests. I am trying to set Path environment variable. The env variable name is Path for Windows and LD_LIBRARY_PATH for Linux. I don't want to keep on changing these env. variable names depending on the OS. How should I achieve this?
<profile>
<id>integration-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tychoVersion}</version>
<configuration combine.self="override">
<argLine>${tycho.testArgLine} ${global.test.vmargs} ${bundle.test.vmargs}</argLine>
<forkMode>${bundle.test.forkMode}</forkMode>
<useUIHarness>${bundle.test.useUIHarness}</useUIHarness>
<useUIThread>${bundle.test.useUIThread}</useUIThread>
<environmentVariables>
<!--For windows change LD_LIBRARY_PATH to PATH-->
<LD_LIBRARY_PATH>${dependenciesDir}${path.separator}{env.LD_LIBRARY_PATH}</LD_LIBRARY_PATH>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Profile activation might help here. Remove the <environmentVariables> config from the integration tests profile. Then add the profiles below, tweaking the <activation> sections to meet the specific requirements. You do not need to explicitly enable these profiles on the command line; Maven will activate the right profile based on which system is running the build.
<profile>
<id>windows-tests</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tychoVersion}</version>
<configuration>
<environmentVariables>
<PATH>${dependenciesDir}${path.separator}{env.PATH}</PATH>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>linux-tests</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tychoVersion}</version>
<configuration>
<environmentVariables>
<LD_LIBRARY_PATH>${dependenciesDir}${path.separator}{env.LD_LIBRARY_PATH}</LD_LIBRARY_PATH>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>

Resources