How to find Spring XML definition from Java Class in Eclipse - java

I work on a large Spring/Struts project in Eclipse. One thing I have to do frequently is dig through the spring.xml file so that I can update the definition for the class that I am working on. It seems like there should be an easy 2 or 3 click way to go from the Java class I am in to the Spring definition.
I have SpringSource installed, but this doesn't seem to offer anything that's actually useful to me. Does anyone know if this is possible in Eclipse and how to do it?
Bonus Question: is it possible to jump from a Struts Action class to it's corresponding struts.xml definition in Eclipse?

in your eclipse project, just add the spring nature. Right click the project and select the Spring Tools option -> Add Spring Nature. This will ensure eclipse keeps your java classes and spring context in synch.

Related

Why are URLs not resoliving in jsp view of intellij with struts 2 convention

I have two "errors" with url references that appear when using struts forms in a new project I'm templating out in IntelliJ Idea. It's the strangest thing because neither of them are actual errors. The program builds and deploys as I expect
The first one is this. Now I'm sure that I could extract a copy of the "Struts-Tags" and put it somewhere but why am I getting this <statement> or delimiter error.
The second one is of the same line, it has to do with the zero config project I'm trying to build with convention I think. This one fails to recognize that I'm mapping to an action via the convention plugin without a config.
I'm just getting started on a project that I plan to use as a template for a larger project and I like to keep my projects clean of any errors. If I'm breaking best practices and that's the issue I'd love to hear about it but I was rather fond of building my template framework this way so I'd be disappointed if I was I guess. I'm new to the convention plugin but it seemed like a pretty clean way to set up a business application, more so than my last xml configured struts2 app on 2.3.
Anyway here are some additional references in case there is an issue elsewhere that I am overlooking.
Struts 2 plugin enabled (have tried all 8 combinations of the 3 struts intellij plugins)
Empty struts.xml file
web.xml file (some spring stuff cut off but the removal of all spring dependencies and configs did not affect intellij showing me these errors)
Maven struts dependencies
Action class... don't mind Data, it just generates my getters and setters, again #Component definitely isn't the issue as I have already tried removing all my spring stuff
Package Layout
If it helps you can download the project:
https://github.com/DrakeFramework/DrakeNelson
I was hoping to get my jpa and 3 deployments configured but I just can't stand committing a project and saying "OK" to errors, that's how it grows out of control and before you know it the 10,000 warnings are all just ignored.
The first problem is not reproducible in your sample project:
It could be that you've injected something like SQL into the parameter using Alt+Enter | Inject language or reference context menu. You can repeat this step, but use the Un-inject option.
The second problem is also not reproducible for some reason:

Referencing JPA project in a JSF project

I want to create a JSF project with JPA. I am using eclipse juno 4.2 How can I integrate both in one project?
I read somewhere that keeping JSF and JPA project separately is a good practice, but I don't know how to do this. If I am using two different projects that is for JSF one project and JPA another how do I integrate and make it working depending on each other?
In the properties of the JSF project, add the JPA project as Deployment Assembly. This way the JPA project will end up as JAR in /WEB-INF/lib of the JSF project, which is exactly what you need after all.
Further you should make sure that you haven't fiddled/messed around in Build Path property in an careless attempt to solve this. If you changed anything there, make absolutely sure that you undo it.

How to organize projects?

I've been working with Visual Studio for a long long time, but now I'm been requested to work on a Java web project. We've decide to use Spring MVC as framework, and we want to use Log4J (for logging obviously =P) and JUnit for unit testing. Now, in the "Microsoft way" I will create a Solution, and I'll add A web project and a Unit testing project; now that I'm usign Netbeans, is it possible to do like that? Or how should I organize my projects?
Thanks for sharing your experience!
Have you thought about using Maven as a way to manage your project? I've heard really good things about it.
You can find a list of what Maven is, exactly, here.
In short, it has the following goals (I took these from the web site):
Making the build process easy
Providing a uniform build system
Providing quality project information
Providing guidelines for best practices development
Allowing transparent migration to new features
Try to use maven, and there is a standard way for a project :)
In Netbeans you specify what type of project you want to create, say Java Web Application. Netbeans will then create the files and folders to support that project. Within the project view explorer, you can see the 'Test Packages' node, this is where you add java classes to support your unit testing. When you add a unit test, Netbeans will add a reference to the correct JUnit library to your project (you can see this on project properties > libraries > compile test).
For Spring MVC, the same goes. You add a dependency in Netbeans, either at project creation time, or from the properties dialog afterwards.
This is just tip of the iceberg. So I hope this information allows you to at least get started and you can return with more specific questions as you get further in.

Best Eclipse Plugins for java development making use of spring/ struts /hibernate?

I am looking for plugins which make developer's life easy while using technologies like Struts/ Spring/ Hibernate. For instance, here is a requirement:
If I were to change an Struts Action, I should be able to list out all the Struts Actions for my webapp, right click and add a method/ do some changes.
So, basically, I need to know what plugins will make eclipse more 'technology/framework friendly'.
Appreciate your help!
I've heard good things about Spring IDE. It has support for the Spring basics plus a few associated libraries, and is available as an Eclipse plugin download from http://springide.org/updatesite/. Once installed, you apply a Spring nature to the project in order to use it.
Hibernate also has Hibernate Tools available, but I've never checked that out to see how it works. From the description, it apparently offers some functions to make creating and editing mapping files easier.
As far as I can tell, Struts doesn't have anything up-to-date as far as IDE plugins go. MyEclipse may have something like that.
Side note: for some reason, I've never stuck with the plugins for these libraries. I gave the Spring one a try once, but eventually got used to editing the Spring configs manually and haven't touched it in a while. I don't know how much of a benefit they would be for increasing config file creation... although they probably would help in visualizing dependencies in a big set of Spring configs.
Spring tools suite is great for this. You might also look into Fast Code Eclipse Plugin
If you don't mind paying the price ($31.75 for standard, $63.55 for pro), you could check out MyEclipse. This is a nice and powerful "extension" of Eclipse that has many nice features, including Spring Tools, Struts (and Struts 2), Hibernate and many more.

Using Hibernate with Dynamic Eclipse Plug-ins

I have classes that are named exactly the same across different plug-ins that I use for my application, and I'd like to be able to configure them properly with Hibernate. The problem is that it looks like Hibernate dynamically generates a class' package name when trying to find a class when it's doing its mapping. With one plug-in this scheme works, but across multiple plug-ins it's not working. It looks like Hibernate gets confused when dealing with Hibernate configuration files across multiple plug-ins.
Is this because each plug-in has its own class-loader? What is the best way to proceed to make this work with the existing plug-ins and Hibernate?
The problem is, that every plugin has its own Classloader and Hibernate uses Reflection to find the right classes.
I have a very nice article at home about exactly this problem, but this one is in German. I will try to explain what you need to do.
In order to have the datastructure shared over several plugins, you have to put it in a plugin and enable a feature called buddy-policy.
Lets say you have a main-application-plugin which is initiating hibernate on startup, this plugin needs to "see" the classes from the datastructure-plugin. To do this the main-plugin sets its Buddy-Policy to "registered" and the datastructure-plugin registers itself as a "buddy". Unfortunately you have to do this all directly in the manifest file, at least in 3.3 there was no way to do this in the editor.
Once this buddy-policy works, Hibernate will also.
I looked up my old application and here is how I did it.
The main-application (toolseye.rcp) is dependent on the hibernate plugin (de.eye4eye.hibernate) and the datastructure-plugin (toolseye.datastructures)
The hibernate-plugin specifies its buddy-policy as "registered"
The datastructure-plugin registers itself to the hibernate-plugin
Here are the important lines:
Hibernate-plugin de.eye4eye.hibernate
Eclipse-BuddyPolicy: registered
Datastructure-plugin toolseye.datastructures
Eclipse-RegisterBuddy: de.eye4eye.hibernate
Put those line directly in the MANIFEST.MF
Both plugins need to reexport their packages in order that the main application or whatever layer you have in between can use them.
Hope that helped.
Just to make this complete.
Instead of using Hibernate, EclipseLink could be used as JPA-provider in a Eclipse RCP application. EclipseLink is the former TopLink from Oracle and has been choosen to be the reference implementation for JPA 2.
The point for an RCP is, that EclipseLink is available as OSGI-Bundles (org.eclipse.persistence.jpa), and due to that it can load classes from another plugin without an additional buddy-policy.
Currently I was playing around, using the following project structure (Model-View-Presenter Pattern). The names in the brackets specify the dependecy plugins (not all are included, only the ones related to this question)
rcp.mvp.view (rcp.mvp.presenter /
rcp.mvp.model)
rcp.mvp.presenter (rcp.mvp.data -
data reexports the model, so this is
not needed here) *
rcp.mvp.data (rcp.mvp.data.mysql /
rcp.mvp.model / javax.persistence /
org.eclipse.persistence.jpa)
rcp.mvp.data.mysql - provides only
the mysql-jdbc-driver. has to be
inside the classpath
rcp.mvp.model
In this scenario, the JPA provider in the data-plugin is able to load the classes from the model-plugin without a buddy-policy.
*Note, the presenter is not dependent on any JPA packages since this is encapsulated by DAOs (the main reason why to use them still)
Links
User Guide
RCP example (unfortunately not using DAOs)
EclipseLink conceptual Webinar from live.eclipse.org

Categories