Java 使用 Netbeans 导出 JAR
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4498047/
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
Export JAR with Netbeans
提问by Damir
How to export java project to JAR with Netbeans ? I cannot find options like in Eclipse.
如何使用 Netbeans 将 java 项目导出到 JAR?我找不到像 Eclipse 这样的选项。
采纳答案by a_horse_with_no_name
You need to enable the option
您需要启用该选项
Project Properties -> Build -> Packaging -> Build JAR after compiling
Project Properties -> Build -> Packaging -> Build JAR after compiling
(but this is enabled by default)
(但这是默认启用的)
回答by Sergei Tachenov
Do you mean compileit to JAR? NetBeans does that automatically, just do "clean and build" and look in the "dist" subdirectory of your project. There will be the JAR with "lib" folder containing the required libraries. These JAR + lib are enough to run the application.
你的意思是编译成JAR?NetBeans 会自动执行此操作,只需执行“clean and build”并查看项目的“dist”子目录即可。将有包含所需库的带有“lib”文件夹的 JAR。这些 JAR + lib 足以运行应用程序。
If you disable "Compile on save" in the project properties, then it is no longer necessary to do "clean and build", simply "build" will suffice in most cases. This will save time if you want to change just a bit of the code and rebuild the JAR. However, note that NetBeans sometimes fails to handle dependencies and binary compatibility properly, which will lead to a faulty JAR throwing "no such method" or other obscure exceptions. Therefore, if you made a lot of changes since the last full rebuild and even remotely unsure that it will still work even if some classes aren't recompiled, then you must still do a full "clean and build" in order to get a perfectly working JAR.
如果您在项目属性中禁用“保存时编译”,则不再需要执行“清理和构建”,在大多数情况下只需“构建”就足够了。如果您只想更改一点代码并重新构建 JAR,这将节省时间。但是,请注意,NetBeans 有时无法正确处理依赖项和二进制兼容性,这将导致错误的 JAR 抛出“无此类方法”或其他模糊的异常。因此,如果您自上次完全重建以来做了很多更改,甚至不确定即使某些类没有重新编译它仍然可以工作,那么您仍然必须进行完全“清理和构建”以获得完美的工作 JAR。
回答by Jonas Van der Aa
It does this by default, you just need to look into the project's /dist
folder.
它默认执行此操作,您只需要查看项目的/dist
文件夹。
回答by Rupsingh
- Right click your project folder.
- Select Properties.
- Expand Build option.
- Select Packaging.
- Now Clean and Build your project (Shift +F11).
- jar file will be created at your_project_folder\dist folder.
- 右键单击您的项目文件夹。
- 选择属性。
- 展开构建选项。
- 选择包装。
- 现在清理并构建您的项目(Shift + F11)。
- jar 文件将在 your_project_folder\dist 文件夹中创建。