简体   繁体   English

从命令行创建JAR文件不起作用

[英]Creating a JAR File from the Command Line Doesn't Work

I've edited this question, and now it is exactly what I did: 我已经编辑了这个问题,现在正是我所做的:

I want to create a .jar file from some .class files in the command line. 我想从命令行中的某些.class文件创建一个.jar文件。

I worked on Eclipse, and created: 我在Eclipse上工作,并创建了:

myProject project, and in it: myPackage package, and in it: myClass class. myProject项目及其中:myPackage包,及其中:myClass类。 Then I wrote in the command line: 然后我在命令行中写道:

jar -cfv myJar.jar  myPackage\myClass.class

And I got this: 我得到了:

added manifest
adding: myPackage/myClass.class(in = 745) (out= 473)(deflated 36%)

This really created the myJar.jar file in my current directory. 这确实在当前目录中创建了myJar.jar文件。 Now, I wanted to check if the process was done successfully, so I extracted the class from the jar thus: 现在,我想检查该过程是否成功完成,因此我从jar中提取了该类:

jar xfv myJar.jar

And I got this: 我得到了:

  created: META-INF/
 inflated: META-INF/MANIFEST.MF
 inflated: myPackage/myClass.class

And this created for me just the META-INF folder, with the MANIFEST.MF in it, but I don't see any .class file here!! 这为我创建的只是META-INF文件夹,其中包含MANIFEST.MF,但我在这里看不到任何.class文件!

It seems like something in the packing to jar process is incorrect. 似乎打包到jar过程中有些错误。

Anybody has an idea?? 有人有主意吗?

Any answer is appreciated! 任何答案表示赞赏!

According to the output you gave, there is no myClass.class file in the directory where you execute 根据您提供的输出,您执行的目录中没有myClass.class文件

jar -cf myJar.jar myClass.class

So obviously, the command can't add it to the jar: it doesn't exist. 因此很明显,该命令无法将其添加到jar中:它不存在。 If you want to add the myClass directory, recursively, to the jar file, then use 如果要递归将myClass目录添加到jar文件中,请使用

jar -cf myJar.jar myClass

EDIT: 编辑:

Just look at the output: 只看输出:

 inflated: myPackage/myClass.class

The myClass.class file is there in the jar file. jar文件中存在myClass.class文件。 There is no problem at all. 完全没有问题。

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

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