没有主方法如何生成jar文件? [英] How to generate jar file with no main method?
问题描述
我正在使用Eclipse编写程序.我有9个课程,并且我使用的是applet,我的代码中没有main方法.
I am using Eclipse to write my program. I have 9 classes and I'm using applet and there is no main method within my codes.
有人告诉我,我需要提交一个可运行的Jar存档,包括源代码".以某种方式,当我尝试使用Eclipse导出"Runnable Jar File"导出程序时,找不到程序的启动配置.在Eclipse中,它运行良好,但我无法导出可运行的Jar文件.
I have been told that I need to submit a "runnable Jar Archive including source code". Somehow when I try to export my program using the Eclipse export "Runnable Jar File", I cannot find the launch configuration of my program. It works perfectly fine within Eclipse but I just can't export a runnable Jar File.
有人可以告诉我是什么问题吗?
Can someone tell me what is the problem please?
肯尼
推荐答案
据我所知,可执行JAR需要一个主要方法.在清单Main-Class标记中,只能声明该主类所在的类(无方法).也许以下代码为您提供了可能的解决方案:
As far as I know an executable JAR needs a main method. In the manifest Main-Class tag only a class can be declared (no method) where the the main-class is located. Maybe the following code is a possible solution for you:
package CaesarCodePackage;
public class StartClass {
public static void main(String [] args)
{
// create an object of type appletclass
AppletClass theApplet = new AppletClass();
theApplet.init(); // invoke the applet's init() method
theApplet.start(); // starts the applet
// If the applet views something (this is optional)
// Create a window (JFrame) and make applet the content pane.
javax.swing.JFrame window = new javax.swing.JFrame("Caesar's Cipher");
window.setContentPane(theApplet);
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
window.pack(); // Arrange the components.
window.setVisible(true); // Make the window visible.
}
}
如果不需要框架来显示小程序,只需启动它即可.
If you do not need a Frame for showing the applet only start it.
(感谢Haider M. al-Khateeb提供的代码)
(Thanks to Haider M. al-Khateeb for the code)
这篇关于没有主方法如何生成jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!