I've got one myPackage maven project, compiled and installed to local maven repository under
~/.m2/repository/mygroup/myPackage/1.0-SNAPSHOT/myPackage-1.0-SNAPSHOT.jar
In another maven project, I wish to use it, and in pom.xml I write <dependency> section for it. But I don't know how to write the "systemPath" for this jar:
I cannot use "~" to specify the path, because "~" is a *nix shell extention, java/maven cannot recognize it.
I cannot hard code like
/home/myself/.m2/...
It's not portable.
I cannot use ${project.basedir} because these 2 maven projects are under different folders. But I guess there should be some other maven environment variables that could indicate "home directory"?
All I wish to do is to get this "systemPath" done.
---------------Problem solved by using another project as dependency------------
<systemPath>${project.basedir}/../myPackage/pom.xml</systemPath>
That works!
A system path is required when the library that your project depends on is not in the maven local repository.
As a rule of thumb, this approach is indeed not portable at all and should be avoided for real projects.
Now, the dependency is in local repository if:
It was downloaded from some remote repository (usually)
You've installed it locally (in this case its in your local repository but might not be in your team-mate repo)
In order to install the dependency into the local repo consider using: mvn install:install-file+ parameters as written here
But from your question, it looks like the file is already there... Anyway once the file is in the local repository you can just define a "regular" dependency (group, artifact, version) and Maven will pick it, no need to fiddle with system Path in this case.
Related
I have a legacy project that I'd like to convert to a Maven project for dependency management.
The problem is, that I have one jar (fop-1.1.jar) that I had to edit. It differs from the one that is publicly available and I only have it locally. But I need it this way.
What I tried to do, following several similar how-to's, it to create a fake Maven repo inside the project (local repo is no good, because several people work on that project and the solution has to be self-contained on Git) and reference this repo from the pom.xml. Sounds like the way to go for me, but it doesn't work. Eclipse show the project repo grayed-out :(
What am I missing?
BTW: this is what I tried to follow: https://devcenter.heroku.com/articles/local-maven-dependencies
Let me suggest another way: When we need to "edit" a jar, we give it a special version number like 1.1-edited instead of 1.1.. Then we can easily upload it to our normal Maven repository and use it. Maven even makes sure that you do not accidentally load both versions in the same project because the edit is only in the version number.
I guess what you need is a private maven server(I guess it exists), and then execute command to deploy jar( before deploy, check your account has privileges)
mvn deploy:deploy-file -Dfile=${jarFilePath} -DgroupId=${groupID} -DartifactId=${artifactId} -Dversion=${version} -Durl=${privateServerURL} -Dpackaging=jar -DrepositoryId=${privateServerURLInYourMavenSettings.xml}
,
after deploy successfully, add maven dependency
<dependency>
<groupId>${groupID}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</dependency>
I use dbus-java library in my own library. It depends on unix-java and some more. Those jars are not present in any maven repo.
How would I explicitly depend on all of these?
I see several options:
send jars to maven repo by myself (though it's not clear for me - how to preserve their groupId?)
package all the jar's into mine (which is obviously bad)
write in README: "apt-get install dbus-java-bin" and what to include in classpath... but it makes me really sad :(
Note: I came from Ruby land, so I'm relative new to all these weird Maven repos and confused by missing jars everywhere. In Ruby I was always sure that I will be able to retrieve all the gems either from rubygems or from a specified git repo (usually on github).
Could you explain how is better to distribute such libraries?
What I would do is to download the jars from the net and install them in my local-global repository.
(By this I mean the repository that is not local on my machine, but local to the company, often this is managed by Nexus).
You just need to set a pom with
<groupId>, <artifactId> and <version>.
Then, in your pom, you point to them in your dependencies list.
mvn deploy
By the way, if you wander what the groupId should be, you have two options:
com.yourcompany.trirdparty
or
com.whatever.the.original.groupid.is.groupId
I have some local jar files from a non-maven project which I wish to include in my maven-based eclipse project.
These jar files are undergoing a lot of change as me and my project buddy attempt to 'fix' them, so I'd prefer not to upload them to a repository to avoid making a maven version of this non-maven project if this is possible.
Of course, the jar files need to be embedded in the resulting deployment jar. We did this before using Ant which let us specify that those jar files should be included.
How do you do the same thing in maven? Take into consideration that we do have maven dependencies too which all work fine and aren't required in the deployment. Some answers I've seen don't allow for this requirement.
Here's one of my attempts - the problem is that the jar does not get embedded:
<dependency>
<groupId>se.krka.kahlua</groupId>
<artifactId>kahlua-core</artifactId>
<version>5.1_2.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kahlua-5.1_2.1.0-core.jar</systemPath>
</dependency>
System paths are a very bad idea. When anybody else checks out your projects, he cannot build it anymore. (I always see such crap in many companies). The right solution would be to install the jar into the local repository:
$ mvn install:install-file -Dfile=[JAR NAME] -DgroupId=[GROUPID OF
JAR] -DartifactId=[ARTIFACT OF JAR] -Dversion=[VERSION OF JAR]
-Dpackaging=jar
In your project, you just add the dependency as usual after you installed the jar into the local repository.
<dependency>
<groupId>[GROUPID OF JAR]</groupId>
<artifactId>[ARTIFACT OF JAR]</artifactId>
<version>[VERSION OF JAR]</version>
</dependency>
You can use maven-install-plugin to install kahlua-5.1_2.1.0-core.jar into the local repository then this dependency will behave as any other, see http://maven.apache.org/plugins/maven-install-plugin/usage.html. Or make a remote repository in a location shared with your buddy and let him upload his jar there with maven-deploy-plugin:deploy-file (http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html) each time he changes it and add this repository to your pom. You can use SNAPSHOT version if this jar changes often
I'm building a Java project that has a dependency on a library. mvn.bat clean install produced the target subdirectories as expected, and the project built fine with mvn.bat clean install as well.
What's not expected is that when I deleted the entire directory of the library, the outer project still built fine, although the library it depends on was gone.
How does this work?
UPDATE: Turns out Maven makes some sort of cache in %USERPROFILE\.m2.
You are most likely thinking of your local repository where everything you install locally (and maven downloads for you from the central repository) is put for later usage.
The behavior you describe is intentional, and allows for building A once and then let B reference it whenever needed, without having to recompile A every time. This is usually very desirable, especially in teams or with large code bases.
Note, that for changing code you should be using -SNAPSHOT artifacts. They are treated slightly differently.
Your dependencies are always downloaded into .m2/repository.
If you want to have some predictability on downloaded libraries in your team, you can put in place a repository manager like Nexus : https://repository.apache.org/index.html#welcome
Instead of downloading dependencies from Maven central, your developers will download their dependencies from this repository manager.
I am having a java project with a ant build file, using this ant file i create an ejb of the project and deploy it on the jboss server.
Now I am planning to use maven and convert this existing project which consist of nearly 28-30 jar's in its class path(jars related to ejb3, hibernate, jboss, etc).
I can easily do it using eclipse i.e right click project goto maven and click Conver to Maven.
A pom.xml is generated and the MavenClassPath Container is also added to the project.
Now I want to know how to get rid of those 28-30 jar's present in the lib folder of the project and in the classpath. i.e. I want my pom.xml handle all the dependencies.
Does Maven provide any mechanism to achieve this goal while converting the project or I have to add all of these jar dependencies one by one manually in the pom.xml file.
The intention of doing this is I want to have common maven remote repository where the jars will be stored and each developer machine will point to it through their maven project.
Thanks
I think you're after a repository manager like Nexus (I use Nexus, it seems to be the most popular http://nexus.sonatype.org/ ).
Nexus can be used as:
A proxy repository (for Maven Central, etc)
A repository for your own releases.
Nexus provides user management for your developers to release builds into the repo.
Developers will then point their Maven settings.xml file to your Nexus repository, and all their dependencies will come from here (Nexus will cache them).
I'm afraid you will have to configure the dependencies individually, but that is a good thing, because you should pay attention to what version ranges you are interested in for each dependency.
Any jars which can't be found in Maven Central, etc, you can add to your own Nexus repository .
Ofcourse there are alternatives to Nexus, but I haven't used any.
HTH
The most important thing i can recommend is to use a Maven Repository Manager (Nexus, Artifactory or Achiva or other..).
Second your pom conversion via Eclipse shows me that you are not using an up-to-date Eclipse nor an up-to-date Maven Plugin for Eclipse. The best thing would be use Eclipse-Indigo (m2e is the newest and greatest).
Furthermore you have to go through all your jar's and add them step by step to you pom (dependencies) and see if your project can be compiled. This should be checked on command line not inside Eclipse.
After you got a working pom.xml file put it into your version control and check if you can remove some of your added dependencies based on transitive dependencies. After that you can finally delete your lib folder.