Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Adding a jar file to eclipse
Adding a jar file to eclipse [message #208654] Wed, 02 May 2007 18:59 Go to next message
Phil Troy is currently offline Phil TroyFriend
Messages: 4
Registered: July 2009
Junior Member
Hi!

I have developed a java project using eclipse, and it works. I wish to
add logging to it, and have downloaded the log4j.jar. I wish to make the
classes in that jar file accessible to my project.

Can someone give me or point me to explicit step by step directions for
making a jar file accessible to my eclipse java project?

Thanks/Phil
Re: Adding a jar file to eclipse [message #208671 is a reply to message #208654] Wed, 02 May 2007 21:24 Go to previous messageGo to next message
Paul A. Rubin is currently offline Paul A. RubinFriend
Messages: 188
Registered: July 2009
Senior Member
Phil Troy wrote:
>
> I have developed a java project using eclipse, and it works. I wish to
> add logging to it, and have downloaded the log4j.jar. I wish to make
> the classes in that jar file accessible to my project.
> Can someone give me or point me to explicit step by step directions for
> making a jar file accessible to my eclipse java project?
>

In the Package Explorer, right click on the project, select Build Path
-> Add External Archives..., and point to the jar file. Ir should then
show up in the Package Explorer, as if it were part of the project.

/Paul
Re: Adding a jar file to eclipse [message #208819 is a reply to message #208671] Thu, 03 May 2007 15:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse5.rizzoweb.com

Paul Rubin wrote:
> Phil Troy wrote:
>>
>> I have developed a java project using eclipse, and it works. I wish
>> to add logging to it, and have downloaded the log4j.jar. I wish to
>> make the classes in that jar file accessible to my project. Can
>> someone give me or point me to explicit step by step directions for
>> making a jar file accessible to my eclipse java project?
>>
>
> In the Package Explorer, right click on the project, select Build Path
> -> Add External Archives..., and point to the jar file. Ir should then
> show up in the Package Explorer, as if it were part of the project.

An alternative I recommend is to import/copy the JAR into your project,
put it in a /lib directory. Then you can right-click on the project,
choose Properties, then select the Java Build Path section to add the
JAR on the Libraries tab.
It is generally a good idea to have all the JARs that your code depends
on be located with the project if at all possible.

Hope this helps,
Eric
Re: Adding a jar file to eclipse [message #208863 is a reply to message #208819] Thu, 03 May 2007 16:56 Go to previous messageGo to next message
Paul A. Rubin is currently offline Paul A. RubinFriend
Messages: 188
Registered: July 2009
Senior Member
Eric Rizzo wrote:
>
> An alternative I recommend is to import/copy the JAR into your project,
> put it in a /lib directory. Then you can right-click on the project,
> choose Properties, then select the Java Build Path section to add the
> JAR on the Libraries tab.
> It is generally a good idea to have all the JARs that your code depends
> on be located with the project if at all possible.
>

Out of curiosity, do you do that even if the JAR is a library that will
be used by other projects (so that you'll end up with multiple copies of
the JAR scattered around)?

/Paul
Re: Adding a jar file to eclipse [message #208891 is a reply to message #208863] Thu, 03 May 2007 21:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dtoland.email.uophx.edu

You can put the jar files into a project created to hold shared libraries,
add a reference to the project in other projects, and add the shared project to
the build path of other projects.

--
Dave Toland
dave.toland@verizon.net

"Paul Rubin" <rubin@msu.edu> wrote in message news:f1d47b$jrf$1@build.eclipse.org...

| Eric Rizzo wrote:
| >
| > An alternative I recommend is to import/copy the JAR into your project,
| > put it in a /lib directory. Then you can right-click on the project,
| > choose Properties, then select the Java Build Path section to add the
| > JAR on the Libraries tab.
| > It is generally a good idea to have all the JARs that your code depends
| > on be located with the project if at all possible.
| >
|
| Out of curiosity, do you do that even if the JAR is a library that will
| be used by other projects (so that you'll end up with multiple copies of
| the JAR scattered around)?
|
| /Paul
|
Re: Adding a jar file to eclipse [message #208898 is a reply to message #208863] Fri, 04 May 2007 02:20 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse5.rizzoweb.com

Paul Rubin wrote:
> Eric Rizzo wrote:
>>
>> An alternative I recommend is to import/copy the JAR into your
>> project, put it in a /lib directory. Then you can right-click on the
>> project, choose Properties, then select the Java Build Path section to
>> add the JAR on the Libraries tab.
>> It is generally a good idea to have all the JARs that your code
>> depends on be located with the project if at all possible.
>>
>
> Out of curiosity, do you do that even if the JAR is a library that will
> be used by other projects (so that you'll end up with multiple copies of
> the JAR scattered around)?

Many times, yes. Disk space is cheap ;-)
Having each project own its dependencies is essential sometimes. Imagine
one app that needs version x of a JAR and a different app needs the same
library but version y.
Sometimes I do use a "Common Libs" project that contains commonly used
libraries, but you have to make sure the JAR files all include version
info in their names (something I always do anyway).
The end-goal is to minimize the steps required to go from virgin machine
to successful build. Having all the dependent JARs in the project helps
towards that goal, but a "Common Libs" project is reasonably close.

Eric
Re: Adding a jar file to eclipse [message #208954 is a reply to message #208898] Fri, 04 May 2007 15:29 Go to previous message
Paul A. Rubin is currently offline Paul A. RubinFriend
Messages: 188
Registered: July 2009
Senior Member
Eric Rizzo wrote:

>
> Many times, yes. Disk space is cheap ;-)
> Having each project own its dependencies is essential sometimes. Imagine
> one app that needs version x of a JAR and a different app needs the same
> library but version y.
> Sometimes I do use a "Common Libs" project that contains commonly used
> libraries, but you have to make sure the JAR files all include version
> info in their names (something I always do anyway).
> The end-goal is to minimize the steps required to go from virgin machine
> to successful build. Having all the dependent JARs in the project helps
> towards that goal, but a "Common Libs" project is reasonably close.
>

Makes sense. I'm not a developer, and I have the luxury that stuff I
write pretty much always works with later versions of libraries, so I go
the direction that requires the fewest memory cells to ensure that a
library upgrade gets everything updated. :-) Plus I have at least one
library with a license that precludes multiple copies (I think).
Deployment for me usually means installing on a total of one other
machine, another luxury.

Thanks,
Paul
Previous Topic:Alternating row colors in a table in groups
Next Topic:Easiest way of making the Navigator bar appear and disappear
Goto Forum:
  


Current Time: Fri Apr 19 08:27:15 GMT 2024

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

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

Back to the top