【发布时间】:2011-10-28 09:37:34
【问题描述】:
创建简单的测试java项目只是为了学习如何使用Ant来部署应用程序。 Java 项目使用 Swing 创建 JFrame 和一个 JLabel 来说“Hello World”。它看起来像这样:
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?
怎么了?这似乎是简单直接的过程。我错过了什么吗?
谢谢。
【问题讨论】:
标签: java deployment ant jar