英文:
Does a Jar File need .class files to be executable
问题
目前我正在尝试以编程方式生成可执行的JAR文件。
我一直在使用这个线程(https://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file/1281295#=)来生成JAR文件,但到目前为止,它里面装有我测试项目的原始.java文件。
现在我想知道,如果JAR文件只装有这些原始类,是否有可能运行该JAR文件,还是我必须在生成JAR文件之前(以某种方式)将它们编译成.class文件。
谢谢您即将提供的帮助!
英文:
currently I'm trying to generate an executable JAR file programatically.
I've been using this thread (https://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file/1281295#_=_) to generate the JAR file but so far it's packed with the native .java files of my test project.
Now I want to know, if its possible to run the JAR file if its only filled with the native classes
or do I have to (somehow) compile them into .class files before I can generate the JAR file.
Thanks for your upcoming help!
答案1
得分: 1
Jar存档是一个具有特殊文件夹结构的zip存档。这个结构应该包含*.class文件和资源文件。
可选地,源代码也可以在这个存档中,但这不是推荐的做法(最好使用单独的jar文件提供源代码)。
可执行的jar文件是普通的jar文件 + 包含MainClass选项的Manifest.MF文件,其中MainClass选项具有指向包含main()
方法的主类的完整路径(从jar文件的根目录开始)。
英文:
Jar archive is a zip archive with special folder structure. This structure should have *.class files + resource files.
Optionally, sources could be in this archive as well, but this is not reccomended (it's better to provide sources with separate jar file).
Executable jar file is the plain jar file + Manifest.MF where MainClass option exists with a full path (from the root of jar file) to main class with main()
method.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论