Ant构建失败了mkdir

时间:2016-02-12 00:14:52

标签: java xml eclipse ant

我目前正在尝试为不再为美国服务的旧mmo获取私人服务器。我绝不是一个Java高手,但是我一直在谷歌上搜索并且在墙上撞了几个小时而没有运气。我为此使用了eclipse,安装了JDK和JRE并配置了路径。

build.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name="L1J" default="all" basedir=".">
<description>
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see http://www.gnu.org/licenses/
</description>

<!-- Set Property -->
<property name="src.dir" value="src" />
<property name="lib.dir" value="libs" />
<property name="build.dir" value="build" />
<property name="main.class" value="jp.l1j.Server" />
<property name="jarfile" value="l1jserver.jar" />

<path id="libs">
    <fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<pathconvert property="classpath" refid="libs" targetos="windows"  pathsep=" ">
    <map from="${basedir}\${lib.dir}\" to="./${lib.dir}/"/>
    <map from="\" to="/"/>
</pathconvert>

<!-- Set DefaultTarget -->
<target name="all" depends="clean,compile,jar,clean2" />

<!-- clean Target -->
<target name="clean">
    <delete dir="${build.dir}" />
</target>

<!-- Compile Target -->
<target name="compile">
    <mkdir dir="${build.dir}" />
    <javac includeantruntime="true" srcdir="${src.dir}"
        destdir="${build.dir}"
        optimize="on"
        debug="on"
        encoding="UTF-8">
        <classpath refid="libs" />
        <compilerarg value="-Xlint:unchecked" />
    </javac>
</target>

<!-- jar Target -->
<target name="jar">
    <jar jarfile="${jarfile}" basedir="${build.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main.class}" />
            <attribute name="Class-Path" value="${classpath}" />
        </manifest>
    </jar>
</target>

<!-- clean Target -->
<target name="clean2">
    <delete dir="${build.dir}" />
</target>

</project>

运行Build.xml后Eclipse的输出:

Buildfile: C:\Users\Administrator\workspace\L1J\build.xml

BUILD FAILED
C:\Users\Administrator\workspace\L1J\build.xml:28: C:\Users\Administrator\workspace\L1J\libs does not exist.

Total time: 390 milliseconds

我确实尝试手动创建目录,这样做允许脚本运行,但是这给了我一个&#34;无法找到或加载主类jp.l1j.server&#34;使用此启动服务器批处理文件运行时出错:

@java -server -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -Xms1024m -Xmx1024m -XX:NewRatio=2 -XX:SurvivorRatio=8  -jar l1jserver
@pause

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

您是否需要任何第三方库来编译或运行您的应用程序? 您的类路径似乎总是空的,因为您必须手动创建libs目录。我认为在构建jar时你不需要任何依赖,因为ant build成功了,但是你可能需要在运行时使用它们吗?

答案 1 :(得分:0)

fileset嵌套在具有id libs的path内,一旦pathconvert任务执行,就会扫描目录库。由于pathconvert超出任何target,因此会在任何target之前执行。

此外,无论如何,我都看不到mkdir lib.dir