I want to add jpoller.jar as a maven dependency, so I edited my pom.xml file to include it:
<dependency>
<groupId>org.sadun</groupId>
<artifactId>jpoller</artifactId>
<version>1.5.2</version>
</dependency>
Now, as expected, when I compile from the command line I get an error because jpoller isn't in any of the repositories I have listed in my pom, nor could I find one for it. Although I could create a repository for it, I'd rather not at this point. Thus, I get the following error:
[INFO] Failed to resolve artifact.
Missing:
---------- 1) org.sadun:jpoller:jar:1.5.2
Try downloading the file manually
from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.sadun -DartifactId=jpoller -Dversion=1.5.2 -Dpackaging=jar -Dfile=/path/to/file
How can I do this from the M2Eclipse plugin on machines where the maven CLI isn't available?
How can I do this from the M2Eclipse plugin on machines where the maven CLI isn't available?
Well, simply do it from Eclipse. First, get that jpoller jar and save it somewhere on your file system. Then, in Eclipse, from the top bar, Run > Run Configurations... then right-click on Maven Build and configure the New_configuration freshly created:
Select an arbitrary Base directory
Fill the Goals with install:install-file
Add parameters for each required parameters, without the -D prefix (e.g. file as Parameter name and /path/to/file as Value and so on for groupId, artifactId,packaging and version).
And run this configuration. Or... just install Maven.
The install command automates the creation of a folder structure in ~/.m2 and pom.xml file for the dependency artifact. This can be done manually. OR You can simply copy the ~/.m2/{group}/{artifact} folder from a machine that does have mvn installed.
Edit: This tool will help you find public repositories for a given dependency.
Edit2: See http://maven.apache.org/guides/mini/guide-coping-with-sun-jars.html for an explination of the process of installing dependencies manually. Note that most sun jars are now available in the java.net repository http://download.java.net/maven/2/
Related
Many of maven's plugins run on the current project's pom.xml file.
Sometimes I need to run a certain plugin on an artifact I downloaded from the repository.
For instance I'm downloading sparkjava using dependency:get like that:
mvn dependency:get -Dartifact com.sparkjava:spark-core:2.5.4
I would like then download all sparkjava's dependencies sources using dependency:sources like that:
mvn dependency:sources -Dartifact com.sparkjava:spark-core:2.5.4
Or even better, run dependency:sources directly on the artifact:
mvn dependency:sources -DinputPom=locationToRepository/com/sparkjava/2.5.4/spark-core-2.5.4.pom
Is it possible to do?
The maven dependency plugin sources goal tells Maven to resolve all dependencies and their source attachments, and displays the version.
You can specifically includes or excludes artifacts by using optional parameters. See the maven dependency plugin documentation.
I have a project downloaded from git. Here is the link to source code https://github.com/dwdyer/reportng, I have downloaded it and now I am trying to create a JAR file and then want to attach it to maven repository. When I compile it using mvn compile and mvn package, it gives me the same INFO message, and in my target folder there is a jar file is created. But only pom.xml and pom.properties are shown inside it, instead of whole hierarchy of compiled class files replaced with Java files
Maven is very picky about following a very specific folder layout in the given project (which you can override but it is not really intended to do so).
Instead you may want to just install the generated jar file directly in your local repository using the mvn install:install command.
If you want to script this, see Multiple install:install-file in a single pom.xml for instructions on how to create a pom.xml doing this.
First of all, you have to debug problem:
cd reportng/
mvn -e clean install
-e switch on errors' trace.
If everything ok, install will add jar just created jar file to your local repository.
Then it will be available as dependency to any project:
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
</dependency>
By the way:
Jar is available in maven central, so referencing it as dependency, having compile time internet connection, will be enough.
This can be solved by changing the Maven strusture. Maven must contain src/main/java, whereas in the program it is src/java/main
I have added dependencies in pom.xml and immediately the corresponding jars started to show up in maven dependencies section of dynamic web project.
I just want to know that I have not done mvn install in cmd so how did they get saved in maven repository.
Another query I have, is that since jars are availble in maven dependencies folder of dynamic wep project, so my project runs successfully or not as depndencies are already satisfied without doing mvn install.
When you list a <dependency> in your project's POM, M2Eclipse (Eclipse's plugin in this case) will trigger Maven to resolve that declared dependency...meaning Maven will check your local repo first for that dependency, and if it's not found there it will pull it down from the next highest repo you have configured (possibly an agency-level repo, or Maven's default public repo on the web).
No mvn install is required, as the purpose of that would be to install your current project's packaged artifact into your local repo, rather than install any dependency.
Hope this helps to clarify why an install is not used to copy dependencies into your local repo.
I have several local Maven repositories besides the one located in ~/.m2 directory and I want to simplify the process of installing new artifacts into them from Maven central.
So far I couldn't find a way to tell mvn dependency:get that dependency should be put into a specific local repository.
I did manage to find a way to install a given downloaded artifact using mvn install:install-file -DlocalRepositoryPath=, but I want to be able to get and put dependencies into a specific repository with as few manual steps as possible.
Before you ask why can't I just configure my project to use Maven central directly here is the answer: the project uses Gradle and I do not own its build script (i.e. I can't modify it). The project build script is written to work with several distinct repositories having the same base URI that I fortunately can change using build.properties file. So my idea is to have several local maven repositories in the same root directory and trick the build script to use them.
You can use the maven.repo.local property:
mvn dependency:get -Dmaven.repo.local=/path/to/localrepo
We are using Maven and m2e tools for our development and today we encountered a problem.
One of our projects is small library that is required for other projects, so we packaged it into jar file and put in our private Maven repository.
For now, all of the jars that we put in this repository didn't have any external dependencies, but this library I mentioned uses some external jars.
Now, when I add information about this jar to other poms, this jar is downloaded from our private repository but Maven doesn't download dependencies needed by this jar.
I am wondering if I need to use some special target/add something to my pom.xml file that will inform Maven to include information about dependencies needed by this artifact.
EDIT:
Here is the workflow I perform when I upload jar to our private repository:
1.I generate jar file from Eclipse using m2e
2.mvn install:install-file -DgroupId=<your_group_name> -DartifactId=<your_artifact_name> -Dversion=<snapshot> -Dfile=<path_to_your_jar_file> -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true
3.I copy folder created in my local repository to remote repository
If your small library is a maven project as you state, there should be no reason to have eclipse build the jar and then use maven to install it and then manually copy to the remote repo. Instead you should use m2e to run the deploy goal:
mvn deploy
That will cause the jar to get built and then install it directly into your local maven repo then deploy it to the remote repo.
In eclipse this can be accomplished by right clicking your project, choosing Run As -> Maven Build... then in the run configuration window for Goals input type deploy then click Run. After this has been done once, you can just use Run As -> Maven Build to run the same config again.
I see you use -DgeneratePom=true during the installation of the jar file. What you need to do is create a pom.xml for your artifact. In the pom.xml, you can specify the dependencies that your jar file requires. When executing the install:install plugin goal, you use -DpomFile=pom.xml instead.
The best way to do this is to run mvn deploy
You have to setup the distribution repository to your private artifact manager (nexus or artifactory) in your settings.xml
see this for more details