0
votes

I have a problem when creating even simple Eclipse plugin with Spring support.

My main goal is to develop multi-module Eclipse plugin project using Apache Camel framework. That's why I'm trying to use Spring as IoC container(Camel has good Spring DSL) and Apache Maven as a build tool.

Now I have very simplified sub-goal: create simple Maven project for Eclipse plugin (like HelloWorld), which can create Spring's ApplicationContext by bundle-context.xml file, get some simple dependency from there, and, for instance, print it to console.

I started with spring-osgi-bundle-archetype archetype. I'm trying to use maven-bundle-plugin but without success. Currently, I have following configuration in pom.xml:

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.4</version>
            <extensions>true</extensions>
            <configuration>
                <manifestLocation>META-INF</manifestLocation>
                <ignoreMissingArtifacts>true</ignoreMissingArtifacts>
                <instructions>
                    <Bundle-SymbolicName>${bundle.symbolicName}; singleton:=true</Bundle-SymbolicName>
                    <Bundle-Version>${pom.version}</Bundle-Version>
                    <!-- | assume public classes are in the top package, and private classes 
                        are under ".internal" -->

                    <Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${pom.version}"</Export-Package>
                    <Private-Package>${bundle.namespace}.internal.*</Private-Package>

                    <Import-Package>.,*;resolution:=optional</Import-Package>
                    <Bundle-Activator>${bundle.namespace}.Activator</Bundle-Activator>
                    <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                    <Require-Bundle>org.eclipse.ui,org.eclipse.core.runtime</Require-Bundle>
                    <Bundle-RequiredExecutionEnvironment>JavaSE-1.6</Bundle-RequiredExecutionEnvironment>
                    <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
                    <Embed-Directory>target/dependency</Embed-Directory>
                    <Embed-StripGroup>true</Embed-StripGroup>
                    <Embed-Transitive>true</Embed-Transitive>
                </instructions>
            </configuration>
        </plugin>

This configuration couse MANIFEST.MF generation with a lot of imported packages, all dependencies from pom.xml are embedded into target/dependency and declared in MANIFEST's Bundle-Classpath.

But plugin still doesn't work: there are errors like

NoClassDefFound: org.springframework.context.ApplicationContext

or

No available bundle exports package 'org.springframework.context' (If I try to add this package to Import-Package forcingly).

But archive with this dependency (spring-context-3.0.5-RELEASE.jar) exists in target/dependency and in Bundle-Classpath.

I'm not very experienced in OSGi technology, so I even cannot understand whether this is a issue with Maven or with OSGi.

Does anyone has experience on creation Eclipse plugins with Spring support? Any advice and comments are welcome. Also it would be great to see some OpenSource Eclipse plugin with Spring support.

2
Sorry, this was my fault. I have used Eclipse PDE to test the plugin and it didn't use bundle packaged by maven.ENargit
Besides, it was bad idea to embed Spring modules to meet my main goal - Apache Camel support. That framework doesn't work in OSGi environment with regular Spring libraries. According to docs, Spring Dynamic Modules or Eclipse Gemini Blueprint shold be used instead.ENargit

2 Answers

1
votes

I would suggest you go with a manifest first build for your eclipse project, so you can use all the tools from eclipse for plugin stuff, see tycho and at the end of the page the examples.

EDIT: The links on the tycho page are broken, get the examples via github insteat, its the demo folder

1
votes

Workaround was to add in pom.xml following code:

        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

and call mvn package before Run/Debug plugin in Eclipse PDE.