How to convert Ant project to Maven project - maven-2

How to convert a Ant project to Maven project? A sample project that would link (a Wicket project)
Thanks

The nice part of using maven is that most standard stuff works automatically once you do things the maven way. For a simple webapp:
Create a pom with groupId, artifactId and version (packaging: war)
Add the required dependencies to the pom
move the
java sources to src/main/java,
resources to src/main/resources,
webapp content to src/main/webapp,
test content to src/test/java and src/test/resources
set the compiler compliance version using the maven compiler plugin
That should get you up 'n' running.

http://www.sonatype.com/people/2009/04/how-to-convert-from-ant-to-maven-in-5-minutes/
I don't know what your ant script looks like, but assuming its a basic script for building, you will need to create a pom.xml file for your project, add your dependencies, and then build it via maven.

For anyone who lands here in future, there is an easier way to find dependencies for maven using the file hashes. So, you won't have to guess artifact versions.
As per the below article, the idea is to generate a SHA1 checksum of the dependency that you want to find the information, then do a reverse search in Nexus repository manager using that hash. For the checksum generation, you can use Microsoft's FCIV (free) utility.
https://devreads.xyz/ant-to-maven-conversion-the-painless-method/

Related

Dependency on package in git without jar file

I am distributing a Java package via git for other people to use. I am currently supplying a jar file to go with the source. This way, the user only needs to clone the project once into Intellij IDEA. Projects using the package can then follow this procedure
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
to use the package.
This works, but distributing a jar does not feel nice security-wise. On the other hand, this discussion
IntelliJ IDEA - adding .java file to project dependencies
suggests that to use the source code, you need to copy it into your src folder.
Is there a way to distribute source code (java files) only so that if multiple projects use the same package
the package only needs to be downloaded once
the package can be kept up to date with git pull?
I would really recommend not include jar or any binaries in a Git repo and the best approach to keep these dependencies in a local Nexus repository and use maven or Gradle as your dependency management tool.
I found a working solution:
Supply an Ant build file with the package. The build file compiles classes and packages them into a jar file. The default target is building the jar, which depends on compiling the classes.
Provide users with instructions on how to set the given Ant build file as a build file in Intellij IDEA and build the default target.
Then instruct them to follow the steps in the first link above to add the jar as a dependency.

Convert web application project to maven project and convert corresponding .classpath file to pom.xml

Is it possible to convert project .classpath file to pom.xml after converting a simple web application project to maven project? Because if my project uses many jars and I want to convert it to maven then I will do configure->convert to maven but then it is not possible to add all the jars dependencies in pom.xml manually. So is there any tool to convert this.
First there is no tool to do such things. The problem is usually that you have a larger number of dependencies which you don't need to put into the pom.xml file, cause Maven handles transitive dependencies which means you only need to add only direct dependencies. The best thing is to look at the current projects jar files and try to find them in Maven Central and cut&paste the information form the search output into your pom. And of course test the build via Maven on command line.

Can I install several files into one artifact with Maven2 instal:install-file command

I'm developping application with JOGL2 and my favorite IDE Eclipse, also I want to use Maven2 for this purpose. Unfortunately, JOGL2 has no artifact yet. Also, I plan to deploy it as a runnable jar file.
So I want to install JOGL artifact locally : so i'll use the install:install-file command.
But I want to group several jars to make several artifacts, that is :
gluegen-rt.jar and jogl.all.jar as a single artifact named jogl.core
gluegen-rt-natives-linux-i586.jar and jogl.all-natives-linux-i586.jar as a single jar named jogl-natives-linux-i586
and so on
Is it possible ? (The official documentation does not mention the possibility or unpossibility to do so).
Thanks in advance
Install all files as usual like file:jar:version. Than create pom with pom packaging and use gluegen-rt.jar and jogl.all.jar as dependencies in it (they must be already installed). After that use new pom as dependency in your project.
maven doesn't have support for that. You would have to unpack these JAR files and repackage them together.
maven does have support for merging JAR with dependencies (http://stackoverflow.com/questions/574594) - and it's done the way I mentioned above. But you are asking about merging two arbitrary JARs, which is not possible in maven.

ant/maven integration

I have a project that is built and managed by Maven. I have a second project that has an ant build. I'd like to reference the maven project from the ant project and pull in all of the required dependencies. Can anyone suggest a way to do this?
thanks,
Jeff
The maven-ant-tasks work quite well for this sort of thing.
You can use Ivy:
Ivy can therefore be used to bring the
dependency management feature of maven
to Ant build files, for those of you
who already use Ant and who do not
want to setup a maven project.
Apache Ivy is an Ant library that can handle Maven-style repositories.
Here's a page which describes the differences between them and how to integrate the two.
There are a set of ant tasks for Mercury that allow you to perform dependency management tasks, specify configuration (e.g. server credentials), modify/alter the ant path and write to the repository. See this blog for details.
There are also Maven tasks for ant, though they are not as fully featured. Maven is moving towards Mercury (particularly for Maven3) so it makes sense to use the Mercury tasks.
The following configuration reads the dependencies from the specified pom and populates the specified variable with the resultant path:
<path id="my.compile.path">
<deps>
<dependency name="groupId:artifactId:1.0::pom"
pom="${basedir}/artifactId-1.0.pom"/>
</deps>
</path>
You can also use the Mercury tasks to deploy to a Maven repository using an Ant build file:
<repo id="myRepository"
url="http://localhost:8081/nexus/content/groups/public">
<auth name="myUser" pass="myPassword"/>
</repo>
<write repoid="myRepository"
name="my.group.id:my-artifact-id:1.0"
file="${basedir}/target/my-artifact-id.jar"/>

Maven and Spring

Hi i am studying Spring In Action 2.0 and i am new to maven.
I am walking through the chapters and codes but i i got following error when i imported project through pom.xml on the pom editor in eclipse.
6/21/09 3:19:42 AM CDT: Missing
indirectly referenced artifact
incubator-activemq:activeio-core:jar:3.0-beta3:compile
6/21/09 3:19:42 AM CDT: Missing
indirectly referenced artifact
incubator-activemq:activemq-core:jar:4.0:compile
I downloaded the jar file and added to the library. still it does not work.
I am stuck what to do next? Can anyone help me with this?
Thanks in advance.
The referenced jars aren't available on the Maven2 central repository, so unless you have an additional repository declaration in your POM or an active profile in your settings, Maven will not know where to obtain the artifacts from.
There are a few public repositories like here and here hosting these artifacts.
To use these repositories you could add the relevant repository declaration to your POM or settings. See here for an example configuration.
Alternatively if you don't trust the repositories you could manually download the jars and put them into your local Maven repository, though you'd need to be careful to replicate the structure Maven expects, and you may well encounter the same problem for different jars.
Another alternative is to use a Maven repository manager like Nexus or Artifactory, to manage Maven's interactions with external repositories, though that is almost certainly too much information if you're just starting out.
For general help/information on Maven, check out the Maven book.