免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1061 | 回复: 0
打印 上一主题 下一主题

Eclipse打包工具Fatjar [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-03 09:10 |只看该作者 |倒序浏览


前几天看到一款好用的eclipse打包工具,能够将引用的jar文件都打包出来,做到一个jar包中去。这样自己的程序和其他引用到的jar文件就能够作为独立的程序运行了,非常方便。介绍如下:
                        The Fat Jar Eclipse Plug-In is a Deployment-Tool which deploys an
                        Eclipse java-project into one executable jar.

                       
                        It adds the Entry "Build Fat-JAR" to the Export-Wizard.
                        In addition to the eclipse standard jar-exporter referenced classes and jars are
                        included to the "Fat-Jar", so the resulting jar contains all needed classes and
                        can be executed directly with "java -jar", no classpath has to be set, no
                        additional jars have to be deployed.
                       
                        Jars, External-Jars, User-Libraries, System-Libraries, Classes-Folders and
                        Project-Exports are considered by the plugin.
                        The Main-Class can be selected and Manifest-files are merged.
                        The One-JAR option integrates a specialised Class-Loader written by
                        Simon Tuffs ( http://one-jar.sourceforge.net/ ) which handles jar-files
                        inside a jar.
                        Individual files and folders can be excluded or added to the jar.
                        Different settings can be stored and re-executed as "Quick Build"
                        via the context-menu.
这里有一个使用方法简介,使用非常简单,如下:
                Fat Jar Eclipse Plug-In Tutorial
               
                Step 1: Create a new Java Project "demolib"
               
                        Create a new Java Project named "demolib".
                        Add the Class "demolib.DemoLib.java" containing the following code:
                       
package demolib;
public class DemoLib {
    public static void sayHello() {
        System.out.println("Hello");
    }
}
                       
                        The Project should look something like this:
               
               

               
                Step 2: Create a jar file using Fat Jar Plug-In
               
                        In the "Package-Explorer" (not the "Resource-View") right click on the project "demolib".
                        Select "+ Build Fat Jar".
               
               

               
               
                        A Configuration Dialog appears. Just press "Finish".
               
               

               
               
                        The File "demolib_fat.jar" has been created in the project root directory.
               
               

               
               
                Step 3: Create a new Java-Project "demorun"
               
                        Create a new Java Project named "demorun".
                        In the project properties add the Library "demolib/demolib_fat.jar" to the Java Build Path":
               
               

               
               
                Step 4: Create Main Class
               
                        Add the Class "demorun.DemoRunMain.java" containing the following code:
                       
package demorun;
import demolib.DemoLib;
public class DemoRunMain {
    public static void main(String[] args) {
        DemoLib.sayHello();
    }
}
                       
                        The Project should look something like this:
               
               

               
               
                Step 5: Start the Build Fat Jar Dialog
               
                        Start the Export Wizard from the File-Menu ("File" -> "Export").
                        Select  "+ Fat Jar Exporter" and click "next >".
               
               

               
               
                        Select the project "demorun" and click "next >".
               
               

               
               
                        A Configuration-Dialog appears showing the current Settings.
               
               

               
               
                Step 6: Select the Main Class
               
                        The Main Class - the one containing the static methode main - must be defined in the jar.
                        Click on the "Browse..." Button on the right side behind the Main-Class Edit field.
               
               

               
               
                        Select "DemoRunMain" and click the "OK" Button.
                            The FullyQualifiedName "demorun.DemoRunMain" is now set for "Main-Class".
               
               
                Step7: Finish
               
                        Save the current Settings by clicking on the "Finish" Button.
               
               

               
               
               
                        The File "demorun_fat.jar" has been created in the project root directory.
                        In addition the file ".fatjar" storing the configuration settings has been created in the project root directory
                       
                        The created jar file contains all classes from all referenced jar files (demolib_fat.jar) and the project classes.
                        This file can be executed anywhere, no classpath has to be set, because all necessary libraries
                        are extracted inside the "Fat Jar":
                       
> java -jar demorun_fat.jar
Hello
                       
               
               
back
               
               
       
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/3176/showart_373105.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP