Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 蚂蚁部署。罐子罐';我找不到主课_Java_Deployment_Ant_Jar - Fatal编程技术网

Java 蚂蚁部署。罐子罐';我找不到主课

Java 蚂蚁部署。罐子罐';我找不到主课,java,deployment,ant,jar,Java,Deployment,Ant,Jar,创建简单的测试java项目只是为了学习如何使用Ant部署应用程序。 Java项目使用Swing创建JFrame和一个JLabel来表示“HelloWorld”。看起来是这样的: package com.mytest; import javax.swing.*; public class home { private static void createAndShowGUI() { JFrame frame = new JFrame("HelloWorld

创建简单的测试java项目只是为了学习如何使用Ant部署应用程序。 Java项目使用Swing创建JFrame和一个JLabel来表示“HelloWorld”。看起来是这样的:

package com.mytest;
import javax.swing.*;        

public class home {
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);
        frame.pack();
        frame.setVisible(true);
    }
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
然后我创建了build.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project default="mytest" basedir=".">
  <target name ="mytest" description="Create a jar for the Test project">
    <echo message="starting MyTest jar creation..." />
    <jar jarfile="mytest.jar" includes="*.class" basedir="bin">
        <manifest>
            <attribute name="Created-By" value="1.6.0_04 (Sun Microsystems Inc.)" />
            <attribute name="Built-By" value="Me" />
            <attribute name="Implementation-Version" value="1.0" />
            <attribute name="Main-Class" value="com.mytest.home" />
        </manifest>
    </jar>
    <echo message="MyTest jar created..." />
  </target>
</project>

问题是,一旦我通过Eclipse运行部署,jar就被创建了,但我无法启动它。我收到消息:找不到主类:com.mytest.home

怎么了?这似乎是一个简单的直接过程。我错过什么了吗


谢谢。

我在您的ant脚本中找不到编译任务。如果没有编译任务,类文件是如何生成的


另外,只要解压缩jar文件,看看这个类是否真的存在?

我对所有这些有点困惑。据我所知,Eclipse正在运行中构建项目,当您键入时,当您决定部署时,您的部署脚本只需要按照脚本中指定的方式打包所有内容。它基本上是将项目中的类文件复制到jar文件中

对于我的特定问题,我发现缺少元素,它是元素的子元素,因此我的xml脚本现在看起来如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project default="mytest" basedir=".">
  <target name ="mytest" description="Create a jar for the Test project">
    <echo message="starting MyTest jar creation..." />
    <jar jarfile="mytest.jar" includes="*.class" basedir=".">
        <fileset dir="./bin" />
        <manifest>
            <attribute name="Created-By" value="..." />
            <attribute name="Built-By" value="Me" />
            <attribute name="Implementation-Version" value="1.0" />
            <attribute name="Main-Class" value="com.mytest.home" />
        </manifest>
    </jar>
    <echo message="MyTest jar created..." />
  </target>
</project>


我试着运行jar文件,它成功了。

我不确定编译任务是什么?我已经查看了几个帮助网站,包括Eclipse中的一个,我没有看到任何关于编译任务的内容。我将项目(属性>生成器)设置为在手动生成上运行部署任务。我得到消息构建成功,但我打开了jar,它是空的。如何指定编译任务?我的意思是,我知道什么是编译任务,但不知道如何做。我还研究了一些旧项目中现有的deployment.xml。应用程序部署很好,但我在XML文件中找不到任何编译任务…请查看以下链接。您需要有一个javac任务来将java文件编译到一个临时文件夹中。只有你才能把它们捆在罐子里。还有一个建议,如果您是ant新手,那么手动创建MANIFEST.MF文件并将其包含在jar中会更容易。这将使您的生活更轻松。您需要依靠eclipse来编译代码。我会说在ant脚本中放置一个javac任务。否则你迟早会遇到问题。