fabric8 maven plugin configuration with image running Java > 8 - openshift

I am using fabric8 maven plugin to deploy a vertx application into Openshift. My application is running with Java 11.
However, by default, the fabric8 maven plugin uses a Java 8 Docker image to create my vertx application image.
How is it possible to configure fabric8 maven plugin to use a Java 11 image ? Does it provide other images for Java > 8 ?

I fixed it for my Spring Boot application by adding from configuration to the generator. For vert.x the solution could look like this:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.5.42</version>
<configuration>
<generator>
<config>
<vertx>
<from>fabric8/s2i-java:3.0-java11</from>
</vertx>
</config>
</generator>
</configuration>
</plugin>
Which tags are available for the s2i image can be looked up at the Docker Hub page: https://hub.docker.com/r/fabric8/s2i-java/tags

for me this solution from above didn't help but thanks of that! I've found out that I've to declare image in my profile definition. I'm running my openshift build like this: mvn clean fabric8:deploy -P openshift
What help me a lot was adding this to profile:
<properties>
<fabric8.generator.fromMode>docker</fabric8.generator.fromMode>
<fabric8.generator.from>fabric8/s2i-java:3.0-java11</fabric8.generator.from>
</properties>
Below part of my pom.xml have a look profile definition
<properties>
...
<java.version>11</java.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<fabric8-maven-plugin.version>4.4.1</fabric8-maven-plugin.version>
</properties>
<dependencies>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>openshift</id>
<properties>
<fabric8.generator.fromMode>docker</fabric8.generator.fromMode>
<fabric8.generator.from>fabric8/s2i-java:3.0-java11</fabric8.generator.from>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>0.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>${fabric8-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<enricher>
<config>
<f8-healthcheck-vertx>
<readiness>
<path>/actuator/health</path>
</readiness>
<liveness>
<path>/actuator/health</path>
</liveness>
</f8-healthcheck-vertx>
</config>
</enricher>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

Related

Maven run does not include Junit tests

I am trying to run tests by running the maven (pom.xml) file.
All I get is that the tests were not ran:
the pom includes the following:
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
<defaultGoal>test</defaultGoal>
</build>
for some reason, it wouldn't pick up the tests:
#Test
public void testMultiply() {
MathUtils mathUtils = new MathUtils();
assertEquals(0, mathUtils.add(-1, 1),
"Add method should return the sum of two numbers");
}
I can't find any thing wronge with the pom.xml.
Any suggestion?
project on github: https://github.com/subhisamara/Junit-maven-selenium
Add these plug-ins to your pom.xml file:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!--
default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging
-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
Run by this command: mvn test

Jersey - Maven - MessageBodyWriter not found for media type=application/json

Currently i have the problem that everything in Netbeans my webservice works but if i start the jar file with the command "java -jar FILENAME PARAMETERS there is the following error.
MessageBodyWriter not found for media type=application/json, type
=class java.util.ArrayList, genericType=java.util.List
I need an expert do solve this problem :/. It is very strange because when i execute the jar in Netbeans it works.
pom.xml
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>at.schneider.development</groupId>
<artifactId>PhotoBoothImageService</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>PhotoBoothImageService</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>[0.4, 0.5)</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>at.schneider.development.photoboothimageservice.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<jersey.version>2.26-b02</jersey.version>
<jdk.version>1.8</jdk.version>
</properties>
Function:
#GET
#Path("/getimages")
#Produces(MediaType.APPLICATION_JSON)
public List<Image> getImages() {
availableImages = getImageListFromDirectory(Paths.get(configuration.getProperties().get(BASE_DIR).toString()));
return availableImages;
}
Thanks in advice!
Best Regards
I found the answer in comment by Supercop89:
jersey-media-json-jackson has to be the first dependency.
Because maven-assembly-plugin squashes META-INF/services files, it seems the JacksonAutoDiscoverable SPI is gone.
By putting the dependency jersey-media-json-jackson at the top, it ends-up in a better state.
Here is a diff:
JSON FEATURES NOT WORKING
META-INF/services/org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable
JSON FEATURES WORKING
META-INF/services/org.glassfish.jersey.logging.LoggingFeatureAutoDiscoverable:
org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable
So, putting the dependency at the top will make Json features work, at the expense of some other stuff that you (maybe) don't need.
There are some ways to merge the services in maven-assembly-plugin: Merging META-INF/services files with Maven Assembly plugin
See also: https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/using-container-descriptor-handlers.html
EDIT: I played a lot with maven-assembly-plugin as described in the links, but wasn't able to make that work. Eventually, I switched to maven-shade-plugin and it worked on my first try. It also displays information on what it does:
[INFO] Including org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.28 in the shaded jar.
If maven-assembly-plugin had done so, I wouldn't have to search for the problem for 1 hour. Also, it didn't need a bunch of xml. Personal conclusion: much easier with the latter.

Maven and mysql dependency

I currently have a project in which there is a build.xml. In this build, there is the command CreateDB, which calls something.jar. This jar run some sql script (mysql db). So, right now, I can run that command by executing
ant CreateDB
from the command line. But now, I need to do something more. When I am building my application (using Maven), I want to run that ant command. So, I create this pom.xml (see below), but it doesn't work, I got this error :
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.gjt.mm.mysql.Driver'
According to this message, it seems that I don't have the connector for mySql, but I specified it in my dependency. So, what I did wrong ?
Pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dl.test</groupId>
<artifactId>toto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>toto</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.23</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>mysql</id>
<phase>integration-test</phase>
<configuration>
<tasks>
<!-- For MySql -->
<ant antfile="path\build.xml" target="createDB" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The ant task launched by the maven antrun plugin does not inherit the maven dependencies automatically.
You have to reference the maven test classpath explicitly in your build.xml code, which is available through the maven.test.classpath property.
So your execution might look similar to the following (test.classpath also needs to referenced in your build.xml):
<execution>
<id>mysql</id>
<phase>integration-test</phase>
<configuration>
<tasks>
<!-- For MySql -->
<property name="test_classpath" refid="maven.test.classpath"/>
<ant antfile="path\build.xml" target="createDB" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
See also: Maven AntRun Plugin - Referencing the Maven Classpaths

Scalatest html reports

I'm trying to get an html report of the scalatest and I've found a lot of configurations like this:
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0-M2</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<testFailureIgnore>true</testFailureIgnore>
<filereports>NCXEHLOWFD file/constrained.txt,file/full.txt</filereports>
<xmlreports>xml</xmlreports>
<htmlreports>html/report.html</htmlreports>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
But IntelliJ tells me that xmlreports and htmlreports are not allowed, and no xml or html reports are generated.
Can anyone suggest anything?
I'll be very thankful
You need to use the latest plugin version currently available 1.0-M4-SNAP1 instead of 1.0-M2 which doesn't have htmlreports property. Here are important part from my pom.xml:
<project>
<properties>
<scala.version>2.9.3</scala.version>
<scalatest.version>2.0.M5b</scalatest.version>
<scalatest.plugin.version>1.0-M4-SNAP1</scalatest.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>${scalatest.plugin.version}</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<junitxml>.</junitxml>
<filereports>WDF TestSuite.txt</filereports>
<htmlreporters>${project.build.directory}/html/scalatest</htmlreporters>
<testFailureIgnore>false</testFailureIgnore>
</configuration>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.version}</artifactId>
<version>${scalatest.version}</version>
<scope>test</scope>
</dependency>
<!-- required by scalatest-maven-plugin to generate HTML report -->
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.2.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
With this setting I can run mvn clean install and it will produce nice HTML report under ${project.build.directory}/html/scalatest
#rozky's solution works for me but the css is awkward. It doesn't display the table correctly. It doesn't show me the suite name column in the table no matter what version of pegdown and scalatest-maven-plugin I use :/

NetBeans: Re-run Maven with the -e switch on / PluginResolutionException

i have no clue about Maven and Netbeans,
i updated my netbeans and now my test is not working anymore:
Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to central (http://repo1.maven.org/maven2): pr-dfs-bank- 00.emea.isn.corpintra.net: Unknown host pr-dfs-bank-00.emea.isn.corpintra.net -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
How can i activate the -e or -X switch using netbeans, i saw many examples with "mvn clean" and so on, but I installed Maven via Netbeans so i dont have it on a folder for command line.
I dont get the error message and wanna check out a more detailed log.
I searched my code for this pr-dfs-bank-00.emea.isn.corpintra.net mentioned in the error message, but it is not part of my source code.
My pom.xml, its supposed to be Maven2 and Selenium
<?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>
<version>1.0</version>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>http://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<properties>
<maven.build.timestamp.format>yyMMdd-HHmm</maven.build.timestamp.format>
<project.build.sourceEncoding>windows-1252</project.build.sourceEncoding>
<lfadapter>${project.basedir}/../lib/lf_CAdapter-4.0.jar</lfadapter>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-ie-driver</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8-beta5</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>src/</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<failOnError>false</failOnError>
<debug>true</debug>
<verbose>true</verbose>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<disableXmlReport>false</disableXmlReport>
<forkMode>always</forkMode>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<failIfNoTests>false</failIfNoTests>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<workingDirectory>reports/${maven.build.timestamp}/</workingDirectory>
<reportsDirectory>reports/surefire/</reportsDirectory>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</reporting>
<properties>
<property>
<name>showSuccess</name>
<value>true</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>testng-suite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>netbeans-private-testng</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>netbeans.testng.action</name>
</property>
</activation>
</profile>
</profiles>
</project>
I think my pom.xml is not really the way its supposed to be :(
Any help is appreciated :)
NetBeans 6.9.1 - Mac OS X
To activate the switches you need through Netbeans, go to Preferences --> Miscellaneous --> Maven, then enter the following under Global Execution Options:
--debug --errors
NetBeans - Windows
Add debug and errors to Maven in NetBeans (from version 7.3 at up) as follows:
Click Tools.
Click Options.
Click the Java icon.
Click the Maven tab.
Append to Global Execution Options: --debug --errors
Click OK.
Maven will execute the application with debug and error information included.
most likely you have a mirror or proxy defined in one of the maven's settings.xml files (eg. in ~/.m2/settings.xml) and the definition is wrong? like pointing to a wrong server?
In Netbeans 8.0.2 you define this on the project properties->Actions
Then select the action where you want to specify the arguments to pass
On netbeans 8.2,
Tools > Options > (see below figure)
enter "maven" in the search box
type "--debug --errors" in the "Global ...".