开发者

How to share code between a Java Web app and a normal Java app

I have smallish personal project consisting of the following Eclipse workspace.

+
+-MyApp // this is just a vanilla Java Application
+-MyWebApp // this Dynamic Java Web Application (Tomcat)
+-MyCommonStuff // these are common classes 
                // Ex. Database access code & business classes 

This is all well and good when I'm running on eclipse coz I can use Eclipse build properties to make the two apps reference the common project.

I am now thinking of how to deploy my app to a linux server and I'm wondering how to do it. Can eclipse be used to build appropriate targets which can then reference the common stuff when running in a live en开发者_高级运维vironment?

Or do I have to learn how to use builders like Ant or Maven. Thanks


You just need to add the common projects to the build path of the webapp project and to add them as web library dependency.

In the properties of your webapp project, go to Java Build Path > Projects and select the the common projects from your workspace to add them to the build path. Then, in the Java EE Module Dependencies select the projects which needs to be exposed in the WEB-INF/lib. That should be it.


You don't have to learn to use maven, but there are compelling reasons for doing so.

One of which is, maven can set up your Eclipse's build path up for you (And the next guy who has to work on your code, and the next guy...)

One simple 'mvn eclipse:eclipse' and all your build path setup is done!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜