|
Re: Using a User Library of jars on the Tomcat classpath [message #893814 is a reply to message #893678] |
Thu, 05 July 2012 14:41 |
Larry Isaacs Messages: 1354 Registered: July 2009 |
Senior Member |
|
|
If you examine Tomcat's catalina.bat file you would find it contains the
line:
set CLASSPATH=
Having jars get picked up and added to the server via the "application"
classpath in this fashion causes far more problems than it solves.
Thus, Tomcat "ignores" this environment variable and starts up with only
what it knows is appropriate for the "application" classpath.
As a result, the Tomcat support in WTP includes no special effort to
support adding jars to the "application" classpath as it's generally not
a good idea. It turns out that you can add jars directly to the "User
Entries", but there is no support for resolving the contents of a User
Library.
It would be better to add the JDBC Library to the web project instead.
Add it to the Java Build Path. A "Classpath Dependency..." warning will
appear in the Markers and Problems view. The Quick Fix for the warning
will include that dependency in what gets published to the webapp's
WEB-INF/lib. Now the webapp's dependency is addressed in the project
where it belongs and not by the Server configuration, which is external
to the project.
Cheers,
Larry
On 7/5/2012 4:49 AM, Adam Hardy wrote:
> I'm running Eclipse Indigo and Tomcat 6 and they are not playing nicely.
>
> I have a web project which needs JDBC drivers - in fact it needs 3 JDBC
> drivers. Since I have multiple installs of Tomcat, I figured it would be
> easier to put the 3 JDBC jars in a User Library and place that on the
> Tomcat classpath in its launch configuration, rather than adding 3 jars
> at a time.
> Sounds like a minor issue - guess it is, but I'm documenting the process
> for our team and it would nice to have.
>
> This is how I do it:
>
>
> Create a user library
> Add the 3 JDBC driver jar to it
> Open up a server config window via double click in Servers view
> change to Classpath tab
> Select 'User Entries'
> Click on Advanced button
> Choose Add Library
> Choose User Library
> Select the JDBC library
> Done
>
>
> but Eclipse doesn't add the jars. The app fails when it tries to connect
> to the DB and secondly when I add the server as a run-time target to the
> project, then in the project view I figured I should see the jars as well.
> Am I doing something wrong or does Eclipse WTP not work like that? If it
> is just functionality that never existed, why not? Surely I'm not the
> first to want to do this? To tell the truth, googling the problem didn't
> find any sign of other people having the issue, so maybe I am.
>
|
|
|
Re: Using a User Library of jars on the Tomcat classpath [message #893838 is a reply to message #893814] |
Thu, 05 July 2012 16:02 |
Adam Hardy Messages: 5 Registered: July 2009 |
Junior Member |
|
|
Hi Larry,
thanks for the response.
The application sets up the JDBC drivers as JNDI resource via the context.xml and as a result, having the driver jars in the project's WEB-INF/lib means they are not found when the JNDI resources get created, causing an error.
I deduced from the tomcat wtp faq that I can tell tomcat to load up jars by putting them all in a directory and refering to it in catalina.properties:
shared.loader = /home/adam/jdbc/*.jar
which is a few steps quicker than adding them one by one to the server classpath user entries.
Of course it's one extra step to remember if you quickly want to delete the Eclipse instance of the tomcat server and re-create it, so I am beginning to think that just copying the drivers into the tomcat/lib directory outside Eclipse is probably the most effective approach after all.
I see though that adding the tomcat instance as a run-time target to the project's properties creates an Apache Tomcat 6 library folder in the project's Java Resources/Libraries. Why is this functionality provided? Surely it's not just a visual reminder of what jars are present on the server?
Just trying to get a good grasp of the way WTP is designed to function.
Regards
Adam
Larry Isaacs wrote on Thu, 05 July 2012 10:41If you examine Tomcat's catalina.bat file you would find it contains the
line:
set CLASSPATH=
Having jars get picked up and added to the server via the "application"
classpath in this fashion causes far more problems than it solves.
Thus, Tomcat "ignores" this environment variable and starts up with only
what it knows is appropriate for the "application" classpath.
As a result, the Tomcat support in WTP includes no special effort to
support adding jars to the "application" classpath as it's generally not
a good idea. It turns out that you can add jars directly to the "User
Entries", but there is no support for resolving the contents of a User
Library.
It would be better to add the JDBC Library to the web project instead.
Add it to the Java Build Path. A "Classpath Dependency..." warning will
appear in the Markers and Problems view. The Quick Fix for the warning
will include that dependency in what gets published to the webapp's
WEB-INF/lib. Now the webapp's dependency is addressed in the project
where it belongs and not by the Server configuration, which is external
to the project.
|
|
|
Re: Using a User Library of jars on the Tomcat classpath [message #893866 is a reply to message #893838] |
Thu, 05 July 2012 18:00 |
Larry Isaacs Messages: 1354 Registered: July 2009 |
Senior Member |
|
|
On 7/5/2012 12:02 PM, Adam Hardy wrote:
> Hi Larry,
>
> thanks for the response.
> The application sets up the JDBC drivers as JNDI resource via the
> context.xml and as a result, having the driver jars in the project's
> WEB-INF/lib means they are not found when the JNDI resources get
> created, causing an error.
> I deduced from the tomcat wtp faq that I can tell tomcat to load up jars
> by putting them all in a directory and refering to it in
> catalina.properties:
>
> shared.loader = /home/adam/jdbc/*.jar
>
> which is a few steps quicker than adding them one by one to the server
> classpath user entries.
>
> Of course it's one extra step to remember if you quickly want to delete
> the Eclipse instance of the tomcat server and re-create it, so I am
> beginning to think that just copying the drivers into the tomcat/lib
> directory outside Eclipse is probably the most effective approach after
> all.
> I see though that adding the tomcat instance as a run-time target to the
> project's properties creates an Apache Tomcat 6 library folder in the
> project's Java Resources/Libraries. Why is this functionality provided?
> Surely it's not just a visual reminder of what jars are present on the
> server?
This is how the wep project gets access to the Servlet and JSP API
classes and establishes the version of the API you compile the project
against. It links the project to a Server Runtime, which might or might
not have any relationship to the Server(s) you add the project to. The
server simply has to support an API version equal or greater than what
the Server Runtime provides.
Cheers,
Larry
>
> Just trying to get a good grasp of the way WTP is designed to function.
> Regards
> Adam
>
> Larry Isaacs wrote on Thu, 05 July 2012 10:41
>> If you examine Tomcat's catalina.bat file you would find it contains
>> the line:
>>
>> set CLASSPATH=
>>
>> Having jars get picked up and added to the server via the
>> "application" classpath in this fashion causes far more problems than
>> it solves. Thus, Tomcat "ignores" this environment variable and starts
>> up with only what it knows is appropriate for the "application"
>> classpath.
>>
>> As a result, the Tomcat support in WTP includes no special effort to
>> support adding jars to the "application" classpath as it's generally
>> not a good idea. It turns out that you can add jars directly to the
>> "User Entries", but there is no support for resolving the contents of
>> a User Library.
>>
>> It would be better to add the JDBC Library to the web project instead.
>> Add it to the Java Build Path. A "Classpath Dependency..." warning
>> will appear in the Markers and Problems view. The Quick Fix for the
>> warning will include that dependency in what gets published to the
>> webapp's WEB-INF/lib. Now the webapp's dependency is addressed in the
>> project where it belongs and not by the Server configuration, which is
>> external to the project.
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.06955 seconds