简体   繁体   English

如何将jar中的java文件编译为字节码(*.class文件)

[英]How to compile java files in jar to byte code (*.class file)

如何将jar文件中的java文件编译为字节码(*.class文件)?

A jar file is just an archive. jar 文件只是一个存档。 You have to extract the java source files in order to compile them.您必须提取 java 源文件才能编译它们。

Since a jar is an archive of java-related files and perhaps metadata, they can really hold just about anything.由于jar是与 Java 相关的文件和元数据的存档,因此它们实际上可以保存任何内容。 They are just zip archives with a different name.它们只是具有不同名称的 zip 档案。 Typically you find "regular" jar's (containing .class files) and source jar's (containing .java files).通常,您会找到“常规”jar(包含 .class 文件)和源 jar(包含 .java 文件)。

It sounds like you might have a source jar and you need the regular jar that contains the compiled classes.听起来您可能有一个源 jar,并且您需要包含已编译类的常规 jar。 If this is a jar you've downloaded from someplace, perhaps you should look for it's compiled counterpart.如果这是您从某个地方下载的 jar,也许您应该寻找它的编译副本。 If this is a jar that you've built yourself, then you skipped the compile step and built yourself a source-jar.如果这是您自己构建的 jar,那么您就跳过了编译步骤并自己构建了一个 source-jar。

If it is none of the above, then, like others have pointed out, unzip it and compile the classes.如果以上都不是,那么就像其他人指出的那样,解压缩它并编译类。 Just know that there may be other hurdles involved when it comes to satisfying all the jar's dependencies.只要知道在满足所有 jar 的依赖项时可能还涉及其他障碍。 Unless, it came with a pom for you to use or reference.除非,它带有一个pom供您使用或参考。

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

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