从 Ant 创建的可执行 jar 文件不起作用



我正在尝试使用 Ant 创建一个可执行(双击)jar。我的课程是ChatClient和ChatServer,这是一个简单的多线程聊天服务器。在阅读教程后,我已经创建了build.xml但这里似乎有问题。我得到的错误是,错误:找不到或加载主类 C:...(JAR 文件的路径)

我的项目名称是JamesPractice,包名称是SimpleChat。类是SimpleChatServer和SimpleChatClient

<?xml version="1.0"?>
<project name = "JamesPractice" default= "jar" basedir =".">
<property name = "src.dir" location = "src" />
<property name = "build.dir" location = "c:Build" />
<property name = "project.name" value = "JamesPractice" />
<property name="lib.dir" location="lib" />
<target name = "clean">
    <delete dir="${build.dir}" />
</target>
<target name = "makedir">
    <mkdir dir= "${build.dir}" />
    <mkdir dir= "${build.dir}classes" />
</target>
<target name = "compile" depends = "clean, makedir">
    <javac srcdir = "${src.dir}" destdir = "${build.dir}classes" />
</target>
<target name = "jar" depends = "compile">
    <jar destfile = "${build.dir}/jars/${ant.project.name}.jar" basedir = "${build.dir}/classes" />
    <manifest file = "MANIFEST.MF">
        <attribute name = "Main-Class" value = "SimpleChat.SimpleChatServer"/>
        <attribute name = "Class-Path" value = "."/>
    </manifest>
</target>

MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.2
Created-By: 1.7.0_11-b21 (Oracle Corporation)
Main-Class: SimpleChat.SimpleChatClient

已编辑我已经合并了两个类,它工作正常。但是.jar仍然给了我同样的错误。去测试HelloWorld,看看我是否可以让它工作......

将"清单"部分移动到 ...标签:

<target name = "jar" depends = "compile">
    <jar destfile = "${build.dir}/jars/${ant.project.name}.jar" basedir = "${build.dir}/classes">
        <manifest file = "MANIFEST.MF">
            <attribute name = "Main-Class" value = "SimpleChat.SimpleChatServer"/>
            <attribute name = "Class-Path" value = "."/>
        </manifest>
    </jar>
</target>
最好

使用Maven而不是老式的Ant.Maven在几年前成为行业标准。

相关内容

  • 没有找到相关文章

最新更新