Planet of NCCUCS
dosbox windows resolution Buy Microsoft Windows Server 2008 Web Edition SP2 configure internet connection on windows xp consumer ratings on vinyl windows Buy Microsoft Windows 7 Professional buy dhcp windows 2000 server apple usb keyboard windows drivers Buy Microsoft Office Visio Professional 2007 buy windows xp registration number buy windows applications Buy Microsoft Windows XP Professional SP3 disable autoplay cd windows 2000 asms windows xp home Buy McAfee Total Protection 2009 autocad lt autodesk contemporary windows Buy Cyberlink PowerDVD 8 Ultra check windows genuine effects for windows movie maker Buy Corel VideoStudio Pro X2 audio codec windows cannot end programs in windows xp Buy CorelDraw Graphics Suite X4 borland delphi 5 and windows vista cannot open windows updates Buy Autodesk AutoCAD 2009 checkpoint ngx r65 windows 2003 download terminal services client windows 2000 Buy Autodesk AutoCAD 2010 download windows xp file debug windows application Buy Autodesk 3Ds Max Design 2009 convert dbx outlook express windows mail automatically reboot windows xp Buy Ahead Nero 9 ashampoo defrag windows xp serious error cannot install printer driver windows 2000 Buy Microsoft Office 2003 Professional apple toolbar for windows delay write failed windows xp Buy Microsoft Office 2007 Enterprise cleanup windows startup

Fat-jar — 把全部的jar打包成一個可以執行的jar

作者:RedBug on 七月 28, 2008 Posted in RSS | | 觀看文章來源

在寫java程式時,常常需要引用外部的library。
傳統只要把這些外部的library放置於jre/lib/ext/ ,便可以存取。

不過若是用eclipse開發java程式,
則可以在Project上按右鍵,可簡單的依下列方式引用外部的library
Properties-> Java Build Path-> Libraries-> Add External JARs

但是當Project要export出來成可執行的jar檔時,
若沒有對classpath做設定,可能造成jar檔找不到外部library的jar檔而無法執行。

過去我都把Project export出來的proj.jar 與外部的lib1.jar及lib2.jar放在同一個目錄,並寫一個bat檔來執行它們。
bat檔的內容如下: (其實這是佷久以前陶百神教我的)
java -classpath proj.jar;lib1.jar;lib2.jar Main-ClassName(沒有.class哦)

不過托阿德的福,今天才發現原來eclipse有個很方便的plugin叫 Fat-jar
可以從Eclipse的選單,help-> software updates -> Find and Install -> Search for new features to install -> new remote site

會跳出一個輸入對話窗,要求plugin的名字和更新的來源,輸入如下:
Name: Fat Jar
URL: http://kurucz-grafika.de/fatjar

之後便開始安裝Fat-jar

Fat-jar 簡單易用,

直接在要export的Project上按右鍵,選"build fat-jar"

之後便會跳出選單,把你的Main-Class 設定好,按下一步。

接著把你要一起包進去的lib1.jar lib2.jar …勾選,按下一步。

它就會幫你全部打包成一個xxx.jar檔,並放置於你的Project的根目錄下。

這個xxx.jar檔無論放在什麼位置,應該都是雙點便可執行的。

也可以在console下輸入java -jar xxx.jar 來執行它。

 

Reference:

Java World
http://www.javaworld.com.tw/jute/post/view?bid=20&id=111801&sty=1&tpg=1&age=0

,

:, ,

讀過本文的讀者, 也對以下文章有興趣

No comments for this entry yet...

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

最新文章

照片

R0012028R0012036R0013553R0013551R0013550R0013549R0013560R0013558R0013569R0013561R0013570R0013571R0013580R0013581R0013556R0013567R0013563R0013572R0011783R0012312