In a simple java program, How can I download a JAR from a Maven repository ?
The repository can be local as well as remote ? I am using Maven 3.
As noted by #amit your use of Maven-3 is not relevant. Your application is interested in accessing a JAR at runtime. It just so happens that this JAR is available at a Maven repository. Maven is a build-time tool. It cannot help you at runtime.
So if we have interpreted your question correctly, the issue is one of formulating the URL and making an HTTP request. Since you say the JAR is hosted by a Maven repository you know the format of the URL:
http://repository.url/group_id_segments_separated_with_slashes/artifact_id/version/artifact_id-version.jar
You can take advantage of this in your program if you need to access more than one JAR in this fashion.
define the necessary mapping for dependency tags in POM.xml and than provide repository information inside repository tags... for example..
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.11</version>
</dependency>
and
<repository>
<id>snapshot-repository.java.net</id>
<name>Java.net Snapshot Repository for Maven</name>
<url>https://maven.java.net/content/repositories/snapshots/</url>
<layout>default</layout>
</repository>
see more about this here
Related
When I run
mvn versions:display-dependency-updates
Only some of my dependencies are processed.
For instance I have this dependency.
<dependency>
<groupId>com.github.kagkarlsson</groupId>
<artifactId>db-scheduler-spring-boot-starter</artifactId>
<version>6.2</version>
</dependency>
Im not informed that there is a version 6.6 available. Why is that?
Im using maven 3.6.0
Check if your project pom.xml or your maven settings.xml is not overriding the central repository, if central repo is customized, it may not contain the recent version of this dependency
How to use RatingStars Vaadin addon?
I want to use RatingStars addon on all our vaadin pages so that we can get quick feedback from user.
Is there any example available which shows how to use that?
Using widgets with Vaadin (with or without Maven) usually means you have to do 3 things before starting your application:
adding the widget dependency to your classpath
compiling the widgetst
specifying your widgetset
From your description you've already done the first but you had some trouble, so let's take them separately and since you're already using Maven we'll just continue down this road:
1: Adding widgets
I used dependency in project but maven couldn't find this jar so it's failing
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>ratingstars</artifactId>
<version>2.1</version>
</dependency>
Some of the widgets, also known as add-ons, may not be available in the central maven repo, so make sure you add the Vaadin dedicated repo in your POM:
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
...
</repositories>
Now it should resolve and download your dependency, adding it to the classpath.
2: Compiling the widgetset
Then I manually downloaded that jar, unzipped it and kept that my source location. But it's still failing for
Failed to execute goal com.vaadin:vaadin-maven-plugin:7.6.1:compile (default) on project vaadin-widgetset: GWT Module org.vaadin.teemu.ratingstars.RatingStars not found in project sources or resources
Now, before you can run your app, you also need to compile the widgetset. If you've generated your project skeleton using the vaadin-archetype-application everything should be already configured and you simply need to run mvn package (or mvn vaadin:compile for just the compilation process).
Otherwise take a look at this sample project for a standard vaadin-maven-plugin configuration.
P.S. Depending on you IDE, you can also use dedicated IDE plugins for these tasks, but that's up to you.
3: Specifying the widgetset
Finally, depending on your servlet version and app setup you can define your widgetset location by:
using the web.xml file:
<init-param>
<description>Application widgetset</description>
<param-name>widgetset</param-name>
<param-value>com.example.MyWidgetSet</param-value>
</init-param>
annotating your UI with #Widgetset("com.example.MyWidgetSet")
Now you should be able to run your application and see the widget on your screen :-)
All:
I try to build app using Apache Tika to parse PDF, but I wonder where can I get those libraries like tika-core/target/tika-core-.jar and tika-parsers/target/tika-parsers-.jar
I only find tika-app but there is no such jar like above.
http://tika.apache.org/1.11/gettingstarted.html
Apache Tika has a large number of dependencies it needs to run. Without those present, it will do very little!
You therefore need do use a dependency management tool to not only get Apache Tika, but also the other libraries it needs. If you're using Apache Maven to do that, you can follow the instructions on the Tika website to add it as a dependency to your project with a section in your pom like:
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.11</version>
</dependency>
The Apache Tika quickstart page also lists instructions on adding a dependency to Tika, along with all required dependencies, for both Gradle and Ivy builds too. You really ought to be using one of Maven, Gradle or Ivy to be handling the dependencies for you
If you really do want to handle all the dependencies yourself, you can find the Tika Core and Tika Parsers binary jars on Maven central, in the usual place. For Tika 1.11, that's here for the tika-core jar and here for the tika-parsers jar. But, as previously mentioned, you almost certainly don't want to be doing that by hand!
I'm new to Maven.
I have a POM that does not specify a repo, and I want to download Spring's mobile stuff, and the maven directions specify a repo:
<repository>
<id>springsource-repo</id>
<name>SpringSource Repository</name>
<url>http://repo.springsource.org/release</url>
and
<repository>
<id>springsource-milestone</id>
<name>SpringSource Milestone Repository</name>
<url>http://repo.springsource.org/milestone</url>
How do I edit my POM to use these repos for the Spring mobile dependencies, but keep on using the master repo for the other dependencies?
Did you try out adding repositories tag as mentioned in maven.apache.org/guides/mini/guide-multiple-repositories.html
I have started to learn Maven and have the following question:
I would like to dynamically specify a dependency for building maven project instead of using the dependency specified in POMs - is there a way to do that?
So although I have the following dependencies specified in POM
...
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>ProjectComponent</artifactId>
<version>1.0</version>
</dependency>
...
I would like to specify in the build command that I want to use a different version.
Is there a way to specify this?
The idea is that I want to have an integration build made in Jenkins with a dependency on the latest available snapshot of the system for a particular branch. That snapshot is not released to the maven repository yet, so I would like to fetch it in Jenkins and specify a dependency for mvn build.
Thanks!
POSSIBLE SOLUTION: What I ended up with is to use ${my.lib.version} construction and specify it with -Dmy.lib.version=1.0-SNAPSHOT" when calling to mvn. Thus I can use it for Jenkins integration builds by fetching arbitrary snapshot versions of dependencies from svn and feeding their snapshot versions to the integration build pom.
Maven may use "dynamically" specified property (ex: group.ProjectComponent.version) with the help of profiles.
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>ProjectComponent</artifactId>
<version>${group.ProjectComponent.version}</version>
</dependency>
So if you create some profiles you may switch between them (see maven references)
Example:
<profile>
<id>stable-builds</id>
<properties>
<group.ProjectComponent.version>1.0</group.ProjectComponent.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>beta-builds</id>
<properties>
<group.ProjectComponent.version>2.0.Beta1</group.ProjectComponent.version>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
</profile>
What I ended up with is to use ${my.lib.version} construction and specify it with -Dmy.lib.version=1.0-SNAPSHOT" when calling to mvn. Thus I can use it for Jenkins integration builds by fetching arbitrary snapshot versions of dependencies from svn and feeding their snapshot versions to the integration build pom.
Just came across this as I was looking for something similar. In my case same application code is being reused on different stacks which means using different "drivers" for accessing data. Although drivers implement same interface they do come from different artifacts.
No you can't change the dependencies dynamically. Furthermore it does not make sense, cause you would like to have a reproducible build.