• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jeevan Sunkersett
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if the m2eclipse plugin provides such a capability, but that plugin is worth having even if it does not.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Christopher Burns
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,

Yes you are correct about those '3rd party resources' and you're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic