Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsUsing a User Library of jars on the Tomcat classpath
https://www.eclipse.org/forums/index.php/mv/msg/366919/893678/#msg_893678
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.
]]>Adam Hardy2012-07-05T08:49:52-00:00Re: Using a User Library of jars on the Tomcat classpath
https://www.eclipse.org/forums/index.php/mv/msg/366919/893814/#msg_893814
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.
>]]>Larry Isaacs2012-07-05T14:41:01-00:00Re: Using a User Library of jars on the Tomcat classpath
https://www.eclipse.org/forums/index.php/mv/msg/366919/893838/#msg_893838
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: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.
]]>Adam Hardy2012-07-05T16:02:05-00:00Re: Using a User Library of jars on the Tomcat classpath
https://www.eclipse.org/forums/index.php/mv/msg/366919/893866/#msg_893866
> 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.
>
>]]>Larry Isaacs2012-07-05T18:00:22-00:00Re: Using a User Library of jars on the Tomcat classpath
https://www.eclipse.org/forums/index.php/mv/msg/366919/893978/#msg_893978
Adam Hardy2012-07-06T09:45:43-00:00