同时建立可运行罐子蚂蚁卡住 [英] Ant gets stuck while building runnable jar

查看:107
本文介绍了同时建立可运行罐子蚂蚁卡住的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这又是我。
我一直在试图创建Java项目导入使用Ant脚本运行的JAR。
这是我的build.xml

it's me again. I've been trying to create java project into a runnable jar using ant script. This is my build.xml

<project name="simple-app" basedir="." default="main">
    <property name="src.dir" value="src" />
    <property name="build.dir" value="build" />
    <property name="classes.dir" value="${build.dir}/classes" />
    <property name="jar.dir" value="${build.dir}/jar" />
    <property name="lib.dir" value="lib" />
    <property name="main-class" value="app.App" />

    <path id="classpath">
    <fileset dir="${lib.dir}">
        <include name="*.jar" />
    </fileset>
            <dirset dir="${build.dir}">
            <include name="classes"/>
    </dirset>
</path>

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

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac source="1.7" target="1.7" includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" />
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}" />
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="*.class">
        <manifest>
            <attribute name="Main-Class" value="${main-class}" />
        </manifest>
    </jar>
</target>


<target name="run" depends="jar">
    <java classname="${main-class}">
        <classpath>
            <path refid="classpath" />
            <path location="${jar.dir}/${ant.project.name}.jar" />
        </classpath>
    </java>
</target>

<target name="main" depends="clean,run"/>
</project>

一切顺利,但是当它到达跑,它卡住。终端运行说:并没有任何反应。等了30分钟,什么都没有。我想,我发现在互联网附近许多其他的选择,但这些要么导致在相同的滞后,或扔了ClassNotFoundException。

All goes well, but when it gets to "run" it gets stuck. Terminal says run: and nothing happens. Waited for 30 minutes, nothing. I tried many other options I found around the internet but those resulted either in the same lag, or threw ClassNotFoundException.

我严重不知道是什么,做的。当我做与Eclipse的文件,一切工作正常。任何人都可以帮我吗?这是propably一些完全愚蠢的,但我没有看到它。
非常感谢你。

I seriously don't know what, to do. When I make the file with Eclipse, all works fine. Anyone can help me? It's propably something totally stupid, but I just don't see it. Thank you very much.

推荐答案

要解决,你需要在JAR的清单类路径中的ClassNotFoundException例外。该 manifestclasspath 任务进来非常有用的:

To fix the ClassNotFoundException exception you need to include the classpath in the jar's manifest. The manifestclasspath task comes in very useful:

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}" />

    <manifestclasspath property="jar-classpath" jarfile="${jar.dir}/${ant.project.name}.jar">
      <classpath refid="classpath" />
    </manifestclasspath>

    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="*.class">
        <manifest>
            <attribute name="Main-Class" value="${main-class}" />
            <attribute name="Class-Path" value="${jar-classpath}" />
        </manifest>
    </jar>
</target>

这使您可以调用的jar如下:

This enables you to invoke the jar as follows:

<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>

或命令行:

java -jar /path/to/myproject.jar

在最后,这可能无法解释为什么您的构建是挂....是否有可能在code为进入等待状态?

In the end this may not explain why your build is hanging.... Is it possible the code is going into a waiting state?

这篇关于同时建立可运行罐子蚂蚁卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆