应用程序可以在Netbeans上编译和构建

应用程序可以在Netbeans上编译和构建

本文介绍了应用程序可以在Netbeans上编译和构建,但不能作为独立的jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您的应用程序是否有可能在Netbeans中完美地编译和构建,但是当您在Netbeans之外构建并运行它时,会出现异常堆?? (请记住,所有库和依赖项都随实际的jar文件一起移植).

我运行followingng命令

ant -f运行

我的程序可以正常运行,但是,在这里我运行以下命令来实际构建一个jar文件,

ant -f jar

,当我运行jar文件时,我的应用程序会运行,但不会执行使用第一个命令启动它时执行的任务.

任何想法为何会发生这种情况?!!我完全迷失了这种行为,找不到原因!

解决方案

您如何尝试在NetBeans之外构建项目?

在NetBeans内部,如果您是从NetBeans内部创建项目的,我相信NetBeans大多数情况下都会在名为nbbuild.xml的文件中创建其所有(默认情况下)Ant目标.

因此,如果您试图从命令行在NetBeans外部编译项目(无论系统中是否存在该项目),则需要对ant程序使用-f nbbuild.xml自变量来使用NetBeans生成的Ant文件.因此您的命令行可能如下所示:

ant -f nbbuild.xml compile

在上面的示例中,当然要替换您希望为compile运行的目标.

Is it possible that your application compiles and builds flawlessly in Netbeans but when you build it and run it outside of Netbeans you get heaps of Exceptions??! (keeping in mind that the all the libraries and dependencies are ported along with the actual jar file).

I run the followng command

ant -f run

and my program runs flawlessly as it's supposed to, however, where I run the following command to actually build a jar file,

ant -f jar

and when I run the jar file, my application runs but does not perform the tasks it does when it is launched using the first command.

Any ideas why this is happening??! I'm totally lost with this behaviour and can't find why!

解决方案

How are you attempting to build your project outside of NetBeans?

Inside NetBeans, if you created the project from within NetBeans, I believe that most of the time NetBeans will create all of its (by default) Ant targets in a file called nbbuild.xml.

Thus, if you're attempting to compile your project outside NetBeans from the command-line (however it exists on your system), you would then need to use the -f nbbuild.xml argument to the ant program to use the NetBeans-generated Ant file. So your command-line might look like this:

ant -f nbbuild.xml compile

Substitute, of course, the target you desire to run for compile in the example above.

这篇关于应用程序可以在Netbeans上编译和构建,但不能作为独立的jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:59