• eclipse中如何打jar包


    在eclipse中写个小测试程序(需要用到第三方jar文件),打成jar文件,然后到linux下执行做测试,查了很多资料也没有说怎么把第三方jar打入jar,使用ant,又太麻烦。

    1   选择Main类----->右击选择export----->runable jar files(备注:不是jar file选项,jar file选项不能执行,只能供第三方调用),出现如下对话框

    2 在Launch configuation中选择Main类处于的工程(选择其他的工程会生成jar失败)。如果Save as ANT script也选中并且提供路径,会顺便生成一个ant编译文件。Library handing选项就是集中处理第三方jar包的方式,我选择了第一种,根据意思翻译,其中几种也可以。

    点击完成即可生成。用java -jar TestJarMain.jar 能正确执行。

    解压TestJarMain.jar, 文件发现第三方jar以class的方式按照路径存在其中(我是自己写的jar,作为第三方jar)。

    查看MANIFEST.MF文件,里面内容如下:

    Manifest-Version: 1.0        ------版本
    Class-Path: .                      -----当前路径,是参照路径还是执行时到当前路径下找?待研究,执行的时候,用绝对路径,都可以执行。
    Main-Class: TestJarMain    -----执行的类是TestJarMain

    如果第一步选择的是Jar file而不是Runable Jar file, 则该文件只有第一项---版本项,其他两项没有。

    再看生成的build.xml

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <project default="create_run_jar" name="Create Runnable Jar for Project testJar12">
        <!--this file was created by Eclipse Runnable JAR Export Wizard-->
        <!--ANT 1.7 is required                                        -->
        <target name="create_run_jar">
            <jar destfile="C:/Documents and Settings/hz05995/桌面/TestJarMain.jar" filesetmanifest="mergewithoutmain">
                <manifest>
                    <attribute name="Main-Class" value="TestJarMain"/>
                    <attribute name="Class-Path" value="."/>
                </manifest>
                <fileset dir="D:/kanglsnow/workspace/testJar12/bin"/>
                <zipfileset excludes="META-INF/*.SF" src="C:/Documents and Settings/hz05995/桌面/TestJar.jar"/>
            </jar>
        </target>
    </project>

    还是基础太薄弱啦,流汗中。

  • 相关阅读:
    ping 带时间戳
    普通用户使用docker
    docker权限问题Got permission denied while trying
    Linux下离线安装Docker
    Linux启动流程和服务管理(init和systemd)
    CentOS 7 巨大变动之 systemd 取代 SysV的Init
    Linux系统常用的关机或重启命令shutdown、reboot、halt、poweroff、init 0及init 6的联系与区别
    linux的init.d
    linux service命令
    Linux下安装MySQL数据库(压缩包方式安装)
  • 原文地址:https://www.cnblogs.com/kangls/p/3636880.html
Copyright © 2020-2023  润新知