john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

eclipse maven integration

WITH Eclipse Juno
    Help -> Eclipse Marketplace -> Find maven = "Maven Integration for Eclipse"

(NOTE: ubuntu 12.04 uses maven3 by default (also installs openjdk-6
sudo apt-get install maven


BEFORE Eclipse Juno = Help -> Install New Software -> Work With: All Available Sites -> maven

General Purpose Tools -> m2e - Maven Integration for Eclipse


New Project -> Other -> Maven Project , (modify the location as necessary) DO NOT USE THE "simple" checkbox

choose maven-archetype-quickstart (OR maven-archetype-webapp)

Artifact = GroupId = com.company.app  , ArtifactId = my-app
(packaging = jar unless building webapps and you need wars)


You probably will delete the examples App.java and AppTest.java

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
To install maven manually and have it available at the command line:

http://maven.apache.org/download.html

Windows: Computer -> Advanced System Settings -> Environment Variables
System Variables -> New -> variable=M2_HOME , value=c:\Users\John\Desktop\apache-maven-3.0.4

Modify: Path to append %M2_HOME%\bin

Verify with a new cmd.exe , mvn -version


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EXTERNAL DEPENDENCIES

Explicit dependencies can be brought in:

In the Project Explorer double click on the pom.xml (choose the pom.xml tab, NOT structure)

NOTE: Junit may already be included for you but not a great example...

...
  <groupId>com.oxygencloud.sdk</groupId>
  <artifactId>OxygenSpace</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>OxygenSpace</name>

...
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <dependencies>
    <dependency>
      <groupId>com.company</groupId>
      <artifactId>jarname</artifactId>
      <version>0.1</version>
    </dependency>
  </dependencies>
...

We remove scope to use the default of "compile"

http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

Saving the pom.xml will give you an error that the file is missing (but it will auto generate the whole path for you)

Browse in the new %userprofile%\.m2\repository path

Delete the  o2javasdk-0.0.241.pom.lastUpdated  and o2javasdk-0.0.241.pom.jar placeholders and ...

Add your external .jar to %userprofile%\.m2\repository\com\company\jarname\jarversion\jarname-jarversion.jar

Now refresh/save your pom.xml (I modified the scope to delete the test) and DEPENDENCIES IN SOURCE RESOLVED!

(NOTE: modify the pom.xml to change the version, if you screw up the names GroupID etc. you have to
manually clean up those %userprofile%/.m2 folders)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ALSO Maven can download dependencies it has access to (e.g. org.apache)

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html


FULL EXAMPLE pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.oxygencloud.sdk</groupId>
  <artifactId>OxygenSpace</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>OxygenSpace</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.oxygencloud.sdk</groupId>
      <artifactId>o2javasdk</artifactId>
      <version>0.0.241</version>
    </dependency>

  </dependencies>
</project>



EXAMPLE SOURCE .JAVA BEGINNING

package com.oxygencloud.sdk.OxygenSpace;

import com.oxygen.sdk.O2Agent;
import com.oxygen.sdk.O2Space;
import com.oxygen.sdk.exception.O2InvalidSessionException;
import com.oxygen.sdk.exception.O2NetworkException;
import com.oxygen.sdk.exception.O2UnexpectedException;

public class OxygenSpace{



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UNIT TESTS = Project Explorer package -> right click on sourcename.java = Junit Test
(ensure you modify the default path to use the Maven Standard Directory Structure src/test/java)

You can run Unit Tests with Control + F11 (if you have Android SDK make sure you choose the Eclipse Junit)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BUILDS

The goal of "clean" removes previous builds from the ${basedir}/target directory
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

BUILD by right clicking in Project Explorer package -> sourcename.java = Maven clean  (or control + F11)

With "Run" (Control + F11), to repeat choose "Maven build"

To modify the next action of the Control + F11 (i.e. move to the next phase of the build-lifecycle),

Choose "Maven build..."

(OR right click on the sourcename.java -> Run As -> Run Configurations -> Maven Build -> AppName

Usually go straight to goals: install  (this will include all previous lifecycle steps by default)


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project OxygenSpace: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre6\..\lib\tools.jar

http://wiki.eclipse.org/M2E_FAQ#Unable_to_locate_the_Javac_Compiler_Error


ENSURE YOU HAVE THE JDK INSTALLED (with the tools.jar file), if necessary delete the Run As profile,
Add a new one and choose the JRE (alternate) to come from a jdk1.7 JRE (added)

  • « Lubuntu torrent magnet link lxde chrome chromium with transmission
  • restore patch file script bash function »

Published

Sep 25, 2012

Category

java

~546 words

Tags

  • eclipse 22
  • integration 5
  • java 252
  • maven 10