Skip to content
philcal edited this page Mar 25, 2013 · 15 revisions

Installation

In Eclipse, go to the Eclipse MarketPlace and install the m2e-wtp feature.

One-time setup

mvn -Declipse.workspace=<eclipse workspace directory> eclipse:add-maven-repo

See http://stackoverflow.com/questions/4859825/how-to-add-maven-managed-dependencies-library-in-build-path-eclipse

Converting a Project

Commit all changes

IMPORTANT: Make sure all your changes are committed to git, or else they may be lost.

Move the source to Maven's directory naming conventions

  1. Right click on the project and select New -> Source Folder. Enter src/main/java as the Folder Name, and check Update Exclusion Filters in other source folders to solve nesting. Click OK.

  2. On the command line, go to your project and move your source to the new directory. You'll need to do this one file/directory at a time, because moving src/* will try to move the main directory into itself.

     $ git mv src/ttStd  src/main/java  
     $ git mv src/META-INF/ src/main/java  
    
  3. Git should recognise the source files as renamed, rather than deleted and created. Check the git status to check.

     $ git status  
     # On branch 8.1-dev  
     # Changes to be committed:  
     #   (use "git reset HEAD <file>..." to unstage)  
     #  
     #	renamed:    src/META-INF/MANIFEST.MF -> src/main/META-INF/MANIFEST.MF  
     #	renamed:    src/ttStd/basic/PublicSecurityPluggin.java -> src/main/ttStd/basic/PublicSecurityPluggin.java  
     #	renamed:    src/ttStd/basic/UserSecurityPluggin.java -> src/main/ttStd/basic/UserSecurityPluggin.java  
     #	renamed:    src/ttStd/company_maint/CompanyMaintUIM.java -> src/main/ttStd/company_maint/CompanyMaintUIM.java  
     #	renamed:    src/ttStd/contact_maintenance/ContactMaintenanceUIM.java -> src/main/ttStd/contact_maintenance/ContactMaintenanceUIM.java  
     ...
    
  4. If this looks right, commit it now.

     $ git add src  
     $ git commit -m "Moved source to Maven's standard directory structure"  
     [phil-1pmThursday ef0e7ad] Moved source to Maven's standard directory structure  
      103 files changed, 0 insertions(+), 0 deletions(-)  
      rename src/{ => main}/META-INF/MANIFEST.MF (100%)  
      rename src/{ => main}/META-INF/web-fragment.xml (100%)  
      rename src/{ => main}/tooltwist/guroopro/detectSectors/LapsAndSectors.java (100%)  
      ...  
    
  5. Back in Eclipse, right click on the project and select Properties -> Java Build Path -> Source. Click on <project name>/src and press Remove. Press OK when you're finished.

  6. Right click on the project again and select New -> Source Folder. Enter src/main/java for the Folder Name and press Finish.

  7. Right click on the project again and select New -> Source Folder. Enter src/test/java for the Folder Name and press Finish.

Add Maven nature to the project

  • Right click on project -> Configure -> Convert to Maven Project. If the "Create new POM" dialog is displayed, enter the customer's URL (e.g. com.tooltwist) for the group ID. Version will be based upon your project (e.g. 0.0.1-SNAPSHOT).

Updating Project Dependencies

  1. In the project properties, go to Java Build Path -> Projects. Take note of the referenced projects, and then remove any that are already available via Maven. This includes tooltwist, ttStd, ttWbd, XData, and any projects you've already converted. Press OK when you've finished.

  2. Remove any jar files in WebContent/WEB-INF/lib.

  3. Open pom.xml, and select the dependencies tab. Add each of the project dependencies you deleted to this screen. The Select Dependency dialog is easy to use if you use the auto-complete feature - press Control-Space to get a list of allowable values. For tooltwist, ttStd and ttWbd, the Group Id is com.tooltwist.

  4. From the top menu, select Project -> Clean..., select your project and press OK. Your project should now build cleanly.

Use Maven dependencies for 3rd party jars

  1. Back in the project's Properties -> Java Build Path -> Libraries tab, remove 3rdPartyJars. This will probably cause errors, and show undefined classes on the Eclipse Problems tab.

  2. Open pom.xml for your project an go to the Dependencies tab. For each undefined class, we'll need to add a Maven controlled jar to this list.

  3. Choose an undefined class from the Problems tab, press Command-Shift-T and enter the class name. This should show which jar file in 3rdPartyJars contains the class. Take note of the jar file's name, and the version if shown. If the class exists in multiple jar files, go to the source file where the class is undefined and look at the import statement, highlight the full package/class name, and press Command-Shift-T.

  4. On the dependencies tab press Add... and in the Enter groupid, artifactid or sha1 prefix or pattern field enter the name of the jar file. Search through the list for the jar file name. Expand the list below the jar file, select the correct version and press OK. Depending upon your project, you may wish to switch to a later version of jar files, be take note of any you change, and be sure to retest you application.

  5. Press Command-S to save pom.xml and the project will rebuild and update the Problems tab.

  6. Repeat these steps until all the missing classes are resolved.

Note that the dependencies of those jar files, and other projects are all calculated and displayed in the Dependency Hierarchy tab. If there are any version conflicts this tab will help.

Specific Dependency problems

log4j

Recent versions of Log4j reference dependencies not available in Maven Central. The solution is to insert the code below into your pom.xml. http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/

<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
  <scope>provided</scope>
  <exclusions>
    <exclusion>
      <groupId>javax.mail</groupId>
      <artifactId>mail</artifactId>
    </exclusion>
    <exclusion>
      <groupId>javax.jms</groupId>
      <artifactId>jms</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.sun.jdmk</groupId>
      <artifactId>jmxtools</artifactId>
    </exclusion>
    <exclusion>
      <groupId>com.sun.jmx</groupId>
      <artifactId>jmxri</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Oracle

Oracle's licensing prevents the jar files from being included in public repositories. See http://stackoverflow.com/questions/1074869/find-oracle-jdbc-driver-in-maven-repository

--

Clone this wiki locally