简体   繁体   中英

How Can I Add the Apache POI Library in and Eclipse Project?

我从apache.org下载Apache POI,但不知道如何在Eclipse中使用我现有的项目。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM