Ant构建 - Java项目 - 运行时异常与.properties

时间:2014-01-30 12:39:20

标签: java eclipse ant junit jenkins

我在运行时遇到此异常,同时使用ant工具从Jenkins开始我的测试(junit)活动: java.util.MissingResourceException:找不到基本名称的包 < / strong> com.mainpackage.V_45_4_3.view.translation.Translation,locale en_US

该目录中存在Translation_en_US.properties,它看起来像路径/类路径问题。

只有在我使用ant build工具时才会发生这种情况。从Eclipse开始,一切正常。 我将粘贴ant:

使用的.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<!--  -->

<property name="root.dir" location="." />
<property name="src.dir" location="${root.dir}/src" />
<property name="bin.dir" location="${root.dir}/bin" />
<property name="lib.dir" location="${root.dir}/lib" />

<property name="local.tests.dir" location="C:/NEMTESTS" />

<property name="test.src.dir" location="${root.dir}/tests" />

<property name="test.bin.dir" location="${local.tests.dir}/bin" />




<property name="javaClasspath" value="
            ${root.dir};
            ${bin.dir};
            ${lib.dir}/AdventNetSnmp.jar;
            ${lib.dir}/AdventNetLogging.jar;
            ${lib.dir}/ranabFtp.jar;
            ${lib.dir}/castor-1.2.jar;
            ${lib.dir}/synthetica.jar;
            ${lib.dir}/alu_LAF.jar;
            ${lib.dir}/jbasiccomp_java2.jar;
            ${lib.dir}/jnavapi_java2.jar;
            ${lib.dir}/jsch-0.1.50.jar;
            ${lib.dir}/j2ssh-daemon-0.3.1.jar;
            ${lib.dir}/j2ssh-core-0.3.1.jar;
            ${lib.dir}/j2ssh-common-0.3.1.jar;
            ${lib.dir}/j2ssh-core-0.2.9.jar;
            ${lib.dir}/commons-io-1.4.jar;
            ${lib.dir}/tar.jar;
            ${lib.dir}/maverick-debug-all.jar;
            ${lib.dir}/maverick-sshd-debug-no-j2ssh.jar;
            ${lib.dir}/fest-assert-1.3.jar;
            ${lib.dir}/fest-reflect-1.2.jar;
            ${lib.dir}/fest-swing-1.2.jar;
            ${lib.dir}/fest-util-1.1.4.jar;
            ${lib.dir}/fest-swing-junit-1.2.jar;
            ${lib.dir}/fest-swing-junit-4.5-1.2.jar;
            ${lib.dir}/jcip-annotations-1.0.jar;
            ${lib.dir}/junit-4.8.2.jar;
            ${lib.dir}/pmd-4.2.5.jar;
            ${lib.dir}/asm-3.1.jar;
            ${lib.dir}/jaxen-1.1.1
            ${lib.dir}/log4j-java1.1.jar;
            ${lib.dir}/commons-logging-1.1.jar" />

<target name="test" depends="prepare, test-compile, run-tests, finish-errors, finish" />

<target name="prepare"> 

    <delete dir="${test.bin.dir}"/>
    <mkdir dir="${test.bin.dir}" />

</target>


<target name="test-compile" description="Compile Java tests">

    <javac destdir="${bin.dir}" debug="false" optimize="yes" fork="yes" includeantruntime="false" >
        <src refid="test-src-path" />
        <classpath>
            <path refid="test-lib-path" />
            <path refid="run-classpath" />
        </classpath>
    </javac>
</target>

<target name="run-tests" description="Run GUI tests">
    <junit fork="no"  haltonfailure="no" haltonerror="no" errorproperty="test.failed" failureproperty="test.failed" printsummary="no" showoutput="yes">
        <jvmarg value="-Xmx1024m" />


        <classpath>
            <path refid="test-lib-path" />
            <path refid="run-classpath" />
        </classpath>

        <formatter classname="nem.utils.OneLinerFormatter" usefile="false" />
        <formatter type="xml" />

        <test name="nem.AllTests" todir="${test.bin.dir}" />
    </junit>

    <junitreport todir="${local.tests.dir}">
        <fileset dir="${local.tests.dir}" >
            <include name="TEST-*.xml" />
        </fileset>
        <report todir="${local.tests.dir}" format="frames"/>
    </junitreport>
</target>


<target name="finish-errors" if="test.failed">
    <echo>GUI tests failed.  Check logs in workspace for details</echo>
</target>

<target name="finish" unless="test.failed"> 
    <echo>NEM is ok. Is it ...?</echo>
</target>

<path id="run-classpath">
    <pathelement location="${bin.dir}" />
    <path refid="test-lib-path" />
</path>

<path id="test-src-path">
    <pathelement location="${test.src.dir}" />
</path>

<path id="test-lib-path">
    <fileset dir="${lib.dir}">
        <include name="**/*.jar" />
    </fileset>
</path>

<path id="test-run-classpath">
    <pathelement location="${test.bin.dir}" />
    <path refid="test-lib-path" />
</path>

编辑:

好吧,当我说Eclipse中的一切正常时,我说测试是通过使用JUnit(Eclipse集成)开始和运行的。

从命令行运行ant -f .xml时也会出现错误。这是一回事。

这是完整的堆栈跟踪:

prepare:
   [delete] Deleting directory C:\NEMTESTS\bin
    [mkdir] Created dir: C:\NEMTESTS\bin

test-compile:

run-tests:
    [junit] 
    [junit] ----------------------------------------------------------
    [junit] Testsuite: nem.AllTests
    [junit] java.util.MissingResourceException: Can't find bundle for base name mainpackage.rlr14_01.V_45_4_3.view.translation.Translation, locale en_US
    [junit]     at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
    [junit]     at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
    [junit]     at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
    [junit]     at mainpackage.base.view.translator.Translator.createTranslation(Translator.java:125)
    [junit]     at mainpackage.base.view.translator.Translator.<init>(Translator.java:31)
    [junit]     at mainpackage.base.view.translator.TranslatorFactory.getTranslator(TranslatorFactory.java:116)
    [junit]     at mainpackage.base.manager.BsManager.setMibVersion(BsManager.java:1469)
    [junit]     at mainpackage.base.action.ConnectAction.action(ConnectAction.java:314)
    [junit]     at mainpackage.base.action.AbstractAction.run(AbstractAction.java:164)
    [junit]     at java.lang.Thread.run(Thread.java:744)
    [junit] mainpackage.base.view.translator.exception.TranslationException: Cannot load translation for locale en_US and MIB version #R_LR14_01_L#V_45.4.3; will use locale en_US and no MIB version.
    [junit]     at mainpackage.base.view.translator.Translator.createTranslation(Translator.java:163)
    [junit]     at mainpackage.base.view.translator.Translator.<init>(Translator.java:31)
    [junit]     at mainpackage.base.view.translator.TranslatorFactory.getTranslator(TranslatorFactory.java:116)
    [junit]     at mainpackage.base.manager.BsManager.setMibVersion(BsManager.java:1469)
    [junit]     at mainpackage.base.action.ConnectAction.action(ConnectAction.java:314)
    [junit]     at mainpackage.base.action.AbstractAction.run(AbstractAction.java:164)
    [junit]     at java.lang.Thread.run(Thread.java:744)
    [junit] java.util.MissingResourceException: Can't find bundle for base name mainpackage.rlr14_01.V_45_4_3.view.translation.Translation, locale en_US
    [junit]     at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
    [junit]     at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
    [junit]     at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
    [junit]     at mainpackage.base.view.translator.Translator.createTranslation(Translator.java:125)
    [junit]     at mainpackage.base.view.translator.Translator.<init>(Translator.java:31)
    [junit]     at mainpackage.base.view.translator.TranslatorFactory.getTranslator(TranslatorFactory.java:120)
    [junit]     at mainpackage.base.manager.BsManager.setMibVersion(BsManager.java:1469)
    [junit]     at mainpackage.base.action.ConnectAction.action(ConnectAction.java:314)
    [junit]     at mainpackage.base.action.AbstractAction.run(AbstractAction.java:164)
    [junit]     at java.lang.Thread.run(Thread.java:744)
    [junit] Exception in thread "ConnectAction" java.lang.NullPointerException
    [junit]     at mainpackage.base.action.AbstractAction.run(AbstractAction.java:174)
    [junit]     at java.lang.Thread.run(Thread.java:744)
Build was aborted

1 个答案:

答案 0 :(得分:0)

你是对的。这只是一个路径问题。

我昨天遇到了这个问题,使用

ResourceBundle.getBundle(propertyFileName, locale)

我的属性文件位于同一个包中。 您使用哪个命令来读取属性文件?

我通过将属性文件移动到源文件夹来解决它。

因此,如果你有一个com.example.common软件包放在名为“src”的源文件夹中,那么你的文件系统就是... / src / com / example / common。

  1. 在此示例中,您应尝试将propery文件移动到“src”文件夹中。

  2. 如果你有错误:

  3. 您是否使用ant脚本复制属性文件? 我在你的剧本中找不到它。

    也许你需要这样的东西:

    <copy todir="${basedir}/yourDestinationPath">
        <fileset dir="${basedir}/src" includes="*.properties"/>
    </copy>