简体   繁体   English

(JAVA)使用命令提示符从多个.class文件创建.jar文件

[英](JAVA) Use Command Prompt to create .jar file from multiple .class files

I have written a .java file, called Main.java, and have compiled it using the javac in the Windows Command Prompt. 我编写了一个名为Main.java的.java文件,并使用Windows命令提示符中的javac编译它。 The compiler is creating multiple .class files (called Main.class, Main$1.class, & Main$2.class--presumably because I have anonymous inner classes in my Main.java file). 编译器正在创建多个.class文件(称为Main.class,Main $ 1.class,&Main $ 2.class - 可能是因为我在Main.java文件中有匿名内部类)。 I am trying to create a runnable .jar file so I can double click a shortcut to run this application (it is a Java Swing application), but I am unsuccessful when I navigate to the directory of the three class files and type: 我正在尝试创建一个可运行的.jar文件,因此我可以双击快捷方式来运行此应用程序(它是一个Java Swing应用程序),但是当我导航到三个类文件的目录并输入时,我不成功:

jar cfv file.jar Main.class Main$1.class Main$2.class

The Command Prompt then outputs this text: 命令提示符然后输出此文本:

added manifest
adding: Main.class(in 4871) (out = 2848)(deflated 41%)
adding: Main$1.class(in 1409) (out = 833)(deflated 40%)
adding: Main$2.class(in 1239) (out = 767)(deflated 38%)

Despite this, when I double click on the file.jar file in Windows Explorer, simply put, nothing happens. 尽管如此,当我在Windows资源管理器中双击file.jar文件时,简单地说,没有任何反应。 No swing application opens. 没有摆动应用程序打开

Hopefully someone can help me out with this. 希望有人可以帮助我解决这个问题。 Thank you 谢谢

Best...SL 最佳... SL

您需要使用入口点开关-e (包含main()方法的类的名称):

jar cfve file.jar Main Main.class Main$1.class Main$2.class

Something's gotta tell the java which class should be started automatically. 有些东西必须告诉java哪个类应该自动启动。 That's the Manifest - see description here You have to package the Manifest.mf in your jar. 这是清单 - 请参阅此处的说明您必须在您的jar中打包Manifest.mf。

  1. Open Command Prompt 打开命令提示符
  2. cd go to the path where jar file exist cd转到jar文件存在的路径
  3. run command jar xf fileName.jar 运行命令jar xf fileName.jar
  4. It will generate com, META-INF & Copyright.mk files 它将生成com, META-INFCopyright.mk文件
  5. Go to the particular package where u want to modify the class file (Basically class files present in com directory) 转到您想要修改类文件的特定包(基本上是com目录中的类文件)
  6. Download the JAD.exe from google (Its Zip File) 从谷歌下载JAD.exe (其Zip文件)
  7. Extract the Zip file you will get jad.exe 解压缩您将获得jad.exe的Zip文件
  8. Place the class file (which u want to modify) in the folder, that contains jad.exe 将类文件(您要修改)放在包含jad.exe的文件夹中
  9. Go to command prompt, run jad fileName.clas s (the class filename which u want to modify) 转到命令提示符,运行jad fileName.clas s(要修改的类文件名)
  10. fileName.jad file will get generate , rename it as fileName.java fileName.jad文件将生成,将其重命名为fileName.java
  11. compile the fileName.java (if its referring to some other class file configure it in eclipse accordingly) 编译fileName.java (如果它引用其他类文件,则相应地在eclipse中配置它)
  12. once compiled replace the class file in the directory defined in step 4 编译后,替换步骤4中定义的目录中的类文件
  13. Go to command prompt, cd Step 4 path, run jar cf fileName.jar (* represents all the class files irrespective of directories) 转到命令提示符,cd步骤4路径,运行jar cf fileName.jar (*代表所有类文件而不管目录)
  1. open cmd (windows+r type cmd) open cmd(windows + r type cmd)
  2. simipily type command as a "jar" without quatoes simipily类型命令为没有quatoes的“jar”
  3. it will give some options and those usage. 它会给出一些选择和那些用法。
  4. use what you want 用你想要的
  5. to create a jar file with class you to mention jar cfv filename.jar example.class example2.class etc.. 用class创建一个jar文件你要提到jar cfv filename.jar example.class example2.class等。
  6. IF your using swing compile it with javac -deprecation SwingApplication.java but JDK version must be greater than version JDK1.1 如果您使用swing使用javac -deprecation SwingApplication.java编译它,但JDK版本必须大于版本JDK1.1
  7. run java SwingApplication 运行java SwingApplication
  8. ALL THE BEst 祝一切顺利

暂无
暂无

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

相关问题 从Java执行命令提示符的命令以创建jar文件 - Execute command prompt's command from java to create jar file 如何在命令提示符下将jar文件与Java中的另一个jar文件一起使用 - How to use a jar file in conjunction with another in Java from the command prompt 通过命令提示符从具有多个JAR依赖项的JAR运行类 - Running class from JAR with multiple JAR dependencies via command prompt 如何在命令提示符下运行依赖于YahooFinance jar文件的多个.java文件 - How to run multiple .java files with dependency to YahooFinance jar file in Command Prompt 如何在java文件中包含jar文件并在命令提示符下编译 - How to include jar files with java file and compile in command prompt 如何从命令提示符将 jar 反编译为 .java 文件 - How to decompile a jar into .java files from command prompt 如何在命令提示符下的不同位置运行多个JAR文件 - How to run multiple JAR files at differnt locations from a command prompt 无法从命令提示符下引用类路径中的jar运行Java类 - unable to run java class from command prompt refering to a jar in classpath 使用从java程序调用的Windows命令提示符,将带有多个连续空格的字符串作为参数传递给jar文件 - Pass a string with multiple contiguous spaces as a parameter to a jar file using Windows command prompt called from a java program 从命令提示符执行具有多个类路径库的jar文件 - Execute jar file with multiple classpath libraries from command prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM