Maven configuration on new machine - maven

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?)

Related

Plugin org.apache.maven.plugins: dependencies could not be resolved

I am trying to build a simple web API using dynamic web maven project.
When I run my project as maven project with the goals of clean install. I get this error:
Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Cannot access https://repo.maven.apache.org/maven2 with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access https://repo.maven.apache.org/maven2 using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
role: org.apache.maven.wagon.Wagon
Here is my POM file, it might be useful as it is where the dependencies are stated:
POM File
<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>group5</groupId>
<artifactId>studentService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.rpc/javax.xml.rpc-api -->
<dependency>
<groupId>javax.xml.rpc</groupId>
<artifactId>javax.xml.rpc-api</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
I am aware of this question: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved
However the proxy solution did not work for me. (I have never made a proxy before).
Any help appreciated.

maven compile error - [ERROR] Non-resolvable import POM: Could not transfer artifact

New to Maven, possible newbie error.
I am doing the pluralsight introduction to jenkins course. in it we clone the git repository http://github.com/g0t4/jenkins2-course-spring-boot in its subdirectory jenkins2-course-spring-boot\spring-boot-samples\spring-boot-sample-atmosphere there is the following pom.xml file:
<?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>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-atmosphere</artifactId>
<name>Spring Boot Atmosphere Sample</name>
<description>Spring Boot Atmosphere Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>atmosphere-javascript</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
when I try to compile with mvn compile, I get the following build log with errors:
[INFO] Scanning for projects...
Downloading from spring-snapshots: http://repo.spring.io/snapshot/org/springframework/spring-framework-bom/4.3.2.BUILD-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata org.springframework:spring-framework-bom:4.3.2.BUILD-SNAPSHOT/maven-metadata.xml from/to spring-snapshots (http://repo.spring.io/snapshot): Authorization failed for http://repo.spring.io/snapshot/org/springframework/spring-framework-bom/4.3.2.BUILD-SNAPSHOT/maven-metadata.xml 403 Forbidden
Downloading from spring-snapshots: http://repo.spring.io/snapshot/org/springframework/spring-framework-bom/4.3.2.BUILD-SNAPSHOT/spring-framework-bom-4.3.2.BUILD-SNAPSHOT.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:4.3.2.BUILD-SNAPSHOT from/to spring-snapshots (http://repo.spring.io/snapshot): Authorization failed for http://repo.spring.io/snapshot/org/springframework/spring-framework-bom/4.3.2.BUILD-SNAPSHOT/spring-framework-bom-4.3.2.BUILD-SNAPSHOT.pom 403 Forbidden # org.springframework.boot:spring-boot-dependencies:1.4.0.BUILD-SNAPSHOT, C:\JenkinsTryOut\jenkins2-course-spring-boot\spring-boot-dependencies\pom.xml, line 2058, column 16
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-websocket:jar is missing. # line 46, column 15
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.springframework.boot:spring-boot-sample-atmosphere:1.4.0.BUILD-SNAPSHOT (C:\JenkinsTryOut\jenkins2-course-spring-boot\spring-boot-samples\spring-boot-sample-atmosphere\pom.xml) has 2 errors
[ERROR] Non-resolvable import POM: Could not transfer artifact org.springframework:spring-framework-bom:pom:4.3.2.BUILD-SNAPSHOT from/to spring-snapshots (http://repo.spring.io/snapshot): Authorization failed for http://repo.spring.io/snapshot/org/springframework/spring-framework-bom/4.3.2.BUILD-SNAPSHOT/spring-framework-bom-4.3.2.BUILD-SNAPSHOT.pom 403 Forbidden # org.springframework.boot:spring-boot-dependencies:1.4.0.BUILD-SNAPSHOT, C:\JenkinsTryOut\jenkins2-course-spring-boot\spring-boot-dependencies\pom.xml, line 2058, column 16 -> [Help 2]
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-websocket:jar is missing. # line 46, column 15
[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
java version is:
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
maven version is:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\ProgramData\chocolatey\lib\maven\apache-maven-3.6.3\bin\..
Java version: 11.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.1
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
It appears a mixture of not reading the comments and #khmarbaise advice.
in the pom.xml it said:
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>1.4.0.BUILD-SNAPSHOT</version>
</parent>
so when I changed the artifactId to spring-boot-starter-parent, as the comment suggested, and updated the version to 2.2.4.RELEASE as #khmarbaise suggested I got the following parent element of the pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>
and then compiled with mvn compile I was able to successfully compile.
I also started watching the same course, and issued the same problem.
The answer you gave is only partially true. Changing the version to 2.2.4.RELEASE will cause you to face many errors while trying to run mvn test since in the later releases some of the classes are thrown out (ex. org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration). The best solution would be to change artifactId to spring-boot-starter-parent as you said and version to 1.4.0.RELEASE and you'll be able to run all your maven comands without getting errors. So, let's say, fully answer would be:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
Multiple pom.xml files have reference to BUILD-SNAPSHOT versions of libraries which are no longer available. Following steps worked for me:-
Create your github account
Fork repository
https://github.com/g0t4/jenkins2-course-spring-boot
Clone your forked repository to your local directory (say /user/ponson/jenkins2-course-spring-boot)
Open bash terminal and change your current directory to your local git directory (/user/ponson/jenkins2-course-spring-boot)
Run below command to replace occurances of '1.4.0.BUILD-SNAPSHOT' with '1.4.0.RELEASE' in pom.xml files
find . -name pom.xml | xargs sed -i 's/1.4.0.BUILD-SNAPSHOT/1.4.0.RELEASE/g'
Open spring-boot-dependencies/pom.xml for editing and replace '4.3.2.BUILD-SNAPSHOT' with '4.3.2.RELEASE'
Stage your changes to local repository using command 'git add .'
commit your changes (git commit -m '<>')
Push your changes to your remote git repository (git push origin). Keep your github credentials handy and enter when prompted.
The fixes are available in below forked repository. May be you can use it directly.
https://github.com/PonsonT/jenkins2-course-spring-boot

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

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!

Cannot include project artifact: com.test.mmm.jar:1.0; it doesn't have an associated file or directory

I'm pretty lost with maven and I can't seem to find a solution for my problem. When I try to generate the jar file with all the dependencies of my project to execute it on another computer I find this warning when I execute sudo mvn clean compile assembly:single:
[WARNING] Cannot include project artifact: com.test:mmm:jar:1.0; it doesn't have an associated file or directory.
Also, when I try to execute the .jar with java -jar target/test.jar this error appears:
Error: Unable to access jarfile target/test.jar
here's my 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.test</groupId>
<artifactId>mmm</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>mmm</name>
<url>http://maven.apache.org</url>
<properties>
<nd4j.backend>nd4j-cuda-8.0-platform</nd4j.backend>
</properties>
<dependencies>
<dependency>
<groupId>org.jblas</groupId>
<artifactId>jblas</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.deeplearning4j</groupId>
<artifactId>deeplearning4j-core</artifactId>
<version>0.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.test.mmm.Main</mainClass>
</manifest>
</archive>
<finalName>test</finalName>
<descriptorRefs>jar-with-dependencies</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
The main class is located in src/
I've tried many solutions from stack overflow but had no success, can someone help me?
Thank you!
Use mvn package first to build your module classes then assembly:single.
mvn package assembly:single
From the warning you've included in your question:
[WARNING] Cannot include project artifact: Amjar:amjar:pom:0.2; it doesn't have an associated.
I'd guess that you've got the packaging in your pom.xml set to pom.
This is fine if your module is simply packaging a set of dependencies or resource files, however, if you also want Maven to create a jar containing the classes in you module you will need to set the packaging to jar.
make sure that your atrifact produced is matching with <finalName>
i.e.
<groupId>com.rocket</groupId>
<artifactId>myapp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>myapp</name>
produces myapp-1.0.jar
and provide same here
<finalName>myapp-1.0</finalName>
and run then execute:
mvn package assembly:single

Maven error - Spring Surf Alfresco

To construct a project Spring Surf on Alfresco, I used the command:
mvn archetype:generate -DarchetypeCatalog=https://artifacts.alfresco.com/nexus/content/groups/public-snapshots/archetype-catalog.xml
I gave groupId=surfcmistest and artifactId=surfcmistest-1.0-SNAPSHOT. Then, on the folder surfcmistest-1.0-SNAPSHOT created by the project, I try to make build and package with Maven. I run:
mvn install
and I obtain the error:
Failed to execute goal on project surfcmistest-1.0-SNAPSHOT: Could not resolve dependencies for project surfcmistest:surfcmistest-1.0-SNAPSHOT:war:1.0-SNAPSHOT: Failed to collect dependencies at org.springframework.extensions.surf:spring-surf:jar:5.1-BF-SNAPSHOT: Failed to read artifact descriptor for org.springframework.extensions.surf:spring-surf:jar:5.1-BF-SNAPSHOT: Failure to find org.alfresco:alfresco-parent:pom:5.1-BF-SNAPSHOT in https://artifacts.alfresco.com/nexus/content/groups/public-snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of Alfresco-Artifacts has elapsed or updates are forced -> [Help 1]
My pom.xml is:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>surfcmistest</groupId>
<artifactId>surfcmistest-1.0-SNAPSHOT</artifactId>
<packaging>war</packaging>
<name>sample-app Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>Alfresco-Artifacts</id>
<name>Alfresco Artifacts SNAPSHOTS</name>
<url>https://artifacts.alfresco.com/nexus/content/groups/public-snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf</artifactId>
<version>5.1-BF-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.extensions.surf</groupId>
<artifactId>spring-surf-api</artifactId>
<version>5.1-BF-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.2.v20140723</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<scanTargets>
<scanTarget>src/main/webapp</scanTarget>
</scanTargets>
</configuration>
</plugin>
</plugins>
</build>
<version>1.0-SNAPSHOT</version>
</project>
What is my error?
The error message you are getting is:
resolution will not be reattempted until the update interval of Alfresco-Artifacts has elapsed or updates are forced
This is a very classic error and it is resolved by running Maven with the -U option.
You should restart from scratch and follow this procedure:
Remove your whole m2 repository (the default location is ~/.m2/repository) and remove any directory created by an earlier execution of the maven-archetype-plugin.
Run the command:
mvn archetype:generate -DarchetypeCatalog=https://artifacts.alfresco.com/nexus/content/groups/public-snapshots/archetype-catalog.xml
Choose the option org.springframework.extensions.surf:spring-surf-archetype (for me, it was option 1 but it can change).
Choose the version 5.1-SNAPSHOT, which was option 4 for me (but again, this can change)
Select a groupId, an artifactId, a version, a package and confirm all those properties by pressing Y.
Go into the newly created directory (it will be named after the artifactId you chose earlier) and run the following Maven command:
mvn -U clean install

Resources