How to use Spring-Beans in Eclipse-PDE-Projects [message #266341] |
Sun, 16 November 2008 16:05 |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.11269 seconds