简体   繁体   English

如何制作可运行的.jar文件?

[英]How to make a runnable .jar file?

for school i have to make a game, together with 2 classmates. 为了上学,我必须和两名同学一起做游戏。 our group had to make something in Java, a language we never used before. 我们的小组不得不用Java编写某种东西,这是我们以前从未使用过的语言。 we got ourselfs a little game now, but we can't seem to get it into a working .jar file nor a runnable jar. 我们现在有一个小游戏,但似乎无法将其放入工作的.jar文件或可运行的jar中。 We use eclipse, but the .jar file created through export => jar file doesn't work. 我们使用eclipse,但是通过export => jar文件创建的.jar文件不起作用。 it doesn't do anything. 它什么也没做。 (manifest file is totally empty) the runnable jar file is even worse, it says there is no main class selected, but when i try to set 'Main.class' as main class, then it's not in the list. (清单文件完全为空),可运行的jar文件甚至更糟,它说没有选择主类,但是当我尝试将'Main.class'设置为主类时,它不在列表中。 (at advanced options for creating a runnable jar in Eclipse) i tried through cmd too, but then it couldn't find a manifest attribute... any help? (在Eclipse中创建可运行jar的高级选项)我也尝试了cmd,但是后来找不到清单属性...有什么帮助吗? my maps: -Smash'em All -.settings - bin -data (all my images and such) -Smash (all the .class files) -java.policy.applet - src -data (some old pictures, not the same as in the other data map) -Smash (all the .java files) - .classpath - .project 我的地图:-Smash'em全部-.settings-bin -data(所有我的图像等)-Smash(所有.class文件)-java.policy.applet-src -data(一些旧图片,与在另一个数据图中)-粉碎(所有.java文件)-.classpath-.project

any idea how to make a runnable jar? 任何想法如何制作一个可运行的罐子? and if i want to implement it in HTML, do i need a runnable or just a .jar file? 如果我想用HTML来实现它,我需要一个可运行文件还是仅一个.jar文件? EDIT: my lay-out doesn't seem saved? 编辑:我的布局似乎没有保存? :( sorry, is my first post ever herer :( :(对不起,这是我的第一篇文章herer :(

如果要使用“ java -jar”运行,则需要在JAR清单中指定主类。

要使用java -jar命令运行jar,或双击您需要指示要运行的主类的jar,可以通过在jar的META-INF / Manifest.MF中添加Main-Class来进行操作 。可以看到如何设置主类

To add to Césars' comment, have you tried: 要添加到Césars的评论中,您是否尝试过:

jar cvf YourApplication.jar *.class

From " Java How to Program " : 从“ Java How to Program ”中:

That should jar up your classes which creates in the current directory a JAR file named YourApplication.jar containing the applet's .class files. 那应该震撼您的类,这些类会在当前目录中创建一个名为YourApplication.jar的JAR文件,其中包含小程序的.class文件。 If the program had other resources, you'd simply add the file names or the folder names in which those resources are stored to the end of the preceding command. 如果程序具有其他资源,则只需将存储这些资源的文件名或文件夹名添加到上一个命令的末尾。 The letters cvf are command-line options to the jar command. 字母cvf是jar命令的命令行选项。 The c option indicates that the command should create a new JAR file. c选项指示该命令应创建一个新的JAR文件。 The v option indicates that the command should produce verbose output so you can see the list of files and directories being included in the JAR file. v选项指示命令应产生详细输出,因此您可以查看JAR文件中包含的文件和目录的列表。 The f option indicates that the next argument in the command line (YourApplication.jar) is the new JAR file's name. f选项指示命令行中的下一个参数(YourApplication.jar)是新的JAR文件的名称。

As per one of your questions, you asked "if i want to implement it in HTML, do i need a runnable or just a .jar file". 根据您的问题之一,您问“如果要在HTML中实现它,我需要一个可运行文件还是仅一个.jar文件”。 No, you can just run the class file, if you want. 不,您可以根据需要运行类文件。

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <applet code = "YourApplication.class" width = "300" height = "45">
        </applet>
    </body>
</html>

you can make use of exe4j tool, which takes your classes in jar and produce exe for you. 您可以使用exe4j工具,该工具将您的类放在jar中并为您生成exe。 try this http://www.ej-technologies.com/products/exe4j/overview.html 试试这个http://www.ej-technologies.com/products/exe4j/overview.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM