Is it possible to use Spring within Eclipse plugins? - eclipse

Is it possible to use a Spring container for DI from inside Eclipse plugins?
I'm wondering because I know that Eclipse causes a lot of issues with class loading, looking up things within the plugin, etc.
The plugin is intended to be distributed as a JAR.

Yes but you will need Spring DM http://www.springsource.org/osgi

The answer is yes. You can use Spring DM, but you don't have to. It is probably better with it.
I did it without Spring DM and the main concern is class loading issues (not sure if Spring DM solves them, but I guess it should). Assuming you bundle the Spring JAR in a separate plugin with dependencies, you will need to load the context with the class loader of the invoking plugin .
Example:
Plugin A - your functional plugin
Plugin B - The Spring lib plugin exporting the spring packages
Plugin A depends on B. When plugin A starts, it will load the application context, when invoking this load, you will need to do something like:
Thread.currentThread().setContextClassLoader(PluginAActivator.class.getClassLoader())
So that the loading of the classes will happen under your own class loader. Now you can use a ClassPathXmlApplicationContext to load configuration XMLs from your class path.
One small note: the default ClassPathXmlApplicationContext validates your XMLs upon loading. You may want to disable it or point your XMLs to a local schema (rather than the standard Spring schema on springframework.org), otherwise, you will connect to the internet to download the schema files upon loading and working offline will fail.

do you have a code example for your post?
This would be great, since I´m hanging around with this for a while.
Cheers!

Related

Is there any way of configuring Oracle ATG to load java class changes dynamically?

I am interested in setting up a development environment for ATG in which changes on class will take effect immediately after the build is done, without restarting server and building again the ear file.
I have searched in the product documentation but the only thing I saw you can configure to load dynamically would be the configuration files section.
Is there any other way of configuring the environment for better productivity?
Use JRebel. That will do dynamic re-loading for java classes, property files and other deployable assets. Great for productivity.
If your purpose is to debug and most of time is getting wasted packing and unpacking the ear, you can always use remote debugging with JBoss and Eclipse, but for major changes like adding a method wont be working in that case. One solution to this is use Java DCEVM which will dynamically update code in the JVM. Its a simple jdk just point your Java_home to this jdk and in debug mode you can add code to you class see changes. Use the below link for more information about DCEVM
https://github.com/dcevm/dcevm

How to get eclipse content assist working in XML files

I have started creating the Spring web application where I need to mention the spring classes in the XML configuration files, for ex, the deployment descriptor (web.xml) where I need to mention the DispatcherServlet class of Spring.
What I am looking for is, I want eclipse to show me the list of packages/classes when I type org.springframework..., like we do in the Java editor. I have googled to find out, but no luck. I am sure there would be plugins available. Can any of you please share me on how to fix this?
Since you are working on a spring project, I'd recommend installing the SpringToolSuite (STS). The info page is here: http://spring.io/tools
Since you already have an Eclipse instance that you are working with, you should go with the update sites: http://dist.springsource.com/release/TOOLS/update/e4.4/
(Make sure to use the correct update site for the Eclipse version you are using.)
Not only does STS include all tools for XML editing, but it also includes special tools for editing your Spring application files.

Beginning jbpm 6 questions about expectations of integration

I have been researching the jbpm / drools engine and have been working on a proof of concept using jbpm 6 and the kie workbench. I am currently working on a proof of concept for page navigation, the process should receive a variable representing an action the user took on the page the engine uses the variable in the process to decide which page will be displayed to the user next and returns that value.
I have created this navigation example in drools and jbpm that has the "user action" variable mapped as a parameter before starting the process. Both a drools and jbpm application are created through eclipse where the process operated off a JbpmJUnitBaseTestCase class with console printouts that show me both processes are working as I expect.
Now I am working with the Kie Workbench in an effort to construct the same projects but produce a jar file that can be consumed by a stand alone application. Currently I am having trouble finding information for some questions and I not sure if my expectations are exceeding what Kie Workbench was designed to do.
Overall I would like to have a resulting jar file deployed from Kie Workbench that can be used in a stand alone application. It will use a data object from the data modeler that can be assigned values from the stand alone application. I will then run the Business process from the stand alone application to get the return a result to work with and load the corresponding page.
I have accessed the data object included in the deployed jar, can that jar also contain a KB and Session I can attach the data object to and run the process? I would eventually like to see a jar file I can include in a web page where I can instantiate the data object class, assign values and then attach and run a session without adding any additional libraries to the stand alone application.
Thanks you in advance.
If you managed to create your project(s) with all the assets and data models, you can build and deploy the project and that will generate a maven artefact (jar) which will be installed in a local maven repo. You can consume that jar inside your stand alone application. if you are using maven in your standalone application, you just need to add the dependency to your project and the kie-wb repository and it should work.

Eclipse plugin for spring

IDEA allow to find bean definition, declared in xml, right from Java code. For example if I've got interface SomeIntrfaceImpl IDEA allow me to find out instances of SomeIntrfaceImpl in .xml contextes files, pointing me to .xml file to line of code where bean is created
Is there any Eclipse plugin, that allow me to do the same ?
Yes there is different Eclipse provided by SpringFramework makers itself. They have extended the eclipse to provide easy development for Spring web application and other products like Spring ROO also.
Its is called SpringSourceToolSuit. You can download its latest version from here after providing some basic information about you asked in a form there.
Its the best IDE to develop Spring applications. I am currently using it.
Hope this helps you. Cheers.

How to use 3rd party libraries in glassfish?

I need to connect to a MongoDB instance from my EJB3 application, running on glassfish 3.0.1. The Mongo project provides a set of drivers, and I'm able to use them in a standalone Java application.
How would I use them in a Java EE application? Or maybe better phrasing: how would I make a 3rd party library available to my application when it runs in an EJB container?
At the moment, I'm getting a java.lang.NoClassDefFoundError when deploying a bean that
tries to import from the library:
[#|2010-03-24T11:42:15.164+0100|SEVERE|glassfishv3.0|global|_ThreadID=28;_ThreadName=Thread-1;|Class [ com/mongodb/DBObject ] not found. Error while loading [ class mvs.core.LocationCacheService ]|#]
[#|2010-03-24T11:42:15.164+0100|WARNING|glassfishv3.0|javax.enterprise.system.tools.deployment.org.glassfish.deployment.common|_ThreadID=28;_ThreadName=Thread-1;|Error in annotation processing: java.lang.NoClassDefFoundError: com/mongodb/DBObject|#]
[#|2010-03-24T11:42:15.259+0100|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=28;_ThreadName=Thread-1;|Exception while loading the app
org.glassfish.deployment.common.DeploymentException: java.lang.NoClassDefFoundError: com/mongodb/DBObject
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:171)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)
I tried adding it to the NetBeans project (Properties -> Libraries -> Compile -> Add Jar, enable 'Package'), and I also tried manually copying the jar file to $GF_HOME/glassfish/domains/domain1/lib (where the mysql-connector already resides).
Do I need to 'register' the library with the container? Reference it via Annotation? Extend the classpath of the container to include the library?
Hmm... Shouldn't you put this "driver" in glassfishv3/glassfish/domains/domain1/lib/ext?
You could put shared libs to lib/ext of your domain. commons-logging and jdbc drivers are often added in this domain path.
Common Class Loader
GlassFish v2 has a well defined Class
Loader hierarchy which identifies the
common class loader as the proper way
to deal with shared libraries. So to
make a long story short, putting you
libraries and other framework JARs in
domains/domain1/lib is all you need to
do.
lib/, not lib/ext
The person asking me the question had
tried putting the libraries in
domains/domain1/lib/ext which
triggered an interesting
ClassNotFoundError for core Java EE
classes such as
javax.servlet.http.HttpServlet. Shing
Wai Chan was quick to explain that
domains/domain1/lib/ext is part of
-Djava.ext.dirs which makes any of its JARs be considered as a JDK extension
which means web app frameworks placed
there will be loaded before
webcontainer implementation classes as
they are higher up in the classloader
delegation chain.
Glassfish has own Class loader hierarchy, http://docs.oracle.com/cd/E19798-01/821-1752/beade/index.html
I face the same problem in my project and then I put all my Third party libraries in domain/domain1/lib and my problem solved. On other way round, my problem was solved too by putting libraries in glassfish/lib.
In my case I was using Oracle Express Edition 11gR2 and Glassfish 3.1.2 and the ONLY way that works in my case was putting the ojdbc6 in:
C:\Program Files\glassfish-3.1.2.2\glassfish\lib
Go to your Glassfish doamin directory.
Then go to lib folder.
Place the libraries there.
Restart the glassfish and run.
(Ex) C:\glassfish3\glassfish\domains\domain1\lib
Try to put Your libs into $GF_HOME/glassfish/modules/.
It's dirty, but will work.