如何创建具有包结构的jar文件? [英] How to create jar file with package structure?

查看:19
本文介绍了如何创建具有包结构的jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹结构

/com/cdy/ws/a.class files
/com/cdy/ws/b.class files
/com/cdy/ws/c.class files

当我运行以下命令jar cvf asd.jar *.class"时,它会提供包含所有类文件的 jar.但是文件夹结构没有生成.所有的类文件都必须在com.cdy/ws"下,但所有的类都在 META-INF 的同一级别.谁能告诉我生成包结构的命令是什么?

When I run the following command "jar cvf asd.jar *.class" it gives jar with all the class files. But the folder structure is not getting generated. All the class files have to be under "com.cdy/ws" but all the classes are in same level of META-INF. Can anyone tell me what is the command to generate the package structure?

谢谢

推荐答案

您需要在文件的开始创建 JAR.

You need to start creating the JAR at the root of the files.

例如:

jar cvf program.jar -C path/to/classes .

假设 path/to/classes 包含 com 目录.

That assumes that path/to/classes contains the com directory.

仅供参考,现在大多数人直接使用 jar 命令相对不常见,因为他们将使用诸如 AntMaven 来处理这个(和其他构建的各个方面).让这些工具中的一个来处理构建的所有方面是非常值得的,而且使用好的 IDE 来帮助编写 build.xml (Ant) 或 pom.xml (Maven).

FYI, these days it is relatively uncommon for most people to use the jar command directly, as they will use a build tool such as Ant or Maven to take care of that (and other aspects of the build). It is well worth the effort of allowing one of those tools to take care of all aspects of your build, and it's even easier with a good IDE to help write the build.xml (Ant) or pom.xml (Maven).

这篇关于如何创建具有包结构的jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆