Building a Docker-Image with maven and spring-boot on Windows - java

I'm trying to learn how to use maven, spring-boot and docker to create a web-application. I'm following this guide:
https://spring.io/guides/gs/spring-boot-docker/
I managed to build the maven project as such that localhost, says "Hello Docker World".
Then I copied the Dockerfile and added the extra property and plugin.
<properties>
<java.version>1.8</java.version>
<docker.image.prefix>springio</docker.image.prefix>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
When executing mvn -N io.takeri:maven:wrapper to add the maven wrapper I received an error:
Error resolving version for plugin 'io.takeri:maven from the repositories[...]: Plugin not found in any plugin repository -> [Help 1]
As the command above has already worked on a different attempt (without docker) I checked the Help 1-link
https://cwiki.apache.org//confluence/display/maven/pluginresolutionexception
and added the same plugin-repository to the pom.xml as in the other project were it worked.
This proved to be ineffetive.
Executing the Project without the wrapper (mvn install dockerfile:build)
gives a MojoExecutionException followed by a long Error-Trace
and the
error: Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.6:build
(default.cli) on project ...: Could not build image:
java.util.concurrent.ExecutionException:
com.spotify.docker.client.shader.javax.ws.rs.ProcessingException:
org.apache.http.conn.HttpHostConnectException: Connect to localhost:2375
[localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused:
connect
How can I resolve this issue?
Note1: I'm new to Maven AND Spring-Boot AND Docker AND Stackoverflow, please let me know how I can improve this post or learn more about them.
Note2: I'm running Windows 10, and was planning on using Virtual Toolbox for Windows and successfully executed this guide https://docs.docker.com/get-started/part2/

I wonder what repositories you refer to? Both the takari plugin and spotify plugin are available in maven central, so no repositories should need to be configured in your pom. Or did you add them to your settings.xml? Could you try to simply remove repositories from your project?
Maven distinguishes dependencies and plugins. So you have sources (repositories to download them from) for both, meaning repositories and pluginRepositories. Nowadays companies will use a mirror/proxy like nexus or artifactory, so the difference is not directly visible - you only configure the mirror and point all repositories there.
So to use plugins there must be a pluginRepository configured that contains that plugin. See settings.xml docs.
Since all you need is in maven central the default config should just work without any more to do. So just remove all repositories from your pom.xml or settings.xml
The docker error you get seems not to be related to maven or the plugin, it simply cannot communicate with your docker host. Maybe to port is wrong or you are running a docker version not compatible with the plugin or it was not running? Docker for Windows might require you to expose the daemon without TLS.
Hope any of this is of some help :)

I had same issue. HttpHostConnectException You must run docker deamon on your machine.

Maybe you could configure environment variables.

Related

Java deploy to Heroku with maven plugin invalid credentials

I am trying to deploy my Java app into Heroku server with maven heroku plugin. But i am getting such error:
Failed to execute goal com.heroku.sdk:heroku-maven-plugin:3.0.4:deploy (default-cli) on project endlessblow-server: Execution default-cli of goal com.heroku.sdk:heroku-maven-plugin:3.0.4:deploy failed: Failed to create source statuscode:401 responseBody:{"id":"unauthorized","message":"Invalid credentials provided."}
my pom.xml looks like this:
(...)
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.4</version>
<configuration>
<appName>MY_APP</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* pl.jawegiel.Main</web>
</processTypes>
</configuration>
</plugin>
(...)
How to solve that? A few weeks earlier everything was working fine.
Thank you in advance!
From the Maven plugin's doc: https://github.com/heroku/heroku-maven-plugin#heroku-api-key
This plugin uses Heroku's Platform API and thus requires an API key to function. If you have the Heroku CLI installed and logged in with heroku login, the plugin will automatically pick up your API key. Alternatively, you can use the HEROKU_API_KEY environment variable to set your API key
I guess you were previously logged in with Heroku CLI, so running mvn heroku:deploy was working just fine...

JBoss Fuse unable to install bundel with maven install

I created maven project in eclipse to expose rest web service to JBoss Fuse and make maven clean and install and the package created in maven local repository in this path:
C:\Users\mohamed.mostafa\.m2\repository\com\javainuse\apache-camel-jaxrs\0.0.1-SNAPSHOT
I want to install this package to jboss fuse with this command:
JBossFuse:karaf#root>install mvn:com/javainuse/apache-camel-jaxrs/0.0.1-SNAPSHOT
Please help me ...
Give me unable to install bundle com/javainuse/apache-camel-jaxrs/0.0.1-SNAPSHOT
This should be configured in org.ops4j.pax.url.mvn.cfg configuration available in etc folder.
Syntax you are using to install is wrong. It should be like below.
JBossFuse:karaf#root>install mvn:<groupId>/<artifactId>/<version>
Example:
JBossFuse:karaf#root>install mvn:com.javainuse/apache-camel-jaxrs/0.0.1-SNAPSHOT
Also, it matters from where you are tying to install If you using nexus you could use something like below.
org.ops4j.pax.url.mvn.repositories = http://someurl.com/nexus/content/groups/public#snapshots
If you want to use local maven repo.
Path to the local maven repository which is used to avoid downloading
artifacts when they already exist locally.
The value of this property will be extracted from the settings.xml file
above, or defaulted to:
System.getProperty( "user.home" ) + "/.m2/repository"
org.ops4j.pax.url.mvn.defaultLocalRepoAsRemote = true
org.ops4j.pax.url.mvn.localRepository= Path of Local maven Repo
To create an OSGi bundle for JBoss FUSE by using Maven you should add the maven-bundle-plugin to your pom.xml, and set packaging type to bundle:
<packaging>bundle</packaging>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<version>2.3.7</version>
</plugin>
</plugins>
</build>
To make your bundle available for JBoss FUSE, build and install the artifact into your local Maven repository:
mvn -DskipTests=true clean install
To install your OSGi bundle in JBoss FUSE by using Apache ServiceMix or Apache Karaf, you can run the following command from its shell:
JBossFuse:karaf#root> osgi:install -s mvn:<groupId>/<artifactId>/<version>
You'll see:
Bundle ID: //some identifier here
Parameter -s allows to start bundles automatically.
Also JBoss FUSE provides a web administration console available at:
http://localhost:8181/hawtio
Among other things, there you can manage your bundles.
Important note: as described in the documentation,
If your local Maven repository is stored in a non-standard location,
you might need to customize the value of the
org.ops4j.pax.url.mvn.localRepository property in the
InstallDir/etc/org.ops4j.pax.url.mvn.cfg file, before you can use
the mvn: scheme to access Maven artifacts.

Intellij 13 Ultimate not able to find supported files

I'm using Intellij 13 Ultimate on Windows 7 enterprise. My maven pom includes the following:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration/>
</plugin>
</plugins>
</reporting>
I have settings.xml configured to access Nexus repositories within the firm for whom I am working.
Within intellij, the '2.9.1' displays in red and I see : Plugin "org.apache.maven.plugins:maven-javadoc-plugin:2.9.1" not found.
At the windows command line, though, I am able to download the artifact to the local repo using the same settings.xml file and the command:
C:\swdtools\apache-maven-3.1.1\bin>mvn org.apache.maven.plugins:maven-dependency
-plugin:2.1:get -DrepoUrl=https://dsnexus.uk.<HIDDEN>.<HIDDEN>:8081/nexus -Dartifact=org
.apache.maven.plugins:maven-javadoc-plugin:2.9.1
Intellij doesn't pick it up if I do 'reimport all maven projects'.How to fix or debug this further within intellij?
I have the same issue while including the report plugin "maven-jxr-plugin" with IDEA 13, but other plugins are work well.
The plugin could be found in Central Repo, but not in local.
One solution is to move the declaration from report section to build section, then the downloading will be triggered, and the reporting still works.
I changed config intellij's config dirs in 'idea.properties' and found the 'idea' log file. The dependency problem went away as soon as I changed config dirs, no explanation, except that i didn't realize intellij was throwing errors until I ran 'idea.bat' at the command line. So - 1/ run from command line 2/ look into idea log file for unexplained problems

How does Maven understand release:prepare command?

I'm trying to create a plugin which would download and install jars from Maven central as system tools. So I want my line to be like
mvn install-plugin:install org.chaschev:cap4j:1.0
similar to Ruby's
gem install capistrano
This plugin would gather all the needed information about the shortcuts to create from the JAR. I.e. this jar would contain a class implementing an installation interface.
How does Maven understand that in order to execute a command like release:prepare it requires to download the release plugin and to run it? Any better/other way to do this?
Do you mean how the relation between plugin/goal in the comamnd line and plugin implementation is defined? Then the answer is plugin.xml. See plugin.xml for release plugin, e.g. maven-release-plugin-2.0.jar:
<goalPrefix>release</goalPrefix>
...
<mojos>
<mojo>
<goal>help</goal>
...
<mojo>
<goal>prepare</goal>
...
Or do you mean, how Maven discovers which plugins are available? Then the answer is:
There are two default groups where plugins are searched, org.apache.maven.plugins and org.codehaus.mojo
For your own plugin you may want to use name ${prefix}-maven-plugin, e.g. cap4j-maven-plugin
You can keep your name cap4j, but then put the plugin description to your POM, under <plugins>
If you want your build to work at other machines, they should point <pluginRepositories> in POM or in settings.xml to your plugin repository
It is not good to use default Maven groups for your own project.
Instead, define your own group for your plugin, like this:
<pluginGroups>
<pluginGroup>org.chaschev</pluginGroup>
</pluginGroups>
And rename your plugin from cap4j to cap4j-maven-plugin. Then Maven will discover your plugin without further cahnges in POM.
Alternative, without <pluginGroups>, just put following to your POM:
<plugins>
<plugin>
<groupId>org.chaschev</groupId>
<artifactId>cap4j</artifactId>
<version>...</version>
<configuration>
...
</configuration>
</plugin>
...
</plugins>

artifactory-maven-plugin: How to resolve dependencies from private Artifactory without settings.xml

How can I configure the artifactory-maven-plugin to resolve dependencies from our private Artifactory server?
The official documentation explains on how to publish:
https://www.jfrog.com/confluence/display/RTF/Maven+Artifactory+Plugin#MavenArtifactoryPlugin-Usage
Usually, dependency resolving works by adding servers to my .m2/settings.xml and specifying credentials there. However, in a cloud Docker build environment, it is difficult to place the settings.xml inside the container. It would be much easier if the plugin could be configured accordingly.
The Gradle Artifactory Plugin has explicit documentation about this (see dependencies resolution):
https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin#GradleArtifactoryPlugin-UsingtheArtifactoryPluginDSL
Turns out the Maven plugin also has a resolver configuration option. But it is not documented anywhere. This does not work (Maven still won't try to download dependencies from Artifactory):
<plugin>
<groupId>org.jfrog.buildinfo</groupId>
<artifactId>artifactory-maven-plugin</artifactId>
<version>2.6.1</version>
<inherited>false</inherited>
<configuration>
<resolver>
<contextUrl>${artifactory.context.url}</contextUrl>
<username>${artifactory.username}</username>
<password>${artifactory.password}</password>
<repoKey>libs-local</repoKey>
</resolver>
</configuration>
</plugin>
You can configure Maven to resolve artifacts through Artifactory you need to modify the settings.xml. You can generate one automatically, or modify it manually.
jfrog docs has provided steps to do this ,
In the Artifact Repository Browser of the Artifacts module, select Set Me Up. In the Set Me Up dialog, set Maven in the Tool field and click "Generate Maven Settings". You can now specify the repositories you want to configure for Maven.
Check here

Categories