I have a maven-java project and I use git at the same time. Now I need to use some libraries which does not have any maven support. I have the .jar files of the libraries.
How will I add them to my maven project? and.. Will the other people who pull my code from my git repo be able to run my code without having the .jars?
If you have an artifact repository manager such as Nexus, Archiva, or Artifactory, you can deploy the jars to it. Then you can define them as dependencies in your pom.xml files.
If you don't, you can install them to your local repository using the maven-install-plugin using the install-file goal.
If you don't want to do that, there's also a not-recommended option of defining a dependency with <scope>system</scope> as illustrated here. Again, this is highly NOT recommended, as you would be expecting people would have the artifact on their file system and quite possibly, this jar might end up in your version control, which is really not the way to do it, but is also possible.
answer is that others will not be able to build your code unless some conditions are met.. As mentioned by carlspring, you would have to either install to your own local repo or put a system scope dependency.
if you add it to your local repo, then your local would have to be
some kind of common network writeable share/location that your entire team maps to in a standardized fashion in your development environment.
if you add a system scope dependency, you could actually put this jar into your codebase into a project relative lib directory and provide a path such as ${basedir}/lib/some.jar
Related
I am trying to export to the dependencies of my project using:
mvn dependency:copy-dependencies -Dmdep.useRepositoryLayout=true -DoutputDirectory=c:\output
The result of this is a subset of my local maven repository containing some jars that only I have on my machine.
I am trying to SHARE this subset of my local repository with my colleague.
All I want is to send this folder structure so he can import it to this own local maven maven repository.
We tried to copy these folders in his own local repository knowing this won't work.
My question is there any way to tell maven to "index" these files that were copied in the directory?
There are descriptors next to these files and inside the META-INF folders that makes me believe that group-ids, artifact-ids and version could be resolved.
Is there a solution or a workaround for this?
We could use mvn install:install-file for each individual jar, but there is too many.
Thank you very much,
Peter
So, there two solutions to your problem:
The real and standard solutions to share jars inside a company is to set up a Nexus or Artifactory server where you deploy your build artifacts to and which your colleague uses. Actually, if you develop with Maven with more than two people in a company, I would always set up a Nexus/Artifactory. They are for free and easy to use.
If you really want to go forward with your approach, you can give the whole directory to your colleague. Then you can put this directory as a repository into the settings.xml and use it. Repositories can be local directories, they need not be remote repositories. See e.g. this answer https://stackoverflow.com/a/28762617/927493
If you want a quick workaround, then you can make a copy of your entire repository and then remove the elements that you don't want to include. Compress the whole repository folder, pay special attention to include all the hidden files and send it.
This way you will include not only the metainfos that are in the jar folders, but also other metainfos that are spreaded in other folders inside the repo.
Your colleague will need to use that repository instead of their own (althought I would make a backup until doublecheck everything works ok). This way should work. The dependencies he had in it's own repo should be downloaded automatically again if needed, as long as he have access to remote repos.
I don't have an internet connection at work, and I want to bring there a specific library.
So I want to be able to download at home an artifact along with all of its dependencies (recursively), in order to be able to take all of these jars and bring them to work.
I have read on this site about dependency:get, which is great but downloads the artifacts to the local Maven repo (~/.m2/repository). This means that after downloading, I need to look at pom files and manually copy all of the dependent JAR files to some directory, which I can then bring to work.
I would love to have a way to simply download the desired JAR and all of its dependencies into a specific folder.
Is there a way to acheive this?
Please note: this question is different than the mentioned duplicate, in that I'm asking how to do this without any project or pom.xml file. I'm looking for the simplest way to do this.
EDIT: I believe I found a possible solution (not the most elegant though..):
Rename the local repo (~\.m2\repository on my Windows machine) to repository.old. Create an empty directory repository at the same location instead.
Run
mvn dependency:get -Dartifact=<groupid>:<artifactid>:<version>
This doesn't require a pom.xml or a project.
The artifact and dependencies have been downloaded to your local previously-empty repository (~\.m2\repository).
Move the local repository to wherever, and rename repository.old back to repository.
(I think) you now have all the dependencies for your desired artifact.
dependency:get will load everything you need in .m2 then when you are offline you will be good. I don't think you need to do anything else.
Test it by disconnecting your machine for your network when you are at home.
Normally the dependencies are downloaded when maven is updating the indieces.
As you can see in this post: What is Eclipse doing when it says that it's updating indexes? you just need to enable eclipse or whatever ide youre using to download the sources as well.
We have a core set of java libraries, published as jar files, that are used in multiple client projects. Both the library projects and the client projects are on our git server (GitLab EE). Sometimes clients and third-parties (such as sub-contractors) have access to the project source code, but we don't want them to have access to the source for the core java libraries.
So what I need to know is how to set up some kind of dependency or similar in git so that we can automatically pull in the latest version of the library file? I've been looking at git submodule, but that looks like it will pull in, or at least give access to, the full source of the library projects. I've also started looking at Maven, but I'm unclear whether that also needs access to the whole repository. Is there another/better way to do it? Or will Maven actually do what I want? Or do I need to publish my jar files somewhere else, and if so how can I automate that process, as I don't want to have to manually copy the jar file somewhere every time it's updated (which is often)?
Maven and a binary repository like Nexus is the common way to do what you're asking. Nexus stores binary files like .jar's .dll's etc and Maven has the capability to publish and retrieve specific versions of these binaries and include them when building the project. As Ryan commented, Maven Central is a public binary repository that you could publish to if you wanted the whole world access to your .jars, but with Nexus you have fine grained access control over your binaries.
If you build your own projects with Maven, you can configure it to build, test, and publish right to your Nexus repository with a single command mvn deploy. Then clients just have to update their project to point to the new version and Maven will download it and use it on the classpath. It's all very seamless, and I would definitely recommend refactoring your build process to use Maven or a similar product.
i am working with others developers on eclipse project. The project is hosted on SVN. I wonder how I can add JAR file to the dependencies.
Thank you.
Could you be more specific...
What do you want to do? Add some jar files to your SVN repository?
This is strange...cause you have to share on SVN just the project not compiled, to be able to evolve the code line wit your team...but not the jar files...they could be published on a remote repository like Artifactory or Nexus but no under SVN, for me, it does not make sense.
Not on SVN...but maybe, simply, i don't understand your question...
Try see this -----> Java jar files into a repository (CVS, SVN..)
First, what do you mean I wonder how I can add JAR file to the dependencies.?
Do you mean that you need to add a jar to the compile classpath in Eclipse? Do you mean there's a jar that you need to access whether locally built or from some open source project somewhere on the web?
Is this a jar that Project "A" builds and Project "B" needs?
You can simply check the jar into Subversion. That way, when someone checks out the project, they have the jar. This is a common way to handle this issue, and it's known as the wrong way.
The right way is to use Ivy or Maven, and then use a third party Jar repository like Nexus or Artifactory to host your locally built jars that your projects need. Then, use m2eclipse or IvyDE to connect your repo to your Eclipse project.
Doing things the right way is a bit more difficult, and you and your developers will have to learn Maven or Ivy and how it works. In the end, it makes your development faster and easier. Plus, knowing something like this can help your future career.
My project requires some external libraries to build in in Eclipse. They live in /trunk/lib whereas my project is in /trunk/projectA. To get Eclipse to find the libraries on all machines we set a variable PROJECT_A_HOME.
Now I'm trying to get some builds going with maven and I can not figure out how to add that path (be it environmental variable or relative to $(basedir)) to the build. I really do not want to set up a repository for these dependencies, as I keep them in source control and want builds to continue to work in Eclipse.
I've seen talk about but that hasn't worked for me.
Ideas ?
You should put your static configuration files in resources/ dir. If you have your own or proprietary jars you should set a your own repository so you can download them from the repository or better yet just install them manually , here is how
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Setting up a file-based repository as suggested in this previous question would allow to keep the libs in your version control system and work seamlessly at the Eclipse level (the libs would be treated like any other dependency). The only problem I can think of could be at the continuous integration level: a build of projectA would require a checkout of trunk/lib. Many CI tools would allow to implement this though. And if not, moving the libs under projectA (or another mavenized project project if you need to share them between modules) would do the trick.