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.
Related
Maven has repositories and dependecies. Some plugins allow to use s3 or github as repository. But is there something to use direct URL? Like:
<dependency>
<groupId>my-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>some-version</version>
<url>https:someurl</url>
</dependency>
May be define URL and dependency info (group and artifact) in properties and for it installed during some maven phase.
Is it possible?
No.
Maven resolves dependencies from Maven repositories. So you cannot just add a JAR that is present at some URL. The JAR has to come from a Maven repository and (if it is not MavenCentral or already specified in your settings.xml or POM), you need to add it.
Yes this is officially supported but not in as convenient a mechanism as you perhaps desire.
Maven resolves dependencies against your local repository. If it can't find them there, it then tries to resolve them against any remote repositories you have configured.
Therefore, if you manually install the jar into your local repository, Maven will find it and use it.
To do this you must:
Download the jar
You have to do this yourself manually or automate the process e.g. using curl or wget
Specify the Maven Install Plugin version in your pom
You are going to be relying on the Maven Install Plugin so you should install you specify the version in your pom.xml, rather than relying on the default version.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
</plugins>
</build>
Install the jar to your local repo
If the jar has been built with Maven, then it will include a pom.xml inside it. If you are unsure, open the jar with any archive manager and look inside the directory /META-INF/maven. You should find another directory named after the group ID, then another for the artifact ID, and then finally the pom.xml itself.
If the pom.xml is included, you can just run this and the tool will read the pom.xml to find the group ID and artifact ID so it can be placed in the right location in your repository:
mvn install:install-file -Dfile=/path/to/downloaded.jar
If the pom.xml is not included, you will need to specify all of this information yourself. It does not matter what you choose but you should choose something that isn't going to confuse you later:
mvn install:install-file -Dfile=/path/to/downloaded.jar -DgroupId=my-group-id -DartifactId=artifact-id -Dversion=some-version -Dpackaging=jar
Update your pom.xml
You can now just reference the dependency as normal in your pom.xml:
<dependency>
<groupId>my-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>some-version</version>
</dependency>
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.
I'm working on a web service locally, built using maven and deploying to tomcat. I'm using the maven plugin to run locally, using mvn tomcat:run as my run configuration.
Right now, my service is being deployed using the default project name as a context path:
http://localhost:8080/myArtifactId/servletPath
I would instead like to deploy to remove the context path, and deploy to this url through configuring the tomcat maven plugin:
http://localhost:8080/servletPath
Per this documentation: http://tomcat.apache.org/maven-plugin-2.1/tomcat7-maven-plugin/usage.html
I am trying this:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<!-- Why isn't this working??? -->
<path>/</path>
</configuration>
</plugin>
Any ideas on why what I'm trying isn't working, or a different way I can go about this? As I've stated, I'm trying to do this through the maven plugin.
Alternatively, does anyone know how to pass this in as an argument to the run configuration? Maybe passing it in explicitly at the command line will override the default.
UPDATE: Running mvn tomcat7:run or mvn clean tomcat7:run from the command line appears to make this work as intended. But when I run using a Maven Build run configuration in Eclipse, the service is started using the default artifact ID, regardless of what I put in the path variable in my pom.xml.
UPDATE: This appears to be a problem with the Eclipse Maven plugin. When I run the command from the command line, everything works as expected but when trying to add an Eclipse/Maven run configuration with a Tomcat7:run goal, the project keeps running using the default artifact id context path.
When experiencing problems with maven they mostly get solved by using the clean plugin (mvn clean) which cleans out your project's working directory.
http://maven.apache.org/plugins/maven-clean-plugin/
I have a bundle:
<groupId>com.helloworld</groupId>
<artifactId>Helloworld</artifactId>
<version>1.0.0-SNAPSHOT</version>
Previously, the bundle and OSGi container(FUSE ESB Enterprise) are at the same machine. I use the following command to install it from local maven repository:
FuseESB:karaf#root> install file:/home/li/.m2/repository/com/helloworld/Helloworld/1.0.0-SNAPSHOT/Helloworld-1.0.0-SNAPSHOT.jar
Now the bundle and OSGi container are at different machine:
bundle in a machine where IP is 192.168.122.22
How can I install this bundle remotely?
Notice that the argument to the install command is a URL. So you can install from any URL for which you have a URL handler available. For example:
install http://www.example.com/helloworld-1.0.jar
For Fuse ESB or more general for Apache Karaf based servers you have the pax url mvn uri prefix. This allows to install bundles from mvn repositories. I propose to always use this uri instead of the file one.
In your case the command would be:
install mvn:com.helloworld/Helloworld/1.0.0-SNAPSHOT
This uri is even a little smaller than the file based one. The big adavantage though is that you have the full mvn resolution available. So this above url will work for bundles from your local maven repo but also from maven central.
Of course you typically will not deploy your own artifacts to maven central. So if you want to use this inside your company you should set up a maven repository like Nexus or Archiva. Then you deploy your own bundle using mvn clean deploy into your company repo. Of course this will require that you set up your pom correctly but you will need that anyway for any larger project.
The last step needed is then to set up your Fuse ESB / Karaf to also use your company repo. This is done by adding the repo uri to the file etc/org.ops4j.pax.url.mvn.cfg.
Of course this is a little more work than the http url that Neil proposed. THe advantage is that this will integrate very well with your maven build process and it will make your bundle mvn uris independent of the location of your maven repo. It will also allow you to mix your own bundles and open source bundles when you start to combine them using features.
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