windows 如何将 java 类添加到 jar 文件中的文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1044243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:42:41  来源:igfitidea点击:

how to add a java class to a folder within a jar file

javawindowsjar

提问by Ian Cohen

using jar on the windows command prompt, how can I add foo.class to a folder "classes" in foo.jar?

在 windows 命令提示符下使用 jar,如何将 foo.class 添加到 foo.jar 中的文件夹“classes”?

I can add the file to the jar using

我可以使用

jar uvf foo.jar foo.class

jar uvf foo.jar foo.class

but that doesn't put the class in the "classes" folder in the jar.

但这并没有将类放在 jar 的“classes”文件夹中。

I know I can use winzip to unzip the jar, add the file, and zip it up again, but that's slow and hopefully unnecessary.

我知道我可以使用 winzip 来解压缩 jar,添加文件,然后再次压缩它,但这很慢,而且可能是不必要的。

回答by Jon Skeet

Put foo.classinto a classesdirectory, then run

foo.class进入一个classes目录,然后运行

jar uvf foo.jar classes/foo.class

(I've just tried it to make sure it works. There maya way of doing it without creating the classesdirectory, but I think this is the simplest solution.)

(我刚刚尝试过以确保它有效。可能有一种方法可以在不创建classes目录的情况下进行,但我认为这是最简单的解决方案。)