How do you configure a Maven/SpringBoot Project's pom.xml for docker? - maven

I am attempting to dockerize my SpringMVC application via Maven. My intent is to have an image that I can then proceed to expose and display via my web browser.
Unfortunately, in following this guide, I appear to still lack a critical piece of understanding concerning the pom.xml edits I must make to achieve this, and the Dockerfile.
======
Here is the Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
======
Here is the source code's pom.xml in its latest revision.
======
Here is my latest attempt at revision, in following the example pom.xml of the SpringIO guide I referenced above (dependencies section not included).
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.davidonus</groupId>
<artifactId>davidonusSpringDemo1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- tag::packaging[] -->
<packaging>jar</packaging>
<name>davidonusSpringDemo1</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<!-- tag::docker[] -->
<docker.image.prefix>springio</docker.image.prefix>
</properties>
<profiles>
<profile>
<id>DavidSpringTime</id>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
</configuration>
</plugin>
<!-- end::plugin[] -->
<!-- tag::unpack[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- end::unpack[] -->
</plugins>
</build>
Here are my present results, using the command mvn install build:docker
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.050 s
[INFO] Finished at: 2019-06-15T13:24:01-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:unpack (unpack) on project davidonusSpringDemo1: Unable to update Marker timestamp: /home/david/Desktop/DevOps2019/springBoot/teluskoSpringBoot/target/dependency-maven-plugin-markers/com.davidonus-davidonusSpringDemo1-jar-0.0.1-SNAPSHOT.marker: Unable to update last modified timestamp on marker file /home/david/Desktop/DevOps2019/springBoot/teluskoSpringBoot/target/dependency-maven-plugin-markers/com.davidonus-davidonusSpringDemo1-jar-0.0.1-SNAPSHOT.marker -> [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
======
In summary, given my original pom.xml, what changes would you implement to make my SpringBoot + Maven project deployable as a docker image and container?
Furthermore, are there adaptions to my Dockerfile that you'd make? Your consultation is appreciated. Thank you.

If you have your springboot code ready with pom.xml. Then follow below steps to containerize your application.
git clone https://github.com/dnmorris7/teluskoSpringBoot (I'm cloning your springboot code)
git checkout module5 (checked out module5 branch)
Created Dockerfile in your git codebase with following contents:
FROM maven:3.6-jdk-8-slim AS build
COPY . /usr/src/app/
WORKDIR /usr/src/app/
RUN mvn -f /usr/src/app/pom.xml clean package
FROM java:8-alpine
WORKDIR /
COPY --from=build /usr/src/app/target/*.jar /app.jar
CMD java -jar app.jar
NOTE: I'm using docker multi-stage build where in first stsage maven builds the jar and in the second stage we copy that jar in java image.
Now build your docker image docker build -t appimage:v1 .
Run your docker container docker run -it -d -p 9090:9090 appimage:v1
Hit the api to check if its working fine.
$ curl localhost:9090/home
{"timestamp":"2019-06-16T05:34:26.655+0000","status":404,"error":"Not Found","message":"/pages/home.jsp","path":"/home"}
Please hit the correct base url, I tried with /home
NOTE: If you want to provide your own custom application.properties then change the java -jar command in Dockerfile to CMD java -jar app.jar --spring.config.additional-location=application.properties and change the docker run command to docker run -it -d -v application.properties:/application.properties -p 9090:9090 appimage:v1 where application.properties is the one which you provide from outside.

I think not much is missing. Or even better there may be even too many things.
First, you need to tell the docker maven plugin to run. The maven lifecycle defines which plugins run at what phase. So all other plugins need an execution configuration somewhere (in a parent pom or in yours). Second, there is no need to unpack the created jar file. Spring Boot will create an executable jar file automatically. You only need to tell the docker maven plugin about it (where it is created)
This would be the Dockerfile:
FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/myapp.jar
ENTRYPOINT ["java","-jar","/usr/share/myapp.jar"]
And this your pom:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-spring-boot-docker</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<name>Spring Boot Docker</name>
<description>Getting started with Spring Boot and Docker</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath />
</parent>
<properties>
<docker.image.prefix>springio</docker.image.prefix>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.9</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
The unpack goal of the dependency plugin can be removed. This way the jar is added into the image and run directly. Hope it works!

Related

Quarkus: Try to cache maven dependencies using multistage docker build

I have got a simple Quarkus application and I try to build it using the following multistage Dockerfile.
FROM maven:3-jdk-8-slim AS build
WORKDIR /build
# Download Dependencies
COPY pom.xml .
RUN mvn dependency:go-offline
# Build App
COPY src/ /build/src/
RUN mvn -Dmaven.test.skip=true package -Dcheckstyle.skip
# Stage 2 : create the docker final image
FROM adoptopenjdk:8-jre-openj9 AS runtime
COPY --from=build /build/target/*-runner.jar /app/app.jar
COPY --from=build /build/target/lib/* /app/lib/
WORKDIR /app
RUN chgrp -R 0 /app &&\
chmod g=u /app
USER 1001
EXPOSE 8080
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
and the pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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.test</groupId>
<artifactId>booking-mgr</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.1.1.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.1.1.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
The build works fine, it downloads the maven dependencies, then it creates the .jar and runs the .jar in the final container. But if I change something in the source code and leave the pom.xml untouched, the dependencies are downloaded again. It seems that mvn dependency:go-offline does not download all dependencies.
Is there a way to speed up docker builds that way? For example, I do the same with Spring Boot and everything works great there.
Thank you for your help.
Your pom.xml and src folder are in the build context (the dot in your command).
If you change files in src then you change your build context so you invalidate the COPY cache.
See Docker build is not using cache
Simply, you can split the Dockerfile into two, such as builder-base.dockerfile and final.dockerfile. Then, create a directory builder-base and move pom.xml into builder-base.
directory structure:
.
+-- builder-base
| +-- pom.xml
|-- src
|-- builder-base.dockerfile
|-- final.dockerfile
In the final.dockerfile is :
FROM java-builder AS build
# Build App
COPY src/ /build/src/
RUN mvn -Dmaven.test.skip=true package -Dcheckstyle.skip
# Stage 2 : create the docker final image
FROM adoptopenjdk:8-jre-openj9 AS runtime
COPY --from=build /build/target/*-runner.jar /app/app.jar
COPY --from=build /build/target/lib/* /app/lib/
WORKDIR /app
RUN chgrp -R 0 /app &&\
chmod g=u /app
USER 1001
EXPOSE 8080
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app/app.jar"]
First, put this code into builder-base.dockerfile:
FROM maven:3-jdk-8-slim
WORKDIR /build
# Download Dependencies
COPY pom.xml .
RUN mvn dependency:go-offline
So, at first, you should build a image named 'java-builder'
docker build -t java-builder -f builder.dockerfile ./builder-base
Now, you can compile the source code use the command below:
docker build -t app -f final.dockerfile .
The base image in the final.dockerfile is java-builder, if you don't re-build the image, you can always create the docker final image using the cache.
I found mvn package will do the work.
Now I use:
COPY pom.xml .
RUN mvn --batch-mode \
--quiet \
--errors \
dependency:go-offline \
package
COPY src ./src
RUN mvn --batch-mode \
--quiet \
--errors \
--define maven.test.skip=true \
--define java.awt.headless=ture \
clean package
Looks weird, but no errors.

Running Payara Micro from Maven: "Deployed 0 archive(s)"

I am trying to set up an Eclipe MicroProfile Application with Maven. I generated the archive with the MicroProfile Starter at start.microprofile.io, which generates the following pom:
<?xml version="1.0" encoding="UTF-8"?>
<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>de.javahippie.playground</groupId>
<artifactId>config_api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
<profiles>
<profile>
<id>payara-micro</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>fish.payara.maven.plugins</groupId>
<artifactId>payara-micro-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<payaraVersion>5.191</payaraVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I tried to start the application from Maven, as stated by the documentation: mvn package payara-micro:start, and Payara does not seem to find my packaged WAR file:
[2019-04-07T10:21:56.358+0200] [] [INFORMATION] [] [PayaraMicro] [tid: _ThreadID=1 _ThreadName=main] [timeMillis: 1554625316358] [levelValue: 800] Deployed 0 archive(s)
However, if I run this command from my projects' target folder, everything works as expected: java -jar config_api-microbundle.jar.
I would prefer bundling and starting the application with maven a lot, how can I achieve this?
Generated Payara Micro application from https://start.microprofile.io can be started using bundled Payara Micro uber jar with the following instructions :
The generation of the executable jar file can be performed by issuing the following command
mvn clean package
This will create an executable jar file demo-microbundle.jar within the target maven folder. This can be started by executing the following command
java -jar target/demo-microbundle.jar
To launch the test page, open your browser at the following URL
http://localhost:8080/index.html
And If you want to start Payara Micro instance from war, You may set deployWar property value to true:
<plugin>
<groupId>fish.payara.maven.plugins</groupId>
<artifactId>payara-micro-maven-plugin</artifactId>
<version>1.0.4</version>
<configuration>
<payaraVersion>5.191</payaraVersion>
<deployWar>true</deployWar>
</configuration>
</plugin>

Fabric8 Docker Maven plugin not working for compose.yml on Multi module project

I trying to use Fabric8 docker-maven-plugin, though I was successful in configuring plugin for individual module and run docker:build docker:start Maven goal without using docker-compose.yml, however I needed externalize ports and link the different module, hence I intended to use docker-compose.yml. Below is my project structure.
--kp-parent
|
--- docker-compose.yml
--- pom.xml
|
---- rest1
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
---- rest2
| |
| -- .maven-dockerignore
| -- pom.xml
| -- Dockerfile
Here are my configurations
Dockerfile[both rest1 and rest2 use identical file except the different port]
FROM openjdk:8-jdk-alpine
MAINTAINER 'Karthik Prasad'
ARG IMAGE_VERSION
ARG JAR_FILE
ENV JAVA_OPTS=""
LABEL version = IMAGE_VERSION
VOLUME /tmp
ADD /maven/${JAR_FILE}.jar app.jar
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
EXPOSE 8000
.maven-dockerignore[In both child modules identical file]
target/**
pom.xml [Both rest1 and rest2 pom files are same except the artifcatid and name of the project]
<?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>
<artifactId>rest2</artifactId>
<packaging>jar</packaging>
<name>rest2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>com.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- https://mvnrepository.com/artifact/io.fabric8/docker-maven-plugin -->
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
<images>
<image>
<external>
<type>compose</type>
<basedir>../</basedir>
<ignoreBuild>true</ignoreBuild>
</external>
</image>
</images>
</configuration>
</plugin>
</plugins>
</build>
</project>
parent 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>com.kp.swasthik</groupId>
<artifactId>kp-docker-multimodule-fabric8-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>kp-docker-multimodule-fabric8-parent</name>
<description>Microservice Parent Pom file</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<modules>
<module>rest1</module>
<module>rest2</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<docker.image.prefix>kp-ms</docker.image.prefix>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.22.1</version>
<configuration>
<skip>true</skip>
<images>
<image>
<alias>${project.artifactId}</alias>
<name>${docker.image.prefix}/${project.artifactId}:${project.version}</name>
<build>
<dockerFileDir>${project.basedir}</dockerFileDir>
<assembly>
<inline>
<id>default</id>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</inline>
</assembly>
</build>
</image>
</images>
<buildArgs>
<IMAGE_VERSION>${project.version}</IMAGE_VERSION>
<JAR_FILE>${project.artifactId}-${project.version}</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
And finally docker-compose.yml
version: '2'
services:
rest1:
image: kp-ms/rest1:0.0.1-SNAPSHOT
ports:
- 8000:8000
rest2:
image: kp-ms/rest2:0.0.1-SNAPSHOT
ports:
- 8001:8001
links:
- rest1
When I run the docker:build docker:start I get below error.
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.22.1:start (default-cli) on project rest1: I/O Error: Unable to pull 'kp-ms/rest2:0.0.1-SNAPSHOT' : repository kp-ms/rest2 not found: does not exist or no pull access (Not Found: 404) -> [Help 1]
[ERROR]
However If I remove rest2 section in docker-compose.yml, build goes fine and I'm able to find the container start successfully.
Another problem I noticed is that even if do not give image name in docker-compose.yml build fails with error image is null. However I'm not sure why I need to provide image can't the plugin map from plugin configuration as I had provided alias. As you can notice I'm trying to generate image name dynamically.

Maven configuration on new machine

I work in a small lab, we have 2 machines with intellij, svn and maven used to develop. I have been tasked with configuring a 3rd machine for development.
Id like some guidance as to how to do this. I have svn checkout and have all the files and the project is open in intellij:
--main:
--java:
--ca:
--virology:
--src:
pom.xml
And my pom.xml looks like:
<?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>
<parent>
<groupId>ca.virology</groupId>
<artifactId>virology-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>ca.virology</groupId>
<artifactId>gatu</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>ca.virology</groupId>
<artifactId>virology-lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.virology</groupId>
<artifactId>base-by-base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.virology</groupId>
<artifactId>vgo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.virology</groupId>
<artifactId>jdotter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ptolemy</groupId>
<artifactId>ptolemy2</artifactId>
<version>0</version>
</dependency>
<dependency>
<groupId>ca.virology</groupId>
<artifactId>virology-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.biojava</groupId>
<artifactId>core</artifactId>
<!--virology-lib used 1.4, 1.8.2 is most recent-->
<version>1.8.2</version>
</dependency>
<!-- this is only in the local repository because the only available maven versions do not contain the classes we need-->
<!-- use "mvn install:install-file -DgroupId=org.ggf.drmaa -DartifactId=drmaa -Dversion=0 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
<dependency>
<groupId>org.ggf.drmaa</groupId>
<artifactId>drmaa</artifactId>
<version>0</version>
</dependency>
<!-- this is only in the local repository because a maven version does not exist-->
<!-- use "mvn install:install-file -DgroupId=javax.jnlp -DartifactId=jnlp -Dversion=0 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
<dependency>
<groupId>javax.jnlp</groupId>
<artifactId>jnlp</artifactId>
<version>0</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
</dependency>
<!-- this is only in the local repository because a maven version does not exist-->
<!-- use "mvn install:install-file -DgroupId=pal -DartifactId=pal -Dversion=1.5 -Dpackaging=jar -Dfile=/path/to/file.jar" to install the file to your local repository if necessary-->
<dependency>
<groupId>pal</groupId>
<artifactId>pal</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-apache-oro</artifactId>
<version>1.9.2</version>
</dependency>
<!--Intellij GUI-->
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>6.0.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>ca.virology.gatu.GenomeAnnotator</mainClass>
</manifest>
<manifestEntries>
<Permissions>all-permissions</Permissions>
<Codebase>*</Codebase>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>xerces:xercesImpl</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
intellij complains about maven "Unable to import maven project: See logs for details" (not sure where log is either :/)
when i cd into ../pom.xml and run mvn install it spits out
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 7, column 13
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project ca.virology:gatu:1.0-SNAPSHOT (/Users/chadsmit/Desktop/Developement/repo/gatu/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 7, column 13 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
My guess is that there are certain .jar files missing in the .m2 folder, but how do i tell maven to look for them there if i copy them from another machine?
EDIT: The jars from the new machines have been copied and dont seem to be causing problems. The pom.xml has been changed to include :
<parent>
<groupId>ca.virology</groupId>
<artifactId>virology-parent</artifactId>
<version>1.0</version>
<relativePath>/Users/chadsmit/.m2/repository/ca/virology/virology-parent/1.0/virology-parent-1.0.pom</relativePath>
</parent>
and yet maven is still trying to download it from elsewhere:
[FATAL] Non-resolvable parent POM for ca.virology:gatu:1.0-SNAPSHOT: Failure to find ca.virology:virology-parent:pom:1.0 in https://repo.maven.apache.org>/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced and 'parent.relativePath' points at wrong local POM # line 7, column 13
Any insights? i feel as though im missing something important
Did you do a new installation of maven on the 3rd machine or you copied the maven folder from the previous two machines. If you installed a new version than you also need to take a look at the settings.xml file in the .m2 folder on the previous machines. It may be a possibility that the repositories configured in the settings.xml file on those machines are not present on settings.xml on the third machine.
If your parent project is not on the local maven repository, then you can also add relativePath in entry for parent like this:
<parent>
<groupId>com.test</groupId>
<artifactId>test-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>{path to}/test-artifact/pom.xml</relativePath>
</parent>
Also, you need to check if intellij is pointing to the maven installation you copied from the previous machines. It is a possibility that Intellij is pointing to built in maven setup.
Run mvn clean install from the project folder.
Just check once your svn has not changed the version of the parent specified here on line number 7 virology-parent, instead try something like ${project.version} in the version for the module
In case you have the jar-files locally, you might be able to [edited]
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=ca.virology -DartifactId=virology-parent \
-Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file
(and have you tried the -offline switch to maven?)

Maven Jboss plugin configuration for a multi-module project having a child module as WAR

I am working on a maven multi-module project having the following folder structure.
+---parent_module
+---module1
+---module2
+---module_web
How do I configure 'jboss-as-maven-plugin' for a local and remote deploy? Note that I want to deploy the child module_web which is the WAR residing inside the parent_module. I ran command 'mvn clean install' and the build completed successfully and the module_web.war file was created.
Then I ran the mvn command 'mvn -e -X package jboss-as:deploy' from parent_module to deploy the WAR to the jboss container, I get the following error.
[INFO]
------------------------------------------------------------------------ [ERROR] Failed to execute goal
org.jboss.as.plugins:jboss-as-maven-plugin:7.4.Final:deploy
(default-cli) on project markodojo: Could not execute goal deploy on
C:\Mahesh\Git\markodojo\markodojo\target\markodojo_solution-1.0-SNAPSHOT.war.
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:8080. The connection timed out
[ERROR] -> [Help 1]
Below are the snippets from the pom.xml files.
Parent module pom.xml
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
<module>module_web</module>
</modules>
<properties>
.....
</properties>
<dependencyManagement>
.....
</dependencyManagement>
<build>
<directory>${project.basedir}/target</directory>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- JBoss AS plugin to deploy war -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.4.Final</version>
<!-- inherited>true</inherited-->
<configuration>
<jbossHome>C:\folderpath\jboss-as-7.1.1.Final</jbossHome>
<serverName>standalone</serverName>
<hostname>localhost</hostname>
<port>8080</port>
<filename>module_web-1.0-SNAPSHOT.war</filename>
</configuration>
</plugin>
other plugins...
<plugins>
</build>
module1 pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
<packaging>jar</packaging>
<name>module1</name>
module2 pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<packaging>jar</packaging>
<name>module2</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<version>${project.version}</version>
</dependency>
other dependencies ...
</dependencies>
module_web pom.xml
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>module_web</artifactId>
<packaging>war</packaging>
<name>module_web</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
other dependencies ...
</dependencies>
Can anyone please let me know what am I doing wrong with the plugin configuration? It would be of great help if you share any tutorial or maven-jboss document which explains the steps to configure the maven-jboss plugin for a multi-module project having a child module as WAR.
Thanks.

Resources