maven - create archive of generated jar files - java

I am currently building out some projects using an aggregate pom. It calls out some parent poms that build out the artifacts.
The artifacts build out ok.
What I would like is to capture the generated jar files and place them into a directory as they are created build after build, version after version.
Possible?
Thank you!

Without knowing more about why you want to achieve this, it's hard to recommend a solution.
A mvn clean install will install all the artifacts into your local repository, but assuming you want a more custom directory layout - you could use the maven-antrun-plugin and use ant to arrange the relevant files.
If you're happy with the default repository layout, you could also configure the repository settings for the project to deploy your plugin into a specific filesystem location (which would be dedicated to this particular project).
Alternatively, you could use the wagon plugin to do the deployment:
http://www.java-tutorial.ch/maven/deploying-in-file-system-using-maven

im using a .bat file that runs
cd dir
mvn clean install
copy dir\*.jar %LIFERAY_TOMCAT_HOME%"\..\deploy
what do you think? would that suit your needs?

Related

Deploy Ant project into Maven repository

I am new using Maven and I need to upload some libraries from an Ant project. To develop this task I have one folder that contains a lot of "pom.xml" files that refers to the jar that I would like to add to my project in Eclipse using Maven, and another xml file that is the Ant project itself.
All ideas are welcome. Thanks!
Unfortunately no good tools exists for Ant to Maven migration. You will need going step by step from module to module do so:
Enable maven nature on each project.
Resolve maven dependency by hand.
Deploy artifact into local or remote repository.
Pay your attention on version numbers of libraries. Make sure the md5 hash or sha2 hash of library in ant project and the library received in maven after adding dependency is exactly same. Otherwise you will definitely get some non traceable errors if not during testing but after deployment to prod.

Pre-download all dependencies

I need to release our Maven build Java project to an remote QA team. For this I would like to download all the dependencies, and send them so they do not need to download them.
Currently all dependencies are defined in the pom.xml file, and we use either mvn install or mvn package to build the project. Some of the project members use uber jars, others use jars + dependencies to do execution.
What would be the easiest way to pre-package the dependent jar files so that there is no download from the internet, and does not change our current build process too much?
A possible solution would be to purge your local repository, tell Maven to download every dependencies and plugin dependencies of your project and make a ZIP of that.
To purge your local repository, you can simply delete the folder {user.home}/.m2/repository. Then, you can use the dependency:go-offline goal:
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
mvn dependency:go-offline
This will download everything that your project depends on and will make sure that on a later build, nothing will be downloaded.
Then, you can simply make a ZIP of {user.home}/.m2/repository and send that to your Q/A team. They will need to unzip it inside their own {user.home}/.m2/repository to be able to build the project.
Offline Package deploy
Your requirement can be accomplished by creating a stand alone jar file with full dependencies. You can port it anywhere please refer https://stackoverflow.com/a/35359756/5678086
Build a full dependency JAR file as said in the answer
Copy the JAR to the destination machine you want
Run the below command from there
mvn install:install-file -Dfile=<path-to-file>
This will install the dependecies in the maven repository of the destination machine. This is fully offline
Theoretically if you know which maven commands you'll use (package, install, etc.) you could clear out your ~/.m2/repository folder, run those commands once on somebody's dev box, then distribute the repository folder. You can run maven -o install etc. to have it not give annoying warnings. This might be a slightly smaller distro than the go-offline answer.

Maven: antrun plugin builds JAR file -> How can i install/deploy it in my repository?

I am in the middle of an Ant -> Maven migration project and I have a question (I'm not really a Maven expert), since I'm stuck at a particular point:
Within one of my pom.xml files I have to use the maven-antrun-plugin to call an external ANT file, which builds a jar file and puts it in a temporary folder. There is no alternative to this call. Everything is working fine - the ant script works as it should, but how can I "package" this jar in the usual Maven workflow?
I know that I could manually call the mvn install:install-file, but isn't there a possibility to configure my pom.xml in a way that the above generated jar file IS actually the artifact of that pom.xml?
you use the build helper maven plugin's attach artifact goal to attach your extra *.jar to the maven module that triggered its creation.
since having a single maven module produce more than one artifact is generally a bad idea it would be best if you isolate this in a maven module of type pom so that this would be its only artifact

how include my local jar to maven?

the question is:
i start a local lib to collect some common utils in it.
then i use eclipse m2e to run as Maven Install, and it truely generate the jar into my local cached repos dir.
and now, i want to use that lib as a dependency in my project, i just type the dependency xml as the other (like spring etc.).
but it just can load that lib in the maven dependencies libs.
I search the web and find that systemPath could work, but i don' t like this way. how can i use my local jar in a same way?
Install it into your repository. Either local (mvn install) or run repository software like Artifactory, Archiva or Nexus. http://maven.apache.org/repository-management.html
You can do a (non-Maven) build and:
install the JAR in your local "repo" directory,
manually upload it your group / corporate repository, or
install it in a so-called "internal repository" that you manage by hand: see http://maven.apache.org/guides/introduction/introduction-to-repositories.html.
(I have even resorted to using an "internal repository" that was part of the project's version control check-out; i.e. putting the JAR into version control.)
But I think that the best approach would be to Mavenize the build for the utility JAR, and handle it just like your main Maven projects.
Use goal install-file .
Like , mvn install-file.

use ivy java project in maven?

I have a big maven project with many subprojects that are also maven based.
I started using Red5, and red5 creates an ivy based project. I need to add that project to the dependencies.
list files of project main directory:
build.properties build.xml ivy.xml ivysettings.xml lib readme.txt src www
how can I add this project as one of the maven project dependencies ?
using Java with Maven 3.0.4
thanks!
Kfir
Interesting... A lib directory in an Ivy project.
You can modify the build.xml to create one more target that calls the <ivy:makepom/> target. Just make sure that <ivy:resolve> is called first. This will create a small piece of the pom.xml file you need.
As for the rest. What's that technical term? Oh yeah, you're screwed.
The problem is that Ant and Maven have two completely different build philosophies. In Ant, you write a build.xml script that describes what you want to build and how you want to build it. In Maven, you describe your project via a pom.xml file, and Maven does all the build processing for you.
This isn't an issue of whether or not Whether Ant or Maven is the force of all that's good in the world and the other is only for luzers Apple Fanboys. This is a case of manually converting a pre-existing project into Maven.
You'll have to go through your build.xml and figure out everything it is doing. Then, you need to convert this over to a Maven pom.xml file. There's no way to automate this. Even worse, Red5 isn't setup like a Maven project, so you'll either have to move all the files around, or go into archaic pom.xml configuration hell trying to override how Maven assumes the build is suppose to take place. This can take days, even weeks to get right. And, in the end, you end up with a project you don't control that if you want to update will have to be done all over again from scratch.
Trust me, I did this before for another job where the System Architect decided that Maven was better than Ant, and all of our projects must be converted from Ant to Maven. And, who got stuck with this task? Not the developers who were too busy with other tasks, but I the Configuration Manager.
And, in the end, you will have a project you don't control that if you want to update will have to be done all over again from scratch.
There is an alternative: Ignore it.
Does it really matter if Red5 is an Ivy project? What do you need from this Red5 project anyway? Do you need that red5.jar or the distribution that gets built.
If you need the distribution, let it remain as an Ivy project. Simply set the ivysettings.xml to point to your Maven repository and let it know that it's in Maven 2 format. Ivy will have no problems getting stuff out of that. So what if it's Ivy?
If you just need that red5.jar file in your other Maven project, you can simply use the <ivy:makepom/> task to generate a pom.xml file for you. Then use mvn deploy:deploy-file to deploy that jar into your Maven repository:
$ mvn deploy:deploy-file -Dfile=red5.jar \
-DpomFile=pom.xml \
-DrepositoryId=$repoId \
-Durl=$url
Now, your red5.jar is in your Maven repository as a fully transitive downloading jar. If you really, really want to get fancy, you can embed the generated pom.xml file into the jar itself, so it is self referential just like Maven jars are. That will take about 30 minutes of hacking the current build.xml file. (Or, if your jar doesn't have to have the pom.xml embedded in it, a separate Ant file that just builds the pom.xml you need, and maybe even deploys it into your Maven repository for you. That way, if the project gets updated, you don't have to worry about the build.xml file being updated.
I've not used it myself, but I know Ivy has a task which can convert an ivy file to a maven pom. I'd explore an option where my CI environment runs that task to generate a pom after a successful build, and then get my maven project to look at the CI's latest artifacts for the jar and pom. You could skip the CI environment as well, and have maven resolve artifacts from the local file system.
I don't think you're going to get away without creating a JAR. Maven's whole dependency philosophy is built around JAR files in a repository - when one maven project depends on another the way it works is that the dependent project builds its JAR and puts it in the local repository, then the main project depends on it from there.
That said, you can fairly easily automate this using a combination of <ivy:makepom> and the Maven Ant Tasks. The idea is to make the Ivy project build its JAR and push that to the local Maven repository as part of every build, so it is immediately available for the maven projects to depend on.
<jar destfile="project.jar">
<fileset dir="classes" />
</jar>
<ivy:makepom ivyfile="ivy.xml" pomfile="project.pom" conf="default,runtime">
<mapping conf="default" scope="compile"/>
<mapping conf="runtime" scope="runtime"/>
</ivy:makepom>
<artifact:pom id="project.pom" file="project.pom" />
<artifact:install file="project.jar" pomRefId="project.pom" />
Make sure your Ivy project has a version number that ends with -SNAPSHOT in its ivy.xml.

Categories