简体   繁体   中英

Ant build fails to mkdir

I'm currently trying to get a private server for an older mmo that no longer serves the US going. I am by no means a Java whiz, but I have been googling and beating my head against a wall for several hours now with no luck. I'm using eclipse for this, have both JDK and JRE installed and paths configured.

The build.xml file:

<?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>

The output from Eclipse after running the Build.xml:

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

I did try manually creating the directories and doing so allows the script to run, but that gives me a "could not find or load main class jp.l1j.server" error when it's run with this start server batch file:

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

Any help would be greatly appreciated!

Don't you need any third party library to compile or run your application ? It seems that your classpath is always empty since you had to create the libs directory by hand. I assume that you do not need any dependencies when building your jar since ant build succeed, but maybe you need some at runtime ?

The fileset nested inside the path with id libs is scanning the directory libs as soon as the pathconvert task is executed. Since pathconvert is outside of any target it is executed before any target .

Besides, I don't see any mkdir for lib.dir anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM