Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Include web project in another web project
Include web project in another web project [message #654519] Wed, 16 February 2011 08:04 Go to next message
snellius  is currently offline snellius Friend
Messages: 3
Registered: February 2011
Junior Member
Hi everyone!

I have a web project A that works quite fine. I have a servlet in a different web project B to works quite fine too Smile
Now I want to use some classes from project A in my project B and I somehow don't get it to work. I added project A to the dependencies of project B ("Project Properties ->Java Build Path -> Projects") and I am now able to use the classes from the "foreign" project. - But when I try to run project B on my local Tomcat server (via Debug as -> Debug on Server) Tomcat can't find the class files from project A, so I guess the are not deployed correctly.
As a workaround, I linked the complete src-folder from project A into my project B and that seems to work. But I doubt that that's the right way to do it.
I admit I'm new to this eclipse and web stuff. I found some discussions that seemed to point in the same direction, but none of them provided a solution I was able to use Smile
Hope I made my problems clear und gave you all the info you need - if not: let me know.

Regards: snellius

PS:
- Eclipse Java EE IDE for Web Developers. Version: Helios Service Release 1Build id: 20100917-0705
- apache-tomcat-7.0.8
Re: Include web project in another web project [message #654604 is a reply to message #654519] Wed, 16 February 2011 13:26 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3265
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2011.02.16 1:04, snellius wrote:
> Hi everyone!
>
> I have a web project A that works quite fine. I have a servlet in a
> different web project B to works quite fine too :)
> Now I want to use some classes from project A in my project B and I
> somehow don't get it to work. I added project A to the dependencies of
> project B ("Project Properties ->Java Build Path -> Projects") and I am
> now able to use the classes from the "foreign" project. - But when I try
> to run project B on my local Tomcat server (via Debug as -> Debug on
> Server) Tomcat can't find the class files from project A, so I guess the
> are not deployed correctly.
> As a workaround, I linked the complete src-folder from project A into my
> project B and that seems to work. But I doubt that that's the right way
> to do it.
> I admit I'm new to this eclipse and web stuff. I found some discussions
> that seemed to point in the same direction, but none of them provided a
> solution I was able to use :)
> Hope I made my problems clear und gave you all the info you need - if
> not: let me know.
>
> Regards: snellius
>
> PS:
> - Eclipse Java EE IDE for Web Developers. Version: Helios Service
> Release 1Build id: 20100917-0705
> - apache-tomcat-7.0.8

Personally, I have always created a third project, a library, that
contributes to both projects A and B. However, I'm eager to hear what
others have to say about best practice.
Re: Include web project in another web project [message #654664 is a reply to message #654604] Wed, 16 February 2011 15:37 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1313
Registered: July 2009
Senior Member
On 2/16/2011 8:26 AM, Russell Bateman wrote:
> On 2011.02.16 1:04, snellius wrote:
>> Hi everyone!
>>
>> I have a web project A that works quite fine. I have a servlet in a
>> different web project B to works quite fine too :)
>> Now I want to use some classes from project A in my project B and I
>> somehow don't get it to work. I added project A to the dependencies of
>> project B ("Project Properties ->Java Build Path -> Projects") and I am
>> now able to use the classes from the "foreign" project. - But when I try
>> to run project B on my local Tomcat server (via Debug as -> Debug on
>> Server) Tomcat can't find the class files from project A, so I guess the
>> are not deployed correctly.
>> As a workaround, I linked the complete src-folder from project A into my
>> project B and that seems to work. But I doubt that that's the right way
>> to do it.
>> I admit I'm new to this eclipse and web stuff. I found some discussions
>> that seemed to point in the same direction, but none of them provided a
>> solution I was able to use :)
>> Hope I made my problems clear und gave you all the info you need - if
>> not: let me know.
>>
>> Regards: snellius
>>
>> PS:
>> - Eclipse Java EE IDE for Web Developers. Version: Helios Service
>> Release 1Build id: 20100917-0705
>> - apache-tomcat-7.0.8
>
> Personally, I have always created a third project, a library, that
> contributes to both projects A and B. However, I'm eager to hear what
> others have to say about best practice.
>

Adding a dependency via Project Properties ->Java Build Path -> Projects
only creates a "build-time" dependency. Since JDT doesn't have any
notion of Java EE runtime dependencies, you will run into the expected
errors at runtime. For the right way to address both "build-time" and
Java EE runtime dependencies for shared classes, I agree with Russell.
Put the shared classes in a Utility Project and have both Dynamic Web
Projects depend on that Utility Project via the Deployment Assembly
page. Each published web project will get a jar in their WEB-INF/lib
that matches the name of the utility project and contains the shared
classes.

Cheers,
Larry
Re: Include web project in another web project [message #654671 is a reply to message #654664] Wed, 16 February 2011 16:09 Go to previous messageGo to next message
snellius  is currently offline snellius Friend
Messages: 3
Registered: February 2011
Junior Member
Larry Isaacs wrote on Wed, 16 February 2011 10:37

Adding a dependency via Project Properties ->Java Build Path -> Projects
only creates a "build-time" dependency. Since JDT doesn't have any
notion of Java EE runtime dependencies, you will run into the expected
errors at runtime.


Yes, thanks for the explanation - that makes sense to me.
Quote:

For the right way to address both "build-time" and
Java EE runtime dependencies for shared classes, I agree with Russell.
Put the shared classes in a Utility Project and have both Dynamic Web
Projects depend on that Utility Project via the Deployment Assembly
page. Each published web project will get a jar in their WEB-INF/lib
that matches the name of the utility project and contains the shared
classes.

Cheers,
Larry


Thank both of you very much for this solution. This is a quite better way to do it.

Regards: snellius
Re: Include web project in another web project [message #654780 is a reply to message #654671] Thu, 17 February 2011 07:33 Go to previous messageGo to next message
snellius  is currently offline snellius Friend
Messages: 3
Registered: February 2011
Junior Member
Another thing though...

The reason for the setup I described is that the project which I wanted to "include" (project A) was developed by an external contractor and I am supposed to modify it as little as possible.
So - though the suggestions made here seem more reasonable - is it possible to do it in a different way in eclipse? Hopefully without messing with the build files "by hand"?

Thanks a lot:

Snellius
Re: Include web project in another web project [message #654893 is a reply to message #654780] Thu, 17 February 2011 14:22 Go to previous message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1313
Registered: July 2009
Senior Member
On 2/17/2011 2:33 AM, snellius wrote:
> Another thing though...
>
> The reason for the setup I described is that the project which I wanted
> to "include" (project A) was developed by an external contractor and I
> am supposed to modify it as little as possible.
> So - though the suggestions made here seem more reasonable - is it
> possible to do it in a different way in eclipse? Hopefully without
> messing with the build files "by hand"?
>
> Thanks a lot:
>
> Snellius

If you really want to make Project B "appear" to extend Project A, then
you would have to "include" what you needed from Project A in Project B
via linked folders, since there is no support for this via
"dependencies". One problem you may face is that you could end up with
two web.xml files in the "WebContent" portion of Project B. I'm pretty
sure there isn't any code in WTP to handle that scenario. I don't know
what behavior you will get in that case.

There may be a way to make this work if Project A can be modified, if
necessary, to support "inclusion". For example, the web.xml could be
put in a separate "WebContent" folder from the rest of the content,
allowing this other content to be "included" in Project B without
pulling in web.xml. The web.xml in Project B would have to duplicate
the one in Project A, plus any additions or modifications.

You may have to experiment to determine what expectations WTP has about
web.xml. For example, if you have multiple "WebContent" folders in a
project, are there any requirements about which one contains web.xml.
Does it need to be the first one listed on the Deployment Assembly page,
or will things work correctly regardless of which one it is in?

Cheers,
Larry
Previous Topic:Setting audio notification for server startup
Next Topic:javax.servlet.jsp.JspException cannot be resolved to a type
Goto Forum:
  


Current Time: Fri Dec 19 14:30:13 GMT 2014

Powered by FUDForum. Page generated in 0.02542 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software