Am a new bee in this area.
Got a part in pom.xml like below which i need to change in ant buid.xml.
How do i do it? Can i get any help from tutorial or anyone can explain what
<dependency>
<groupId>com.ask.core</groupId>
<artifactId>wzlogging</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
</exclusion>
</exclusions>
</dependency>
In theory it's possible to generate a ANT build file (using XSLT?), but one would need to understand the logic that each plugin implements. In practice only simple Maven builds are feasible candidates.
ANT and Maven are very different build technologies. In ANT you explicitly write all the build logic into the "build.xml" file. Maven on the other hand has most of it's functionality baked in. The "pom.xml" contains no logic instead is used to document meta information about the project (for example the list of dependencies).
Coming from an ANT world this can be very confusing, especially when you want to customise your build. In Maven this is done by declaring plugins, which understand the standard build life-cycle and are able to insert themselves at the correct part of your build.
The purpose of this long-winded explanation is to understand that it's really impossible to know what your plugin is doing by only looking at the POM file.
#Perception recommended ivy. The following answer is related (Convert from ANT to Maven):
Converting Ant Web Application Project to Maven Project
Maven and ant are very different tools.
Ant is a build tool primarily, this means it knows how to compile and package source code and run tests, but has no ability to manage project dependencies. Ant uses build.xml files to define where to find the source code and which steps to take to build your project.
Maven is more than just a build tool, it is a project management tool. It allows you to define dependencies in the pom.xml project definition, as well build, test and distribute the application. It also allows sub projects, parent projects and there exist many plugins for many other features. Maven will automatically download the dependencies and manages these dependencies between projects.
Simply put, it is not possible to just convert a Maven POM project into an Ant build.
There are alternatives that allow binary maven dependencies to be utilized within ant builds. Have a look at the Ivy dependency manager for instance.
Maven has a useful Ant plugin to generate a Ant build file from Maven pom.xml easily.
Use this maven goal: mvn ant:ant.
In eclipse: Simple generate another run-configuration for a maven build. Name it "Antfile generate". In field "Goals" Enter ant:ant. Apply these changes to you new run configuration. Typ run to start the build. In console log you get an message
[INFO] Wrote Ant project for PROJECTNAME to .
Related
GIVEN:
I have an in house tool built with gradle that includes a dependency that is only a POM file which in turn then includes a bunch of other dependencies. No jar for this particular dependency by itself. The tool builds.
I have a maven project with a pom.xml file that I want to include this tool in because of all the company specific methods needed for some processes. I added the dependency with the type of pom and when I build it fails.
ERROR:
[ERROR] Failed to execute goal on project <MYPROJECT>: Could not resolve dependencies for project <MYPROJECT>:jar:0.0.326: <com.pom.only.dependency>:jar:7.0 was not found in <Company Repo where this POM file exists> during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of <company repo> has elapsed or updates are forced
REQUEST:
I have tried making the tool a fat jar in the hopes it would not need this. But it does. The my project builds without this tool jar so I know it is this jar that brings in the dependency. I just have no idea how to resolve this.
ALMOST CODE EXAMPLE
Because of company specific, I can not put the exact POM code but I can put what it looks like removing company specific stuff.
<dependency>
<groupId>com.group</groupId>
<artifactId>tools-app</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>com.group</groupId>
<artifactId>pom only dependency</artifactId>
<version>7.0</version>
<type>pom</type>
</dependency>
So tools app is the one that I am pulling it. It is the gradle build and uses the pom only dependency without any issue. If I pull this into a gradle app it works fine and builds. However, in the app that has this in the pom, if fails for above. So I add the dependency for the pom only dependency and mark it as type pom but still get the error.
So for my situation (and not the best solution), I went into the dependency that has only a pom and pulled the dependencies out of there and built. It worked. But feel there should be a way to make it work without having to do this.
I need to add the package "uk.ac.shef.wit.simmetrics.similaritymetrics"
to my maven project but I am not able to find any remote repository which contains it. I have to add it via dependency to the project, but not successful yet.
-I already added the jar file to the referenced library but in that wat I get the following error:
package uk.ac.shef.wit.simmetrics.similaritymetrics does not exist.
-Adding it through following dependency to the Pom.xml also does not help
<dependency>
<groupId>uk.ac.shef.wit</groupId>
<artifactId>simmetrics</artifactId>
version>1.6.2</version>
<scope>system</scope>
<systemPath>LocalPath\simmetrics-1.6.2.jar</systemPath>
</dependency>
Any help is appreciated!!
If this is a small project that you intend to only build locally or on a few machines then the simplest way is follow directions at the site below to add a 3rd party jar. Those instructions will help you install it in your local repository. You will need to do that for all machines that you intend to run the build on.
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
If you plan to run it on many machines then the best thing to do is to install the artifact to your own private repository. If that is the case then I suggest you create a project for it in version control. Then upload the file as part of that project.
I appear to be the current maintainer of Simmetrics. You can add this dependency to your pom file.
<dependency>
<groupId>com.github.mpkorstanje</groupId>
<artifactId>simmetrics-core</artifactId>
<version>4.0.1</version>
</dependency>
Simmetrics has been given a much needed serious overhaul since 1.6.2. You may have to adjust your code accordingly. For source code and documentation see https://github.com/Simmetrics/simmetrics
I have Java Maven Project with a folder lib with all jars that must be included in my project.
I don't know how I have to modify the POM to add all libraries. I want that Maven uses this libraries and I can use all in the project.
Lets be frank here: you are basically asking how to use Maven but then not use it at the same time. Maven is built around the fact that dependencies are managed from dependable repositories and then you come along and want to bypass that entire system by having local jars anyway as you would have in a project not managed through Maven - like one that is built with ANT.
The true clean solution to "not getting jars from a Maven repository" is to still get them from a repository - your own. Setup a local repository and put your third party dependencies there, then configure your Maven build to know about that local repository. If they are actually dependencies that exist in Maven central then you can setup your local repository to proxy them rather than manually installing them yourself.
http://maven.apache.org/repository-management.html
If you are using the release management features of Maven (or something like Hudson) then you should actually already have such a thing to stick your generated release artifacts into.
You have to know which libraries are you using. Imagine that you use in your project the joda-time library.
So you have to search your libraries (in this case joda-time) in maven repositories and add to your pom.xml like the following:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.7</version>
</dependency>
Here the Maven repository --> Maven Repo
There is a jar file lets say "abc.jar" which maven dependency does not exist(ie created a jar by using java command of own classes). I want to add this jar as maven dependency so that at build time it will automatically copy that jar in lib folder as like other maven dependency. how i will do. please help .
Add it as a dependency with a system scope. See the docs here.
However, rather than adding it as a system dependency it might be better to mavenize the jar itself, then you can build and install it into your dependency management system.
Also, see this question: Can I add jars to maven 2 build classpath without installing them?
You can use the systemPath attribute in the dependency tag in the POM file of your project.
In your pom.xml, use the following snippet corresponding to abc.jar:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>abc</groupId>
<artifactId>x</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>{path_to_abc.jar}</systemPath>
</dependency>
</dependencies>
The scope parameter corresponding to this artifact must be set to system, for the artifact to be picked up from the specified systemPath.
Hope this helps!
A normal maven dependency is always resolved by looking into a repository. So you must put your JAR file into a repository.
You could install your JAR into your local repository. Have a look at the install plugin. The install-file goal is your friend.
If other developers also need this JAR (because they are working with the same project), they either need to install it locally too, or - better - you deploy the JAR to a remote repository. Have a look at the deploy plugin. Here the deploy-file goal is your friend. For deploying artifacts, you need a repository manager like Nexus or Artifactory.
However, a dependency could also have the system scope (look at the other answers).
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)