Using an external .jar file in a vsts hosted Maven build - java

I have a Maven project with several dependencies, all taken from the Maven repo. The project is hosted / stored in VSTS and uses CI. All bar one of the dependencies were available from the Maven Repository online so now I have to find a way of adding this .jar file to this project (and VSTS for the CI build) and making Maven recognise and use it.
Can anyone point me in the right direction?
Thanks

If you don't have or want a Nexus/Artifactory, I would install the jar on every relevant account/computer with the help of the Maven install plugin (see https://stackoverflow.com/a/4955695/927493).
But let me stress that it is standard practise to have a Nexus/Artifactory running in the company - there are free OpenSource versions, and they are easy to set up. Furthermore, you have a canonical place for the artifacts you create yourself.

You should be able to create your own feed with the VSTS Packages Extension.
See here for instructions how to setup a feed and publish an artifact to the feed.
This is an alternative to Artifactory and is no extra cost to your existing VSTS.

Related

Adding local jar (oracle driver) to Maven and Bamboo

I need to use the oracle database driver (oracle.jdbc.driver.OracleDriver) for a project but Oracle does not have a Maven repository for it, so the only way that I have found is to download it onto my machine and then "install" the .jar to Maven as seen in this article.
However, now it is time to add the project to my work's Bamboo build server, but of course the build fails because it can't find the oracle driver.
My question is: how is this sort of thing generally handled? There doesn't seem to be a way to "add" a .jar to a Bamboo build and then point Maven on Bamboo to that .jar. Another alternative that I'm trying is putting the oracle .jar on an internal git repository but I don't know how to point Maven to pull a .jar from a git repository (my current understanding is that maven repos and git repos are different thing entirely).
Any tips or suggestions appreciated, thank you.
The usual way is to set up a Nexus/Artifactory on a server. This server is used for the built artifacts (your Bamboo deploys the EARs/WARs/JARs to it), to proxy external repositories (not necessary, but will speed up things) and to manage third party jars that are not available elsewhere.
In your settings.xml you just point to this Nexus/Artifactory and do the same for the Bamboo.

How to share a maven archetype via email to be used in Eclipse?

I have an eclipse maven-based proyect that I want to share as an example of use of a big library. I have downloaded and installed maven, created an archetype from the proyect (mvn archetype:create-from-project), installed it in my local repository (mvn install) and tested it (archetype:generate -DarchetypeCatalog=local).
Now, I want to share the archetype with a few people. I want to send them a file/files that they can add directly to their eclipse environment to create new proyects using my archetype, but I can't find a way. I don't want to set up a remote repository.
Thanks in advance.
Follow this URL is has all the steps to host your archtype to the central repository. Once it is on the central repository, it can be used by any user in their project.
https://maven.apache.org/guides/mini/guide-central-repository-upload.html
I just realized that Maven is a solution to a much bigger task and was never designed for the way I intended to use it.
Maven depends on servers for distribution of artifacts (an archetype is just one kind of artifact) and sending them by email wasn't a planned use case.

Maven: download file and run command to build dependency

Recently, a project I need as a dependency for some of my programs has switched to providing patch files instead of actual jars (legal reasons).
They included a small tool to automatically patch your existing jars with the new update you downloaded.
I could write a small program that automatically downloads and patches the file, all I need is a way to tell maven not to download the file but to run a command and then use the file from my local repo.
Is there a way to do this (maybe using a custom plugin)?
You could write a small ant task run the tool and call this task from your maven build using maven-antrun plugin.
You could also write your own maven plugin but for such a simle task I would not recommend it.
The reason why your IDE does not find the dependency is that it is not published anymore (not the version you seek apparently).
Building the artifact and installing it locally as #Joe suggested is an elegant solution to solve your issue from my perspective.
The advantage is twofold:
Your IDE can seamlessly find the missing artifact
You can keep multiple version of that dependency (one for every new patch) and thus reproduce previous (working) build in case a new patch breaks something.
if you have a local repository, it is even better as this would maven the dependency available to all your team.
Of course you would still need a tool to download new patch, apply them and deploy the produced artifact to the repository automatically. But doing this as a separate task give you more flexibility concerning the tools you could use.

use of Maven for Java web development

I am new to java web development and the book I am using to learn uses Maven and Tomcat for development. After searching some basics about Maven on internet all I know is that it is a tool for managing dependencies in project. I am using Netbeans 8 and every time I create a new project or clean-build an existing project Maven downloads lots of files. Is there any way I can keep a common place/repository for all my Maven projects which can be used locally? I have gone through some existing answers on stackoverflow but for me as a beginner they are difficult to understand.
Maven indeed has such a local repository (in .m2/repository in your home folder) where the files found to be needed are downloaded are automatically stored for future use.
The source repository - Maven Central - is very large, so you do not want to download everything as you will most likely not need most of it.
If you need to go offline, or want to be sure that everything you may need in your current build, you can run the dependency:go-offline target. You can then safely use the -o switch to maven to avoid network usage.
When you create a Maven project and build it for the first time, Maven will automatically create a local repository for you, downloading the necessary jars for your project to this location. From then on, all your maven projects will share this repository.
On Windows, the default location for your local Maven repository is
%HOMEPATH%\ .m2\repository
You will find this page useful: http://maven.apache.org/guides/mini/guide-configuring-maven.html
You can also download 'Maven the complete reference' for free as a PDF from here: http://www.sonatype.com/resources/books/maven-the-complete-reference/download

Applying Maven to a project

I've been asked to apply Maven to a project. After browsing a dozen sites it appears that it's quite vast and I'm not familiar as I'd like with similar tools like Ant. Why is it used/preferred and what does it offer over a standard Eclipse project? Also, how could it be added to an existing project?
Why is it used/preferred and what does
it offer over a standard Eclipse
project?
It is a build tool which can build your project without the need for an IDE like Eclipse. It can create a jar or war or other artifacts from the source, performing a bunch of steps like compilation, running unit tests, etc.
Where maven scores over ant is in managing third-party dependencies and in convention over configuration (which mean less lines of build script if you follow convention).
Also, how could it be added to an
existing project?
You start by creating a new maven project, following the step here.
Place it in the root folder of your project
If your source and resource files do not follow maven folder convention, update maven properties suitably referring to this documentation.
Run mvn package
It will fail if it needs any third party dependencies, which you can add as specified in the doc
With some trial and error, you should have your project running with maven, possibly, much quicker than if you were to set up the same with ant.
Others are already provided sufficient resources to read more about maven.
I suggest to start reading here:
http://www.sonatype.com/books/mvnref-book/reference/public-book.html
Maven is a great tool when you know how to use it. Maven (at core) is a dependency manager.
You include in your pom.xml (similar in function to the build.xml from Ant) all the librairies your project depends on (example : apache commons) along with their version and Maven get them directly from a repository (by default, the central maven repository)
Then you do not have to manually install any jar to make your project work. All is downloaded and cached on your local machine. You can even create an enterprise repository where you put all the jars needed by your company
Maven uses the concept of artifacts which are pre-built library projects with their own dependencies
To mavenize a project, you'll have to write a pom.xml describing your project (examples are numerous), get rid of your libs directory (or whatever classpath you described under Eclipse) and add all your dependencies to your pom.xml
You could also check Mavenizer for a first-start
But Maven is a lot more what i've just said. Read the docs, read poms from librairies and you'll get used to it quickly ;-)
If you use the M2Eclipse plugin from Sonatype, it's just a matter of right clicking the project in the package explorer and choosing Enable Dependency Management in the Maven menu. You are also advised to adjust the directories that contain the sources to the Maven standard directory layout but if you absolutely can't, you can configure that later.
Apart from that: Well, look for tutorials and documentation (for example there is the free book Better builds with Maven. Maven is very complex (yes, I don't think it is simple) and very powerful.

Categories

Resources