问题
Recently I started to move from a .NET platform to J2EE. I'm Eclipse to build JSP and Servlet applications which should use Business Logic layer.
The approach in .NET is very simple I'm building web Application Project inside the solution, then Creating Class Library project and refers its output in Web Application References.
How should I do it in Eclipse? Should I create separate project and build JAR file as output and refer it in Web Project?
I'm new to Java so any comment will be more then welcomed.
Danny.
回答1:
Yes, creating a separate Java project would be the way to go. Just a simple Java Project suffices. To use it in the dynamic web project, you should not only add it as a project in the Build Path. You also need to refer it as Java EE module in the dynamic web project. Eclipse will then take care about buiding and placing the JAR the right way.
If you're on Eclipse 3.5 or older, then check the Java EE Module Dependencies section in the properties of the dynamic web project. You should add the Java project there.
If you're on Eclipse 3.6 or newer, then check the Deployment Assembly section which does essentially the same (it has just been renamed/grouped with other functions as per 3.6).
回答2:
It depends. IMO: Business Logic Layer means having all your business code separate from your presentation code. Normally this affects in terms of reuse.
It's not necessary to have all your business code in a separated project or jar. But in my short experience its interesting to do this if you are plannig to use this code in other applications than your web site (b.ex: webservices, desktop application or website designed for mobile acess).
I use Maven for building and resolving my project dependencies. But there are many others ways to acomplish this.
In Eclipse you could create two projects and deal with project dependency (Left click on your project -> Properties -> Java Build Path -> Projects tab).
Hope this will help you and sorry for my english.
来源:https://stackoverflow.com/questions/3511479/business-logic-layerin-servlet-and-jsp