在Eclipse中运行pdfbox

【前言】pdfbox是实验室做文档识别需要了解的开源项目,可是官网doc过于简略,网上资料很多只是调用jar并非在Eclipse中配置运行源代码,仅以此文祭奠我两天的折腾时间……

0) Environment Specification
OS:Windows 7
IDE:Eclipse SDK 3.7.0
JDK:Version 6 Update 26

1) This post will not involve the configuration of Java, but you need to confirm JAVA_HOME is in your “Environment Variable” which we will need later on.
The key should be “JAVA_HOME” and the value is the path of JDK, for me is “D:Program FilesJavajdk1.6.0_26”

2) Download and extract pdfbox, pdfbox-*.*.*-src.zip, for me is “pdfbox-1.6.0-src.zip” and the extact location is “E:CodeJAVApdfbox-1.6.0”
http://pdfbox.apache.org/download.html

3) Download and Extract Maven2, apache-maven-*.*.*-bin.zip, for me is “apache-maven-3.0.3-bin.zip” and the extract location is “D:Program Filesapache-maven-3.0.3”
http://maven.apache.org/download.html

4) Configure the “Environment Variable” for Maven2 / Install Maven2
4.1) Add key “M2_HOME” and the value is path you extact Maven2, for me is “D:Program ilesapache-maven-3.0.3”
4.2) Add “%M2_HOME%bin” to the key “Path”.
4.3) Open a new command prompt and run “mvn –version” to verify correct installation.

5) Install and configure the pdfbox via Maven2
5.1) Open a new command prompt and change directory to the extract location of pdfbox
5.2) Run “mvn clean install” to install the pdfbox
5.3) Run “mvn eclipse:eclipse” to make it a eclipse project.
5.4) Run “mvn -Declipse.workspace=”PATH OF THE WORKSPACE” eclipse:configure-workspace” to add M2_REPO classpath variable to Eclipse.
Note : 5.3 & 5.4 is the MOST IMPORTANT part.

6) Import the project into Eclipse with the root directory of pdfbox (for me is E:CodeJAVApdfbox-1.6.0) then there should be no errors in all the projects.

7) Edit the “Run Configurations” and enter the command line arguments in the “Arguments” tab and then everything should run correctly.

Reference:
1) http://pdfbox.apache.org/userguide/building_pdfbox.html
2) http://maven.apache.org/download.html#Installation
3) http://maven.apache.org/guides/getting-started/index.html
4) http://www.mkyong.com/maven/how-to-configure-m2_repo-variable-in-eclipse-ide/

10 thoughts on “在Eclipse中运行pdfbox”

Leave a Reply