ant -f build.xml运行vs ant -f build jar

时间:2011-10-21 00:56:43

标签: java netbeans ant

任何人都可以告诉我之间的技术差异,

1 -

ant -f build.xml run 

2-

ant -f build.xml jar
java -jar project.jar

我问这个是因为我的应用程序运行完美,我用数字“1”命令运行它

BUT

当作为jar文件(第2个命令集)运行时,会产生大量异常。

对此有何解释?我只是想知道为什么应用程序对这两种情况的反应不同???!

由于

<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="LMB" default="default" basedir=".">
    <description>Builds, tests, and runs the project LMB.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. They are: 

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported 
    nbproject/build-impl.xml file. 


    Another way to customize the build is by overriding existing main targets.
    The targets of interest are: 

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
      -do-jar-without-manifest: JAR building (if you are not using a manifest)
      run:                      execution of project 
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look like this:

        <target name="run" depends="iDA-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only on 
    the compile target as the regular run target does. Again, for a list of available 
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file. 

    -->
</project>

这是清单文件

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0-b147 (Oracle Corporation)
Class-Path: lib/beansbinding-1.2.1.jar lib/AbsoluteLayout.jar lib/appf
 ramework-1.0.3.jar lib/swing-worker-1.1.jar lib/swing-layout-1.0.4.ja
 r lib/commons-codec-1.4.jar lib/commons-codec-1.5.jar lib/commons-log
 ging-1.1.1.jar lib/derby.jar lib/derbyLocale_cs.jar lib/derbyLocale_d
 e_DE.jar lib/derbyLocale_es.jar lib/derbyLocale_fr.jar lib/derbyLocal
 e_hu.jar lib/derbyLocale_it.jar lib/derbyLocale_ja_JP.jar lib/derbyLo
 cale_ko_KR.jar lib/derbyLocale_pl.jar lib/derbyLocale_pt_BR.jar lib/d
 erbyLocale_ru.jar lib/derbyLocale_zh_CN.jar lib/derbyLocale_zh_TW.jar
  lib/derbyclient.jar lib/derbynet.jar lib/derbyrun.jar lib/derbytools
 .jar lib/httpclient-4.1.2.jar lib/httpclient-cache-4.1.2.jar lib/http
 core-4.1.2.jar lib/httpmime-4.1.2.jar lib/jdom.jar lib/orangevolt-ant
 -tasks-1.3.8.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: lmb.LMBApp

注意:
在这里,我发现了这个问题的来源,但我不知道如何修复它,

关于库引用和环境变量的一切都很好,除了我在启动jar文件时没有获得与服务器的SSL连接这一事实,而在Netbeans内部运行应用程序时很容易建立连接。事实上,当通过最终的jar执行时,我得到了以下Exception,

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)

请帮助我

2 个答案:

答案 0 :(得分:0)

可能第一个使用编译(或执行)类路径,而第二个依赖于环境类路径(jar不包括所有应用程序的依赖项)。

答案 1 :(得分:0)

清单中的所有项目都需要添加到类路径调用中。

这可能包含一个依赖项jar列表,​​您可以使用-classpath选项将其包含在命令行中

java -cp gen/jars/test.jar -jar project.jar

您可以内联Ant build.xml和/或抛出的异常,以便我们为您提供更多信息。