Skip to content

Maven project with Eclipse

Sanghyuk Jung edited this page Sep 20, 2015 · 35 revisions

Step 1 : Check your Java version

Make sure JRE version 1.6 or later is installed and used in Eclipse and Maven.

  1. Check your java version on the command line.

     java -version
    
  2. Check the compiler version in 'pom.xml'. It is recommended to specify the version with 'source' and 'target' tags.

     <plugins>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>2.3.2</version>
             <configuration>
                 <source>1.6</source>
                 <target>1.6</target>
             </configuration>
     </plugin>
    
  3. Check settings on 'Project > Properties > Java compiler' in Eclipse

Step 2 : Add the dependency in Maven

  1. Add the repository of 'http://jcenter.bintray.com' in 'pom.xml'.

     <repositories>
     ....
     <repository>
     	<id>bintray</id>
     	<url>http://jcenter.bintray.com</url>
     	<snapshots>
     		<enabled>false</enabled>
     	</snapshots>
     </repository>
     </repositories>
    
  2. Add the dependency in 'pom.xml'.

     <dependency>
     	<groupId>org.adrianwalker</groupId>
     	<artifactId>multiline-string</artifactId>
     	<version>0.1.1</version>
     </dependency>
    

Step 3 : Check the version of your 'm2e(m2eclipse)' plugin

  1. Go to 'Help > Install New Software ' menu in Eclipse.

  2. Click 'already installed?' link.

  3. find 'm2e-Maven integration for Eclipse', or 'm2eclipse' on 'Installed Software' tab.

    • If you cannot find installed m2eclipse, go to Step 4 in this page.
    • If the version is 0.13 or greater, Step 5 in this page.
    • If the version is 0.12 or less, Step 6 in this page.

Step 4 : Install 'm2e' plugin

  1. Go to 'Help > Install New Software ' menu in Eclipse.
  2. Click 'Add' button and fill 'Name' and 'Location' field.

Step 5 : Install 'm2e-apt' plugin.

  1. Go to 'Help > Install New Software ' menu in Eclipse.
  2. Click 'Add' button and fill 'Name' and 'Location' field.
  3. Go to 'Project > Properties > Maven > Annotation Processing' menu
  4. Select 'Enable project specific settings'
  5. Select 'Automatically configure JDT APT'

Step 6 : Add the jar file to 'Factory Path' in Eclipse

You have two ways to add 'Factory Path' and select one of them. Both ways will create '.factorypath' file on your project folder.

Option 1 : By using 'apt:eclipse' goal of apt-maven-plugin.

  1. Add 'apt-maven-plugin' plugin in 'pom.xml'.

     <build>
         ....
         <plugins>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
             <artifactId>apt-maven-plugin</artifactId>
             <version>1.0-alpha-5</version>
             </plugin>
             ....
         </plugins>
     </buiod>
    
  2. Execute 'apt:eclipse' goal on the command line.

     mvn apt:eclipse
    
  3. Refresh(F5) your project in Eclipse.

Option 2 : By using Eclipse menu.

  1. Go to 'Project > Properties > Java compiler > Annotation Processing > Factroy Path' menu.

  2. Click 'Add Variable'.

  3. Select 'M2_REPO' and click 'Extend' button.

  4. Select 'multiline-string-....jar' from 'org/adrianwalker/multiline/multiline-string/...' folder.

Step 7 : Check options for annotation processing in Eclipse.

  1. Go to 'Project > Properties > Java compiler > Annotation Processing ' menu.
  2. Select 'Enable project specific settings'
  3. Select 'Enable annotation processing'.

Step 8 : Test

Create a class for test and run it. The following example shows how to use the @Multiline annotation.

import org.adrianwalker.multilinestring.Multiline;

public class Hello {

    /**
     Hello!
     Multiline-string!!
    */
    @Multiline private static String msg;

    public static void main(String[] args) {
        System.out.println(msg);
    }
}

It will write the following message to the console.

Hello!
Multiline-string!!