You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Michal Paluchowski <mp...@gmail.com> on 2007/10/31 10:43:18 UTC

Building Eclipse RCP/PDE Projects

Hi,

here's an issue I've been fighting for the last 5 business days with
every approach taken hitting the same wall. I checked the
documentation, did the googling, asked friends and didn't get any
further. I sincerely hope to get some help here.

I have a set of Eclipse plugin projects, which are to be moved to
Maven-managed building and packaging. Initially the future looked
bright as I found a perfectly suited article at eclipse.org:

  Building Eclipse Plugins with Maven 2
  http://www.eclipse.org/articles/article.php?file=Article-Eclipse-and-Maven2/index.html

Took a day or two to actually find out how to put the scraps of
information there together and install the custom MOJOs. Once I did
that, Eclipse project files were perfectly generated by 'mvn
eclipse:eclipse', all projects built in Eclipse but... not in Maven.
Even though Maven knew that the project depends on the org.eclipse.ui
package in the MANIFEST file (and complained if that package was not
in the repository), it still reported missing dependencies once the
packages were available to it in its repo.

Back at the drawing board, I found an existing MOJO for Maven:

  Eclipse PDE Maven Plugin
  http://mojo.codehaus.org/pde-maven-plugin/

and I also found out about the PDE option for the eclipse:eclipse goal:

  http://maven.apache.org/plugins/maven-eclipse-plugin/eclipse-mojo.html#pde

This brought me to the following situation:

/plugins/
    /eclipse-rcp-common/
        /src/
        /build.properties
        /META-INF/
        /...
        /pom.xml
    /vnc-client/
        /...
        /pom.xml
    /pom.xml

The "super pom" in the 'plugins' directory looks as follows:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.collaboratory.client</groupId>
  <artifactId>client-plugin-container</artifactId>
  <packaging>pom</packaging>
  <name>Collaboratory Client Container</name>
  <version>1.0-SNAPSHOT</version>
  <description>A Simple Plugin PDE Example</description>
  <build>
    <resources>
      <resource>
        <directory>${basedir}</directory>
        <includes>
          <include>plugin.xml</include>
          <include>plugin.properties</include>
        </includes>
        <targetPath>/</targetPath>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.4</version>
        <executions>
          <execution>
            <id>synchronise-eclipse</id>
            <phase>validate</phase>
            <goals>
              <goal>eclipse</goal>
            </goals>
            <inherited>true</inherited>
            <configuration>
              <pde>true</pde>
            </configuration>
          </execution>
        </executions>
        <configuration>
          <pde>true</pde>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>pde-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <buildProperties>
              <javacSource>1.6</javacSource>
              <javacTarget>1.6</javacTarget>
          </buildProperties>
          <eclipseInstall>/home/sonic/tmp/eclipse</eclipseInstall>
        </configuration>
        <executions>
          <execution>
            <id>clean-pde</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
      <dependency>
          <groupId>org.eclipse.ecf</groupId>
          <artifactId>core</artifactId>
          <version>0.8.8</version>
          <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.eclipse.ecf</groupId>
        <artifactId>discovery</artifactId>
        <version>0.8.8</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.eclipse.ecf</groupId>
        <artifactId>presence</artifactId>
        <version>0.8.8</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.eclipse.ecf</groupId>
        <artifactId>provider</artifactId>
        <version>0.8.8</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>org.eclipse.ecf</groupId>
        <artifactId>ui</artifactId>
        <version>0.8.8</version>
        <scope>compile</scope>
      </dependency>
      <dependency>
        <groupId>nl.collaboratory</groupId>
        <artifactId>admininterface</artifactId>
        <version>1.0.0</version>
        <scope>compile</scope>
      </dependency>
  </dependencies>
  <modules>
    <module>eclipse-rcp-common</module>
    <module>vnc-client</module>
  </modules>
</project>

While the pom for the eclipse-rcp-common plugin is:

<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/maven-v4_0_0.xsd">
  <parent>
    <artifactId>client-plugin-container</artifactId>
    <groupId>nl.collaboratory.client</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.collaboratory.client</groupId>
  <artifactId>eclipse-rcp-common</artifactId>
  <packaging>zip</packaging>
  <name>Common Elements Plugin</name>
  <version>1.0-SNAPSHOT</version>
  <description>A Simple Plugin PDE Example</description>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring</artifactId>
      <version>2.0.7</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.acegisecurity</groupId>
      <artifactId>acegi-security</artifactId>
      <version>1.0.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.3</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

Running "mvn eclipse:eclipse" in the eclipse-rcp-common directory
generates appropriate eclipse project files with all required
dependencies:

.classpath

...
  <classpathentry kind="lib" path="spring-context-1.2.9.jar"/>
  <classpathentry kind="lib" path="spring-remoting-1.2.9.jar"/>
  <classpathentry kind="lib" path="spring-core-1.2.9.jar"/>
...

.project

...
<link>
      <name>spring-remoting-1.2.9.jar</name>
      <type>1</type>
      <location>/home/sonic/.m2/repository/org/springframework/spring-remoting/1.2.9/spring-remoting-1.2.9.jar</location>
    </link>
...

(/home/sonic/.m2/repository/ is the folder with the Maven repository
and all libraries are there)

The MANIFEST.MF also contains all required dependencies:

...
Bundle-ClassPath: .,
 commons-codec-1.3.jar,
 commons-collections-3.1.jar,
 commons-lang-2.3.jar,
 commons-logging-1.0.4.jar,
 log4j-1.2.9.jar,
 admininterface-1.0.0.jar,
 acegi-security-1.0.5.jar,
 core-0.8.8.jar,
...

As a result, the project builds perfectly within Eclipse. Not so with
Maven. The PDE plugin for Maven works by generating a build.xml file
and running Ant against it. The appropriate path part of the build.xml
file reads:

....
    <pathelement
path="${build.result.folder}/../eclipse-rcp-common_1.0.0.SNAPSHOT/commons-logging-1.0.4.jar"/>
    <pathelement path="log4j-1.2.9.jar"/>
    <pathelement
path="${build.result.folder}/../eclipse-rcp-common_1.0.0.SNAPSHOT/log4j-1.2.9.jar"/>
    <pathelement path="admininterface-1.0.0.jar"/>
...

Which results in the following absolute paths (excerpt from Ant verbose):

dropping /home/sonic/tmp/test-plugin-development/plugins/eclipse-rcp-common/acegi-security-1.0.5.jar
from path as it doesn't exist
dropping /home/sonic/tmp/test-plugin-development/plugins/eclipse-rcp-common/target/pdeTemp/plugins/eclipse-rcp-common_1.0.0.SNAPSHOT/acegi-security-1.0.5.jar
from path as it doesn't exist
dropping /home/sonic/tmp/test-plugin-development/plugins/eclipse-rcp-common/core-0.8.8.jar
from path as it doesn't exist
dropping /home/sonic/tmp/test-plugin-development/plugins/eclipse-rcp-common/target/pdeTemp/plugins/eclipse-rcp-common_1.0.0.SNAPSHOT/core-0.8.8.jar
from path as it doesn't exist

The path:

  /home/sonic/tmp/test-plugin-development/plugins/...

is the correct path to the 'plugins' directory I mentioned in the
beginnig. All's well until this point. The 'target' folder is there as
well, but inside it there is NO pdeTemp folder, let alone any jars in
it. It seems that the ant script expects the jars to be copied locally
into the projects folder, while they're not!

The documentation for the "pde" option of the "eclipse:eclipse" goal reads:

  Additionally it copies all libraries to a project local directory
and references them instead of referencing the files in the local
Maven repository.

NO! There are no jars being copied to a "project local directory",
they're referenced from the repository as excerpts of eclipse related
files above show. Is that an "eclipse:eclipse" bug? Does anyone have a
working setup of Maven + Eclipse PDE and could share some expertise
with me?

-- 
 Michael Paluchowski [sonic|redmagic]
   paluchowski@post.pl
_________________________________ www.nethut.pl _ www.buggybrain.com _

 I do not fear computers. I fear the lack of them. / Isaac Asimov

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Building Eclipse RCP/PDE Projects

Posted by Graham Leggett <mi...@sharp.fm>.
On Wed, October 31, 2007 11:43 am, Michal Paluchowski wrote:

> I have a set of Eclipse plugin projects, which are to be moved to
> Maven-managed building and packaging. Initially the future looked
> bright as I found a perfectly suited article at eclipse.org:

The next issue you need to sort out is the directory structure.

Maven is designed so that each module can be checked out, and built
independently. The project checked out doesn't depend on anything in the
parent directory.

The Eclipse PDE build on the other hand, expects that the eclipse project
is in a directory called "plugins", and will place the build artifacts two
directories up. Oops.

This causes problems when you try and build stuff using continuous
integration. CI tries to check out your plugin, but the parent directories
are missing, and the build breaks.

The solution we found was to keep the directory structure exactly as
eclipse wants it, ie with the plugin directories and all the eclipse
projects grouped under that.

In maven-land, we create pom files for each eclipse plugin, but we also
create a root pom at the same level of the plugins directory with a
multi-module build, that lists each plugin project as submodules of the
root.

When it comes time to build this in continuous intergration, we check out
the root pom project only, and all of the subprojects get checked out in
the correct structure. Because the correct structure is in place, the
build works.

Regards,
Graham
--



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Building Eclipse RCP/PDE Projects

Posted by Graham Leggett <mi...@sharp.fm>.
On Wed, October 31, 2007 2:38 pm, Michal Paluchowski wrote:

> That was EXTREMELY helpful, thank you :) With that part done, there's
> just one more issue I might need help on and that's dependencies
> between plugins. Adding them to the MANIFEST.MF makes Eclipse compile
> projects but obviously Maven (or PDE) isn't able to read from those.

We haven't gone this far, we just had one plugin depending on jars.

One thing I do know is that maven-eclipse-plugin is under full control of
the dependencies listed in MANIFEST.MF. If maven doesn't know about it,
the dependency won't be included, even if you try and add it manually,
maven will simply remove manually added dependencies again.

That said, Eclipse plugins are effectively osgi bundles, which advertise
their dependency needs (in the form of package prefixes[1]) and expect the
container (Eclipse) to resolve the dependencies automatically.

In other words, as long as plugin A and plugin B are in the same Eclipse
directory structure (the plugins directory), and the dependency packages
are defined correctly in MANIFEST.MF, then Eclipse (and eclipse PDE, and
in turn pde-maven-plugin, and in turn maven) works this out automatically
for itself.

[1] This is one of the reasons why following the Eclipse naming
conventions is important.

Regards,
Graham
--



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Building Eclipse RCP/PDE Projects

Posted by Michal Paluchowski <mp...@gmail.com>.
On 10/31/07, Graham Leggett <mi...@sharp.fm> wrote:
> By way of background, things will make a lot more sense when you know
> exactly what the eclipse plugin does, and the pde plugin does, and the gap
> in between the two that complicates everything.

That was EXTREMELY helpful, thank you :) With that part done, there's
just one more issue I might need help on and that's dependencies
between plugins. Adding them to the MANIFEST.MF makes Eclipse compile
projects but obviously Maven (or PDE) isn't able to read from those.

How do I make one plugin depend on another then? The following setup
doesn't work:

<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/maven-v4_0_0.xsd">
  <parent>
    <artifactId>client-plugin-container</artifactId>
    <groupId>nl.test.client</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>nl.test.client</groupId>
  <artifactId>nl.test.overview</artifactId>
  <packaging>zip</packaging>
  <name>Collaboratory Overview Plugin</name>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>nl.collaboratory.client</groupId>
      <artifactId>nl.collaboratory.commonelements</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

With the super-POM I pasted before.


-- 
 Michael Paluchowski [sonic|redmagic]
   paluchowski@post.pl
_________________________________ www.nethut.pl _ www.buggybrain.com _

 I do not fear computers. I fear the lack of them. / Isaac Asimov

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Building Eclipse RCP/PDE Projects

Posted by Graham Leggett <mi...@sharp.fm>.
On Wed, October 31, 2007 11:43 am, Michal Paluchowski wrote:

> Took a day or two to actually find out how to put the scraps of
> information there together and install the custom MOJOs. Once I did
> that, Eclipse project files were perfectly generated by 'mvn
> eclipse:eclipse', all projects built in Eclipse but... not in Maven.
> Even though Maven knew that the project depends on the org.eclipse.ui
> package in the MANIFEST file (and complained if that package was not
> in the repository), it still reported missing dependencies once the
> packages were available to it in its repo.

I am having a sense of deja vu :)

By way of background, things will make a lot more sense when you know
exactly what the eclipse plugin does, and the pde plugin does, and the gap
in between the two that complicates everything.

First, the maven-eclipse-plugin:

The purpose of this plugin is to take information from maven-land, such as
your dependences and other config, and synchronise your eclipse
configuration with this information. Or in short, maven-eclipse-plugin
causes config data to flow from maven to eclipse, nothing more. The PDE
flag in the eclipse plugin causes more of the eclipse config to be
synchronised, particularly the META-INF/MANIFEST.MF data, but the
principle is the same.

Second, the pde-maven-plugin:

The purpose of this plugin is invoke the PDE build feature of Eclipse,
nothing more, and its PDE where the fun starts.

Eclipse has two different mechanisms for compiling code. The first is the
built in build process in the Eclipse frontend itself. The second is an
ant based system called PDE (plugin development environment) that is able
to build Eclipse projects from the command line.

Unfortunately it is not difficult to create a configuration in Eclipse
which will build successfully inside the Eclipse frontend, but not build
in the PDE environment, particularly when your eclipse plugin has
plain-old-jar-dependencies as dependencies.

The reason for this is that the Eclipse frontend supports the idea of
"linked resources", which work like symbolic links. When the
maven-eclipse-plugin creates the .project and .classpath files, it creates
these "linked resources" for you, pointing at the jars in the local maven
repository.

The problem is that this "linked resources" feature in the Eclipse
frontend isn't supported in the Eclipse PDE ant build. The PDE build takes
the "linked resources" literally, interpreting them as jars existing in
the root of your plugin project, and because they don't exist in the root
of your project, the PDE build fails.

Because the PDE build fails, the pde-maven-plugin fails, and in turn, your
maven build fails.

The workaround is to fool the Eclipse PDE build into working by physically
copying the dependencies you need into the root of your plugin project.
Obviously you don't want to do this manually, so you configure the
maven-dependency-plugin to do the copying for you in the "process-sources"
phase at the start of the maven build, and configure the
maven-clean-plugin to delete all of these copied jars when you run "mvn
clean".

The relevant bits of our pom look like this:

      <!-- tell the eclipse plugin this is a PDE project.

           This plugin is bound to the validate phase to
           ensure the Eclipse dependencies are always up to date.

           we inherit the version from the version specified in
           the root pom.
      -->
      <plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <executions>
          <execution>
            <id>synchronise-eclipse</id>
            <phase>validate</phase>
            <goals>
              <goal>eclipse</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <pde>true</pde>
        </configuration>
      </plugin>

      <!-- copy dependencies into the local build tree, as
           required by PDE.

           This step is a workaround for the fact that Eclipse PDE build
           script does not properly support the Eclipse linked resources
           feature.
      -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>process-sources</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <excludeScope>provided</excludeScope>
              <outputDirectory>${basedir}</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- clean plugin to delete jar files copied above -->
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <configuration>
          <filesets>
            <fileset>
              <directory>${basedir}</directory>
              <includes>
                <include>*.jar</include>
              </includes>
              <followSymlinks>false</followSymlinks>
             </fileset>
           </filesets>
         </configuration>
       </plugin>

      <!-- plugin to build this as an eclipse rcp package -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>pde-maven-plugin</artifactId>
<!--
Note: We use our own private copy of pde-maven-plugin until bug
http://jira.codehaus.org/browse/MOJO-862 has been fixed.
-->
        <version>1.0-alpha-2-private</version>
        <extensions>true</extensions>
        <configuration>
          <eclipseInstall>${env.ECLIPSE_HOME}</eclipseInstall>
          <pdeProductFilename>alchemy-eclipse.product</pdeProductFilename>
          <pdeBuildVersion>3.2.1.r321_v20060823</pdeBuildVersion>
          <pdeBuildConfigDirectory>/</pdeBuildConfigDirectory>
          <antVerbose>false</antVerbose>
          <antDebug>false</antDebug>
          <!-- javacFailOnError>true</javacFailOnError-->
        </configuration>
        <executions>
          <!-- Also bind to mvn clean -->
          <execution>
            <id>clean-pde</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

There are also issues with directory structure, but I'll cover these in a
separate mail.

Regards,
Graham
--



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Building Eclipse RCP/PDE Projects

Posted by Graham Leggett <mi...@sharp.fm>.
On Wed, October 31, 2007 11:43 am, Michal Paluchowski wrote:

> I have a set of Eclipse plugin projects, which are to be moved to
> Maven-managed building and packaging. Initially the future looked
> bright as I found a perfectly suited article at eclipse.org:

One last set of advice:

Stick to the Eclipse naming conventions.

Eclipse wants the name of the plugin to match the package name of the
contents of the plugin, eg "com.example.foo", and this must match the name
of the maven project.

It is tempting to give the eclipse plugin a name, like "foo-plugin", but
the "-" character is invalid as a package name, even though it is
perfectly valid as both a jar name and as a maven dependency name, and you
will start encountering problems when Eclipse starts complaining that the
application_id cannot be found, or that the plugin name contains an
invalid character, and various other weird Eclipse errors caused by
Eclipse assuming the name is well formed as per the Eclipse internal rules
(which are obviously bypassed when all the Eclipse config is written to by
maven).

Many many problems disappeared for us when we refactored our plugin code
to follow the naming conventions exactly.

Regards,
Graham
--



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org