tags:

views:

2061

answers:

2

I download the Apache POI from apache.org but don't know how use it with one of my existing project in Eclipse.

+2  A: 

You can find the option to add external jars to a project in: Project > Properties > Java Build Path > Libraries tab.

Click on 'Add External Jar' and find where you have the POI library.

jjnguy
As I mention in my answer, be careful with this is you share the project with anyone. The classpath for your project will hardcode the location of the jar. Unless all developers have it in the same location, you'll constantly change it...
Scott Stanchfield
+1  A: 

There are several ways, some good, some bad...

  • Add external Jar - as jjnguy says will work. However, not a good option... The problem is that if you share your project with someone else and they have the jar in a different spot, they'll get build path errors

  • Add variable - similar to add external jar, but much more flexible. You can define a classpath variable (under Java prefs) that represents the dir containing jar. In your project, when you add variable, you choose the var you defined and press "extend" to specify the actual jar. As long as you and other developers of your project define the variable, you can have the jar in different spots if you like

  • Add the jar to your project - create a dir in your project (optional, maybe call it lib) and import the jar into it using File->Import or if your OS supports, drag it as an icon into the folder (On windows I open an explorer window and drag it from there into the folder in eclipse). Then, right-click the jar and select Build-Path->Add to build path.

  • Add the jar in a separate project and reference it. Add the jar as mentioned in the last bullet to a separate project for that jar. Choose Build-Path->Configure Build path from the project. Go to the "order and export" tab and make sure the jar is checked. Now you can configure your project to reference the new project. This makes things more modular.

  • Create a user library - under Java prefs you can define a "user library" that contains the jar. This is somewhat similar to a classpath variable, but can reference multiple jars and you only have to add it once to the project.

  • Create a classpath container plugin. This is more complex, but is a nice option if you are providing a set of plugins for folks. A classpath container can be added like a library to a project and it can manage the jars, even searching for them if you want it to.

Scott Stanchfield