简体   繁体   English

Netbeans,Java,创建jar

[英]Netbeans, java, creating jar

I originally had one project with just one class (called GetData) that worked well, and it had a main() method in it. 我最初只有一个项目,只有一个类(称为GetData)运行良好,并且其中包含main()方法。 Now, I got rid of the main method because I have to use this project as a library, and no matter what I do (yes, I went into properties), it won't generate a jar file that I can use! 现在,我摆脱了主要方法,因为我必须将此项目用作库,并且无论我做什么(是的,我进入属性),它都不会生成我可以使用的jar文件! Is there a special way to do this? 有一种特殊的方法吗? Also, I recently got Mercurial revision support on this project, so that might be a reason. 另外,我最近对此项目获得了Mercurial修订支持,所以这可能是一个原因。

EDIT: I get "Finished building PROJECTNAME(clean, jar)" in the lower left hand corner when I do a clean build. 编辑:当我进行干净的构建时,我会在左下角看到“完成的建筑物PROJECTNAME(clean,jar)”。

I am going to assume that your project is called DataGetter. 我将假设您的项目名为DataGetter。 You created the project by doing the following... 您通过执行以下操作创建了项目...

File->New Project and selected Categories: Java and Projects: Java Application on the New Projects dialog. 在“新建项目”对话框中,选择“文件”->“新建项目”,然后选择“类别:Java和项目:Java应用程序”。

You have the Projects explorer open and it shows your project (DataGetter). 您已打开“项目”资源管理器,它显示了您的项目(DataGetter)。

Select the Files item from the Window menu (control-2/clover-2 [on mac]). 从“窗口”菜单中选择“文件”项(control-2 / clover-2 [在Mac上])。

A new explorer window will be displayed, titled Files. 将显示一个新的资源管理器窗口,标题为“文件”。

You will see a 'node' labelled DataGetter, sort of like the node on the Projects explorer... but it has a different icon. 您将看到一个标记为DataGetter的“节点”,有点像Projects资源管理器中的节点...,但是它有一个不同的图标。

Expand that node and you will see a folder node labelled 'dist'. 展开该节点,您将看到一个标记为“ dist”的文件夹节点。 Expand that node to see your jar file, DataGetter.jar. 展开该节点以查看您的jar文件DataGetter.jar。

BONUS ANSWER: 奖励答案:

If you are writing the application that will use this jar in NetBeans, you can make the DataGetter project a Library of the Application that you are developing. 如果您正在编写将在NetBeans中使用此jar的应用程序,则可以使DataGetter项目成为正在开发的应用程序的库。 Look for a node labelled Libraries underneath your new Application project's node in the Projects explorer window. 在“项目”资源管理器窗口中,在新的“应用程序”项目的节点下寻找一个标有“库”的节点。

If you want to have a jar that you can click and run you need a main method somewhere for it run. 如果您想要一个可以单击并运行的jar,则需要在某个地方运行main方法。 Library or not. 图书馆与否。

Are you getting an error message when you try to build it? 当您尝试构建它时,是否收到错误消息? Make sure there's nothing in main that if taken out would prevent it from compiling. 确保main中没有任何东西如果被取出会阻止其编译。

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

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