aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Migrating to Maven...how to build the pom dependencies section from .classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Migrating to Maven...how to build the pom dependencies section from .classpath" Watch "Migrating to Maven...how to build the pom dependencies section from .classpath" New topic
Author

Migrating to Maven...how to build the pom dependencies section from .classpath

Jeevan Sunkersett
Ranch Hand

Joined: Jul 03, 2007
Posts: 77
Hi,

I know Maven and have used it too;

To create and eclipse project from a maven, we have mvn eclipse:eclipse to generate the .classpath and .project and then import the project in eclipse.

Is there any easy way to do the opposite.

I have a eclipse project, with a lib folder with many jar's and added manually to the .classpath (java build path)

Writing the pom.xml by hand is quite a task. ...so this query

~g1
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5836
    
    7

Not sure if the m2eclipse plugin provides such a capability, but that plugin is worth having even if it does not.


JBoss In Action
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

That's a sticky problem. Manually-included JARs would simply go into the project resources folder and not even be mentioned in the POM. The POM dependencies control dynamic downloading of JARs that are not explicitly included in the project. But to do that, you need to know where the original copies are located.

First, you need to know the repository, if it's not the standard one.

Secondly, you need to know the group, artifact ID and version of each JAR that you want added to POM control.

I suppose this COULD be done. You'd need to build up a database, however, since the group and artifact IDs aren't easily predictable. Given that, you could create an app that scanned the project tree for JARs, ripped out the Maven-controlled ones, and added a corresponding dependency to the POM file. There are probably some subtleties beyond that, but that's the basics.


Customer surveys are for companies who didn't pay proper attention to begin with.
Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Hi Tim,

Sorry to jump into the middle of the conversation, but this thread is addressing one of my questions exactly. I am a total newb here, but Katrina Owen (who is a very active member) said this was THE place to find great help with Java, so here I am.

Is what you are saying true?

I used Maven1 about 15 years ago and was impressed with the approach. That was about the last time I wrote any appreciable Java code as well (been doing Smalltalk, C++, C#/VB.NET, PHP, Perl, and a bit of Python since then). Now I find myself in an architect role at a Java-shop, successfully recommending that we move away from Ant and toward Maven, which I am very excited about. BUT... I am having a hell of a time knitting the pieces together.

I have a very simple existing project called "library," which is exactly what it sounds like - a collection of classes defining commonly used functionality. It has no inter-project dependencies, but relies on several 3rd-party JARs (like dnsjava, commons-lang, jmagick, etc.). I have been trying to figure out (by scouring a dozen solid Maven-related websites, the O'Reilly "Maven - The Definitive Guide" and "Maven - A Developer's Journal" books) how to add these JARs as dependencies.

Am I just missing the point of a dependency from Maven's POV? Are these just resources? If so, how do we use Maven to manage them when new versions come out? For instance, the Maven Repository has dnsjava in it, but only up to 2.0.1, and we are using the 2.0.2 JAR.

Any illumination you or anyone else can shed on this would be tremendously helpful.

Thanks, and apologies if I stepped on any forum posting protocols here.

Chris


"It is our choices, much more than our abilities, that make us who we are."
- Albus Dumbledore
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris,

Yes from Maven's POV they are dependencies. If you cannot find them on the Maven central repo (or the couple of other major repos out there, e.g. Java.net and jboss) then you need to probably use a local repository manager. The two documents you mention discuss this, in particular Artifactory and Nexus are quite good.

Hope that helps!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Hi Martijn (and all),

Sorry if this posts twice... didn't look like my first attempt took.

Sorry to be so obtuse about this, but I think I am missing some key bit of information. I am using Nexus' Repo Manager and am connected to Maven Central, Apache Snapshots, and Codehaus, all of which are downloading remote indexes and added to Public Repositories. I will try adding Artifactory, JBoss, and Java.net as well.

I think what I am not getting is simply how you differentiate a "dependency" from a "resource." How do you?

I saw something (maybe in "Maven: The Definitive Guide") that said something to the effect that any local JARs should be placed in the resources folder of the project, but that seems counter-intuitive to Maven's handling of the dependency graph... And it brings up the question of what do you do when you cannot find a JAR in a repo using Maven coordinates? Do you throw your own copy of the JAR into the resources folder, or SHOULD it be added as a dependency?

For instance the project I am working on uses the JMagick JAR, but I cannot find it in the repos I have available. What is the common way (or best practice) for handling that?

Thanks for bearing with me on this. I really appreciate the help.

Cheers,

Chris
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris,

In this case you would manually add this to your local repository _via_ the repository manager (in your case Nexus). You'll add it with a group id, artifact id and version of your choice when you add it, Nexus should have a nice UI for you to do this and will create the extra meta data etc automatically. You then reference that jar in your pom like you would with any other dependency.

Christopher Burns
Ranch Hand

Joined: Oct 21, 2008
Posts: 33
Ok, great. That is my understanding, but that blurb about resources threw me.

Are resources any non-archive project-related items like traditional C++ resources (images, config files, properties pages, etc.)?

Thanks a million, Martijn!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi Chris,

Yes you are correct about those '3rd party resources' and you're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Migrating to Maven...how to build the pom dependencies section from .classpath