This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to handle a project that was not created using maven?

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Suppose I have a  web app project using some standard open source tech like spring, jpa, etc but was not created using maven.  It was just created in some IDE and its size has grown to some scale.  In this case, how do I apply  maven to it ?  Should I convert the entire project into maven project using IDE build-in tool ?


2. Suppose I have a project (or source code in this case) that is not even associated with any IDE, it has proper code structure and it specified its required jar like dependency stuff.  In this case, what's the best way to  apply maven ?

Thanks  
 
Saloon Keeper
Posts: 12264
259
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would first add a Maven POM without changing the project's directory structure. Overwrite the default source and build paths to match how the project used to be built before.

Try to replace all libraries in your project with Maven dependencies. For libraries that aren't built from Maven projects, use this guide: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

After you've done this, use Maven through the command line and thoroughly test your project to make sure that it still works exactly the same way it used to. When you're convinced that everything works, change the project file so that IDEs will use the Maven POM instead of whatever build script they used before. Finally, you can slowly start moving files to a more appropriate location, and change your source and build paths.
 
Saloon Keeper
Posts: 22498
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with Stephan's suggestion is that Maven has a very definite idea of where source files are, where target files go, and so forth, You can override most of those locations in a POM, but it's very messy and definitely not what I'd suggest if you're not a Maven maven.

What I would probably do is create a prototype Maven POM (use an archetype if it helps), and soft-link the original project locations to standard Maven locations. For example, if your project has a "source" directory, create a softlink src/main/java to point to it. Try and build as much of the project as you can using Maven and tweak as necessary. Once the project builds reliable, go back and clean out the softlinks, using actual maven directories and deleting the obsolete paths.

Keep in mind that Maven projects each produce only one product, so if the original project creates multiple JARs, WARs, and so forth, that the project is going to require decomposing into sub-projects.

If you have custom utility programs that you ran in the original build scripts, you might have to build custom mojos to run them in your Maven builds. Or, if you can, replace them with standard maven goals.
 
Linwood Hayes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.  But can I just use eclipse build-in tools like "convert into maven project" ?  For example, if I have a j2ee type project (it may include a webApp project, java project), can I use such eclipse tool to convert ?  I know how to use it to convert a simple java project, but how to convert "projects" (like a j2ee app which contains one java and one web app project) into maven pjs ?  Maybe I should post this in eclipse forum ?
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[I've add this thread to the Eclipse forum.]

I've used the Convert to Maven Project tool in Eclipse long ago and I believe it makes a simple POM file and adds the Maven dependencies to the Eclipse classpath.  But I'm curious about what you want to do with Maven.  Not that it's a bad idea, just what prompted you to want to use Maven with this particular project?
 
Linwood Hayes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:[I've add this thread to the Eclipse forum.]

I've used the Convert to Maven Project tool in Eclipse long ago and I believe it makes a simple POM file and adds the Maven dependencies to the Eclipse classpath.  But I'm curious about what you want to do with Maven.  Not that it's a bad idea, just what prompted you to want to use Maven with this particular project?



Tired of using old stuff like Ant.
 
Knute Snortum
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotcha.  I would learn a little of Maven command line (CLI) as well as the Eclipse plugin.  Here's a good place to start.
 
Tim Holloway
Saloon Keeper
Posts: 22498
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, Ant and Maven are almost the same age. If it's just "new" you want, at least look at something like Gradle.

The primary advantages of Maven are that it standardizes project structure, ensures that all dependencies are made available, and that compatible versions are used for the dependencies and that you can build from anywhere in the world without having to set up a compatible infrastructure (other than Maven and the JDK).

The primary advantage of Ant is that you can have a single project producing possibly multiple products, the project organization is totally what you want it to be, and the build rules can be arbitrarily complex. And while Ant itself cannot resolve dependencies, Ivy can take care of that.
 
Maybe he went home and went to bed. And took this tiny ad with him:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic