Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to use Spring-Beans in Eclipse-PDE-Projects
How to use Spring-Beans in Eclipse-PDE-Projects [message #266341] Sun, 16 November 2008 16:05 Go to next message
Eclipse UserFriend
Originally posted by: iossif.gmx.de

Hi,

I'm new to Spring and the dependency management in Eclipse-PDE-Projects
and I get in trouble by integrating Spring into a PDE-Project.

That's my situation: we have a pde-project, where we want to use spring.
So far we used maven to resolve jar-dependencies in our java-projects
and we generated the appropriate eclipse-projects and classpath-files by
running mvn eclipse:eclipse. To get a real pde-project as well I
configured the maven-eclipse-plugin by adding the pde-configuration to
our pom.
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<pde>true</pde>
</configuration>
</plugin>

Because we have to use some spring features in our pde project I also
added the following dependency to the pom:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.5</version>
</dependency>

We used that dependency in classic eclipse-java-projects as well, and it
works very fine, because it correctly creates the classpath-entries for
the eclipse-ide.

Now if I call mvn eclipse:eclipse on the pde-project, the
spring-classpath-entries in .classpath and the resourcelinks in .project
are missing. I also tried to set the copy-dependencies-execution to the
pom, described under
http://maven.apache.org/plugins/maven-eclipse-plugin/pde.htm l,
but the spring-dependency is missing as well. I only get a dependency to
commons-logging-1.1.1.jar, linked into .project, .class and manifest.mf.
I suppose, maybe that's it related to the optional-tag I found in
spring-2.5.5.pom. (??)

By investigating the web, I found some further suggestions, that refer
to some articles around spring dm and some explanations that try to
integrate spring by eclipse-spring-plugins; e.g.
http://swissdev.blogspot.com/2008/06/eclipse-rcp-application -using-spring-dm.html.

So I downloaded the spring-osgi-1.1.2-with-dependencies.zip, imported
the included osgi-jars, setup the plugin-dependencies.

So I wrote my application.xml with the bean-definitions for the
beans I want to use in the rcp application. It contains this
definitions:

<bean id="smsDao" class="[package_to_class].SmsDaoDummyImpl">
</bean>

<bean id="smsRepository" class="[package_to_class].SmsRepositoryImpl">
<property name="dao">
<ref bean="smsDao" />
</property>
</bean>

<bean id="smsService" class="[package_to_class].SmsServiceImpl">
<property name="smsRepository">
<ref bean="smsRepository" />
</property>
</bean>

<bean id="smsDomainAdapter" class="[package_to_class].SmsDomainAdapter">
<property name="smsService">
<ref bean="smsService" />
</property>
</bean>

The classes SmsDaoDummyImpl and SmsRepositoryImpl are packaged in
persistence.jar and smsService in service.jar. SmsDomainAdapter is a
class of the pde-project.

Now I want to use the smsDomainAdapter-Bean to provide a ResultList
to a TableView, so I wrote the following code:

public class SmsTableView extends ViewPart {
[...]

public SmsTableView() {
super();
ApplicationContext context = new ClassPathXmlApplicationContext(this
.getClass().getClassLoader().getResource(
"/client/spring/applicationContext.xml").toString());
this.smsDomainAdapter = (SmsDomainAdapter) context
.getBean("smsDomainAdapter");
}

[...]
}

If I start the application, I got a ClassNotFoundException on
SmsDaoDummyImpl, although the manifest.mf contains:
Bundle-ClassPath: .,
commons-logging-1.1.1.jar,
persistence.jar,
service.jar,
[...]

Moreover it contains this settings:
Import-Package: org.springframework.beans.factory;version="2.5.5",
org.springframework.context;version="2.5.5",
org.springframework.context.support;version="2.5.5",
org.springframework.core.io;version="2.5.5"

What's wrong there?

I'm very confused and frustrated, how to resolve the dependencies to
spring, persistence.jar and service.jar in the correct way.

So my first question is:
What is the right way to resolve the dependency? By maven setting the
spring-2.5.5.jar to the .classpath-file or by setting the
eclipse-plugin-dependency in manifest.mf?

Further questions:
- If I use the .classpath-way: How do I fully include the
spring-2.5.5.jar correctly into the pde project, so that calling mvn
eclipse:eclipse includes the complete spring-2.5.5.jar?
- If I use the manifest.mf-way: How do I setup the plugin-dependencies
correctly?

Last question:
How do I resolve the ClassNotFoundException?

Thanks for your help
Re: How to use Spring-Beans in Eclipse-PDE-Projects [message #635586 is a reply to message #266341] Wed, 27 October 2010 12:48 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 1
Registered: October 2010
Junior Member
Hi
I have exaclty the same problem... did you solve your problem?
if yes how?
Re: How to use Spring-Beans in Eclipse-PDE-Projects [message #639921 is a reply to message #635586] Thu, 18 November 2010 12:25 Go to previous message
Missing name Mising name is currently offline Missing name Mising nameFriend
Messages: 5
Registered: September 2009
Junior Member
Hi,

I solved the problem by changing the development process after considering that the eclipse dependency mechanism differs from the maven dependency mechanism.

First I switched to Spring-DM by using the prepared OSGi-bundles of Spring-DM. Its very easy to integrate them into any eclipse-bundle and avoids many problems around class-loading and the spring container. But I run into the problem of building and packaging the eclipse-project. For the first time I used the annoying eclipse export. But after a while of investigation on maven plugins like maven-pde, I found a very interesting solution, called maven tycho.

Take a look on
http://mattiasholmqvist.se/2010/02/building-with-tycho-part- 1-osgi-bundles/

There you will find an excellent comprehensive overview on how to build and package eclipse bundles.
Previous Topic:Contract Opportunity
Next Topic:setting/changing color scheme
Goto Forum:
  


Current Time: Wed Sep 25 21:58:09 GMT 2024

Powered by FUDForum. Page generated in 0.11269 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top