在Eclipse 中用WST部署Web项目时关于项目引用的问题

  一直在用.NET做项目,最近一个项目要用ZK+Spring+Hiberate来完成,于是开始了与Java的第一次亲密接触。因为是第一次,所以在一路的过程中遇到了不少的问题。打算借JavaEye的宝地,在我的Blog中记录下来,供自己以后总结。
 今天主要遇到的问题是:我的项目分为前端(A)和后端(B)两个工程,前端工程主要是用ZK实现用户界面,spring secrutiy实现安全机制等。后端主要是用Spring与Hibernate实现主要的业务逻辑和数据的处理。项目开始的前一阶段一直用MyEclipse处理,后来因为种种原因换回了Eclipse,以前直接用MyEclipse自带的Deployment工具将项目部署到Tomcat中,而在Eclipse中我则用WST结合Tomcat进行部署与调试。一开始在B工程中引用工程(Project Reference).编译期间无任何错误。A工程中可以顺利的调用B工程所有的类。但是我用Tomcat调试A工程的时候,在运行时A工程中无法使用B中的类。一直抛出Class Not Find异常。问题应该是出在在运行时,B工程中的类并没有被包括到A的WEB-INF下面去。具体的解决方案是在找到Java EE Module Dependencies,在这个地方把B工程包含进去。

在国外的一个论坛看到一个哥们和我遇到的问题一样。

以下英文原文是搜索到的答案:

J2EE/JEE module dependencies would solve this problem. You have already done the task of extracting your common classes into its own project, possibly because other projects depend on these classes. Either way, you'll have to ensure that this is a Utility project (appears under J2EE/JEE in the project wizards), and not just a plain Java project. One that is done, you can proceed to add the Utility project to your build path (compile-time path) as you have figured out.

The additional (final) step is to establish a J2EE/JEE module dependency between your Dynamic Web project and the shared library, which causes the utility's classes to be placed in WEB-INF\lib during deployment, and even during export of the WAR. To do so, visit the dynamic web project's properties, and browse to the J2EE/JEE module dependencies. Ensure that your utility project is selected here. Redeploy/publish your application and you should be good to go.

------------
接下来的讨论
That seems to have done the trick, but I'm not sure about what you were saying about it being a "Utility" project. Is there something I can see in my .project file or in .settings/ that would let me know it was the right type? – Brian Deacon Nov 28 '08 at 22:12 
Utility projects are Java projects, though they are more apt for the J2EE context. They represent your code (not third party JARs) that are shared across multiple projects in your Enterprise App. Usually these are classes used across multiple EJBs and often a single Web module. – Vineet Reynolds Nov 28 '08 at 22:25 
I normally do not place Utility projects in plain vanilla Java projects, because Utility projects will have the Server's runtime JARs automatically added to the classpath. For instance I could utilize datasources from the same project without adding the container's JARs to the build path. – Vineet Reynolds Nov 28 '08 at 22:28 
And to answer your question about checking the type of the project, you can check the natures of your project in the .project file. For instance, plain Java projects have the org.eclipse.jdt.core.javanature as the only nature in my Ganymede workspace. – Vineet Reynolds Nov 28 '08 at 23:05 
Very helpful. Thank you! – Brian Deacon Dec 3 '08 at 23:40 

你可能感兴趣的:(eclipse,spring,tomcat,Web,zk)