Here is the Maven Repository that I'm trying to use. A snippet from my pom.xml:
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2</version>
</dependency>
When run, it grabs the cscore-1.0.2.pom file just fine, but then it goes searching for cscore-1.0.2.jar which doesn't exist - if you look in the repo, each JAR is platform-specific, and is named accordingly (e.g. cscore-1.0.2-linux.jar).
I've tried:
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>edu.wpi.cscore.java</groupId>
<artifactId>cscore</artifactId>
<version>1.0.2-linux</version>
<type>jar</type>
</dependency>
It gets the cscore-1.0.2.pom fine but then it goes looking in the 1.0.2-linux/ directory for the JAR, which simply doesn't exist. Is there a way to tell Maven that the JAR file it is looking for will be named something else? Or is this simply not a valid Maven repository?
Thanks!
There should be one [and only one] artifact addressable via a coordinate [group-id, artifact-id, version].
These platform-specific artifacts were likely pushed into the repository manually and can't be referred to individually via the expected maven dependency POM element.
The easiest short-term solution would be to manually extract the dependency/dependencies and install each one with its own unique maven coordinates in your local repository. Then refer to that artifact using its local coordinates from the element in your project's POM.
Unfortunately that makes it impossible for maven to automatically detect and download a newer version of the artifact in the remote repo.
The long-term solution would be to petition the keepers of the external dependency's project, asking them to re-consider how they identify and install their platform-specific artifacts.
Related
How do i update the maven local repository? if, i do not have the download rights.
I have the latest jar files with me. how do i replace the jar files in m2 folder and update the pom file?
I have tried this :
You can copy them in your local repository. For example, if you should add this dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
You should create folder in your maven local repository:
//com//fasterxml//jackson//core//jackson-databind//2.9.4 and put your jar in this folder.
Now getting below error -
failed to read artifact descriptor for org selenium selenium selenium-java:jar:3.13.0
You can copy them in your local repository.
For example, if you should add this dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.4</version>
</dependency>
You should create folder in your maven local repository:
//com//fasterxml//jackson//core//jackson-databind//2.9.4 and put your jar in this folder.
You probably do not have the whole list of jars with all relevant parent poms, transitive dependencies etc. It is very hard to create a complete list manually. If any dependency of a dependency of a dependency is missing, your project won't compile.
First of all, I would advise you to try to get the "download rights" because using Maven with a bunch of manually deployed jars is very brittle and will take a huge amount of time to get right.
If you cannot get them, you either need to add all jars manually that Maven is missing (like the selenium jar mentioned in your question), or, if you are sure that certain artifacts are not necessary, you can exclude these dependencies in your pom.
In my application, I want to get a 'view' of the local maven repository. The application is used to start another Java application (via ProcessBuilder), and allows users to add/replace libraries on the classpath. Part of this will provide a view of the artifacts in a user's local maven repository that could be used on the subsequent classpath.
Given an M2_HOME setting, I can get the settings.xml and from that the directory that the local maven repository is stored in (<localRepository>).
I could then do a file system query to get the jars, poms etc. that are in the user's local maven repository, determining the groupId, artifactId, version, packaging etc. from the file path and filename.
However, I am wondering whether there is scope to do this through the maven machinery - i.e. using maven libraries. If possible, that strikes me as being the correct / clever way of doing this.
Have a look at following maven dependencies,
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
</dependency>
Something on following line
RepositorySystem and LegacyRepositorySystem classes
RepositorySystem ArtifactRepository createLocalRepository( File localRepository ) method.
You might still need to inspect your local maven installation conf if local repository is set to other than ${user.dir}/.m2
I have just realized that it does not give a complete artifactory view. Could you check the following,
org.apache.maven.index.Scanner
org.apache.maven.index.DefaultScanner
This is probably used in eclipse Maven repositories view. See following,
I cant find javax.ejb.jar in my .m2 dirctory, I need this jar for import javax.ejb.Schedule; , here is my pom file entry.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
I am not sure if it will work or not, or its a right way to do things. Can some one please help to make a change in the POM file so that it downloads javax.ejb.jar into the .m2 directory.
Updated
by .m2 I mean in the repository directory in the correct folder
hierarchy (What ever it is).
Why? We have multiple sub projects (In eclipse workspace), In order to resolve dependency we use M2_REPO/path/to/the/required_library_file.jar, Now theses projects are part of code bases, Every developer download the source code, Maven download all jar to the repository directory(of the developer using any OS/Platform). This relative path from M2_REPO helps developer to have consitenat code (for eclipse project). Otherwise everyone will be adding their own path.
If it still doesn't make sense, here is what I want, Please give me an entry for POM file which download the javax.ejb.jar file into .m2 directory what ever the sub path is.
I have to include this jar in every project manually (And every developer needs to them as well from what ever directory have glassfish (C: , D:, E:, or /home/glassfish/modules/)
D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar
where rest of the jars in each project are included as M2_REPO/path/to/jar which makes less no changes in the code base to commit.
M2_REPO/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
M2_REPO/javax/enterprise/cdi-api/1.0-SP1/cdi-api-1.0-SP1.jar
M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar
etc etc
I think I hear what you mean now :)
The maven dependency you specify
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
which you have in .m2/repository/javax/ueb/ejb-api/3.0/ejb-api-3.0.jar does not contain the class/interface javax.ejb.Schedule.
But you found the jar-file in your glassfish server, which does contain javax.ejb.Scheduleand its name is D:\servers\glassfish-3.1.2\glassfish3\glassfish\modules\javax.ejb.jar and now you ask how to get that into the pom?
Well, the Java EE APIs and their official jars in maven are somewhat a study in disharmony.
If you run a search on maven central you will find multiple jars containing exactly that class. You will probably note that all appserver vendors provide their own edition of every aspect of every api in every version.
You should be able to find a jar with the javax.ejb module from glassfish in version 3.1.2
http://search.maven.org/#artifactdetails|org.glassfish|javax.ejb|3.1.2|jar
in which case the dependency would be
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.ejb</artifactId>
<version>3.1.2</version>
<scope>provided</scope>
</dependency>
I found another artifactId here, though maven has your version too.
A (very) weird maven caching problem? Then it might work tomorrow.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
</dependency>
Though this is a new version, for compilation it should do.
You may need to provide the repository location in your pom.xml file or in .m2/settings.xml file for the required jar to get downloaded into .m2 directory.
The dependency is declared as provided what means that the container will provide it.
What container are you using? I think Tomcat/Jetty won't provide that jar as it seems so Java EE. In that case just change the scope to compile.
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<version>3.0</version>
<scope>compile</scope>
</dependency>
More info about dependency scopes:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
There is a website with a jar I want to use in my project. I could download it, and make a local dependency on it, but that is lame.
Other people will build this project. I don't want to clutter source control by checking it in. I want to comunicate where the resource can be downloaded from and to easily change the versions. At some point I would like to attach the sources and javadocs.
Is there a plugin that will let me use the URL and download it to my .m2 with a spoofed pom?
The way I do it, is to search for the jars in Maven's central repo:
http://search.maven.org/
This gives you enough data to build the dependency in your pom.xml file
Example:
If I wanted to add jSoup to my project as dependency, then I go and search in the central repo
and add the dependency to the pom file with the info that's in there:
http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.jsoup%22%20AND%20a%3A%22jsoup%22
<dependencies>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
<scope>test</scope>
</dependency>
</dependencies>
I think maven2 repo is included by default when creating the super pom, so you don't have to write it, it will look there by default.
I think the best solution is to set up a Nexus or Artifactory repo for the team available over the network. Download the jar from the third-party location, and then upload it with the proper pom GAV values to your new local repo. Then add the URL of this repo to the repositories section of the pom. Everyone will get it when they sync up with version control.
maven-install-plugin can install files in local repo and generate poms, usage example:
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.3.0 -Dpackaging=jar -Dfile=ojdbc6_g.jar -DgeneratePom=true
How do I take a jar file that I have and add it to the dependency system in maven 2? I will be the maintainer of this dependency and my code needs this jar in the class path so that it will compile.
You'll have to do this in two steps:
1. Give your JAR a groupId, artifactId and version and add it to your repository.
If you don't have an internal repository, and you're just trying to add your JAR to your local repository, you can install it as follows, using any arbitrary groupId/artifactIds:
mvn install:install-file -DgroupId=com.stackoverflow... -DartifactId=yourartifactid... -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/jarfile
You can also deploy it to your internal repository if you have one, and want to make this available to other developers in your organization. I just use my repository's web based interface to add artifacts, but you should be able to accomplish the same thing using mvn deploy:deploy-file ....
2. Update dependent projects to reference this JAR.
Then update the dependency in the pom.xml of the projects that use the JAR by adding the following to the element:
<dependencies>
...
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
You can also specify a dependency not in a maven repository. Could be usefull when no central maven repository for your team exist or if you have a CI server
<dependency>
<groupId>com.stackoverflow</groupId>
<artifactId>commons-utils</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/commons-utils.jar</systemPath>
</dependency>
Actually, on investigating this, I think all these answers are incorrect. Your question is misleading because of our level of understanding of maven. And I say our because I'm just getting introduced to maven.
In Eclipse, when you want to add a jar file to your project, normally you download the jar manually and then drop it into the lib directory. With maven, you don't do it this way. Here's what you do:
Go to mvnrepository
Search for the library you want to add
Copy the dependency statement into your pom.xml
rebuild via mvn
Now, maven will connect and download the jar along with the list of dependencies, and automatically resolve any additional dependencies that jar may have had. So if the jar also needed commons-logging, that will be downloaded as well.
I'd do this:
add the dependency as you like in your pom:
<dependency>
<groupId>com.stackoverflow...</groupId>
<artifactId>artifactId...</artifactId>
<version>1.0</version>
</dependency>
run mvn install it will try to download the jar and fail. On the process, it
will give you the complete command of installing the jar with the error message. Copy that command and run it! easy huh?!
I'll assume that you're asking how to push a dependency out to a "well-known repository," and not simply asking how to update your POM.
If yes, then this is what you want to read.
And for anyone looking to set up an internal repository server, look here (half of the problem with using Maven 2 is finding the docs)