步驟一:
????? 自己的程序先打一個(gè)包my.jar(可以是不可執(zhí)行的),這個(gè)不包含第三方資源包(如log4j.jar);用myeclipse的export方式可以搞定;
步驟二:
???? 寫一些加載第三方資源包的類,這里可以參考這個(gè)類(網(wǎng)上找的

import java.io.*;??
import java.net.*;??
import java.lang.reflect.*;??
?
public class BootLoader??
{??
? public static void main(final String[] args) throws Exception??
? {??
??? // check that the lib folder exists??
??? File libRoot = new File(LIB_FOLDER);??
??? if(!libRoot.exists()) {??
????? throw new Exception("No 'lib' folder exists!");??
??? }??
??? // read all *.jar files in the lib folder to array??
??? File[] libs = libRoot.listFiles(new FileFilter()??
??? {??
????? public boolean accept(File dir)??
????? {??
??????? String name = dir.getName().toLowerCase();??
??????? return name.endsWith("jar") || name.endsWith("zip");??
????? }??
??? });??
?
??? URL[] urls = new URL[libs.length];??
??? // fill the urls array with URLs to library files found in libRoot??
??? for(int i = 0; i < libs.length; i++) {??
????? urls[i] = new URL("file",null,libs[i].getAbsolutePath());??
??? }??
??? // create a new classloader and use it to load our app.??
??? classLoader = new URLClassLoader(urls,??
???????????????????????????????????? Thread.currentThread().??
???????????????????????????????????? getContextClassLoader());??
??? // get the main method in our application to bring up the app.??
??? final Method mtd = classLoader.loadClass(APP_MAIN_CLASS).getMethod("main",??
??????? new Class[] {String[].class});??
??? // Using thread to launch the main 'loop' so that the current Main method??
??? // can return while the app is starting??
??? new Thread(new Runnable()??
??? {??
????? public void run()??
????? {??
??????? try {??
????????? mtd.invoke(null,new Object[] {args});??
??????? } // forward the args??
??????? catch(Exception e) {??
????????? throw new RuntimeException(e);??
??????? }??
????? }??
??? },"AppMain").start();??
??? // Give the app some time to start before returning from main.??
??? // This doesn't delay the starting in any way??
??? Thread.sleep(1000);??
? }??
?
? private static final String LIB_FOLDER = "lib";?? //所有第三方包放在這個(gè)文件夾下
? private static final String APP_MAIN_CLASS = "com.monitor.Main";?? //可執(zhí)行文件的入口程序,也是你自己代碼的一個(gè)包含main函數(shù)的類
? private static ClassLoader classLoader;??
}?
再將這個(gè)獨(dú)立的類打包成可執(zhí)行文件main.jar(不包含第三方資源包)
步驟三:組織好各個(gè)文件
比如在文件下F:/存在 文件
main.jar
lib(文件夾,lib文件夾下 放:my.jar ,log4j.jar,等等)
config.properties(如果有配置文件)
logo.jpg(如果有外部圖片)
可以寫個(gè)批處理文件main.bat 內(nèi)容: java? -Xms100m?? -Xmx800m? -jar main.jar
雙擊main.bat 即可執(zhí)行