仅使用 ant 运行 NetBeans 项目
我有一个使用 Netbeans 构建的示例代码。
它有一个 build.xml 文件,所以我下载了 ant 并尝试运行它。
我收到此错误消息:
...... nbproject\build-impl.xml:76: Platform is not correctly set up
据我所知,这可以通过“简单地”下载 Netbeans 并从那里运行示例来修复,但是...我不想安装它来运行 10 个文件的示例。
是否有使用 Java 运行 Netbeans 项目的解决方法? 我必须修改的正确 .properties 文件是什么?
I have a sample code that was built with Netbeans.
It has a build.xml file so I downloaded ant and try to run it.
I've got this error message:
...... nbproject\build-impl.xml:76: Platform is not correctly set up
For what I can see, this is fixed by "simply" downloading Netbeans and running the sample from there, but... I don't want to install it to run a 10 files sample.
Is there a workaround to run Netbeans projects with Java? What's the correct .properties file I have to modify?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只是添加到Mads的答案......通常,您需要在目标计算机上至少安装并打开一次 Netbeans。 ANT 项目还依赖于 USERDIR/.netbeans/... 目录中的一些设置。 这可能在 6.5+ 中发生了变化。
这将配置一些基本设置并定义 netbeans jar 的类路径。 如果自上次在 Netbeans 中打开项目以来您的依赖项(即库)或项目正在从不同的目录运行,则您将需要按照 Mads 的描述调整 private.properties 文件中的一些设置。
Just to add to Mads' answer... usually, you need to install and open Netbeans at least once on the target machine. The ANT projects also rely on a few settings from the USERDIR/.netbeans/... directory. This may have changed with 6.5+.
This will get some of the base settings configured and define the classpath's to netbeans jars. If your dependencies (i.e. libraries) or project is being run from a different directory since the last time you opened the project in Netbeans, you will need to tweak a few settings in the private.properties file as Mads' described.
我正在使用 Netbeans 6.8,并且使用 Netbeans 创建的 java 项目可以通过 Netbeans 自动生成的构建文件运行,只需在 cli 上使用 ant 即可。 所有常规目标,如
antcompile
、antrun
、antclean
等“都可以工作”。 (如果重要的话我正在使用 Fedora 13)I'm using Netbeans 6.8 and java projects that were created with Netbeans can be run from the Netbeans auto generated build files with just ant on the cli. All the regular targets like
ant compile
,ant run
,ant clean
, etc "just work". (I'm using Fedora 13 if that matters)您可以仅使用此存储库https://github.com/albfan/ant-netbeans
它克服了 netbeans 包装的 ant 配置的所有奇怪之处,所以你只需要:
编译:
运行:
到任何(自动完成):
You can use this repo just for that https://github.com/albfan/ant-netbeans
It overcomes all the oddities of netbeans wrapped ant config so you just need:
To compile:
To run:
To whatever (autocompletion):
可以直接从 Java/ANT 运行 NetBeans 生成的项目,但您可能需要手动设置一些属性和/或添加 jar 文件的路径。
不幸的是,NetBeans 倾向于使用自己的 JAR 文件和引用属性来包含任务定义,这些属性仅在
/nbproject/private/private.properties
文件中定义,这些属性通常在您第一次打开 NetBeans 项目或当您在 IDE 中编辑项目时进行修改。如果您检查
build-impl.xml
,您应该能够找到该属性并导出需要设置的值(操作系统平台),然后:/nbproject/private.properties
父
build.xml
使用
-DPlatform=Foo
进行目标就我个人而言,我喜欢 NetBeans 生成的 ANT 文件和目标的结构,但讨厌它们中塞满了多少自定义/专有的东西,这使得没有 NetBeans 就很难运行。
例如:
It is possible to run the NetBeans generated projects straight from Java/ANT, but you may need to manually set some of the properties and/or add paths to jar files.
Unfortunately, NetBeans tends to include taskdef's using their own JAR files and reference properties that are defined only in the
/nbproject/private/private.properties
files, which usually get set when you first open the NetBeans project or modified as you edit the project in the IDE.If you inspect the
build-impl.xml
you should be able to find the property and derive what value needs to be set(OS platform), then either:/nbproject/private.properties
parent
build.xml
target using
-DPlatform=Foo
Personally, I like the structure of the NetBeans generated ANT files and targets, but hate how much custom/proprietary stuff they jam in that makes it hard to run without NetBeans.
For example:
我刚刚用 ant 成功构建了 NetBeans 项目。 这些是我必须做的事情:
/java2/ant 复制到“Netbeanless”机器
.home=<平台路径>
/extra/org-netbeans-modules-java-j2seproject-copylibtask.jarant -propertyfile ant.properties
它有效,但并不让我高兴。 我要么想找到重用project.properties的方法,要么自动将其转换为“已解决”版本(步骤3)。 然后构建可以自动化。
I've just successfully built NetBeans project with ant. These were the things I had to do:
<NetBeans-folder>
/java2/ant to a "Netbeanless" machine<platform-name>
.home=<path to platform>
<path to nb-ant>
/extra/org-netbeans-modules-java-j2seproject-copylibtask.jarant -propertyfile ant.properties
It works, but doesn't make me happy. I would either like to find the way to reuse project.properties, or to automatically translate it to a "resolved" version (step 3). Build could then be automated.
我刚刚在我的 NetBeans 7.0 项目中完成了这个练习。 我能做的就是从 Windows 系统上的 .netbeans\7.0 目录复制 build.properties 文件,并为我的构建服务器创建一个 server.properties 文件。 这并不是什么大不了的事情,因为每个开发人员的 build.properties 都可能有所不同,因此服务器需要另一个文件是正常的。 然后,我将一个简单的 server-build.xml 文件放在一起,该文件引用该文件,并且仅执行 init、compile、dist 和 clean 的基础操作。 我将这两个文件提交到项目目录顶层的 CVS 存储库中,因为它们不会与其他项目文件冲突,并且可以在需要更新某些内容时作为提醒。 现在我可以使用“ant -f server-build.xml”在 CI 服务器上构建我的项目,一切正常。
我的整个 init 部分如下所示,给予我的服务器路径优先级,但包括来自 NetBeans 项目属性的必要信息。
在为嵌套项目定义 ant 任务时,我还必须执行类似的操作:
我必须将 j2ee.platform.classpath 从 project.properties 复制到我的 server.properties 文件,以确保对 j2ee.server.home 的引用按照我的方式解析需要。 我没想到必须这样做,但类路径否则是错误的,导致构建失败。
感谢您提供有关此问题的信息,因为它帮助指导我找到了这个解决方案。
I just went through this exercise with my NetBeans 7.0 project. What I was able to do was copy my build.properties file from my .netbeans\7.0 directory on my Windows system and make a server.properties file for my build server. This isn't much of a stretch, since every developer's build.properties may vary, so having another file for the server is to be expected. I then put together a simple server-build.xml file that references this file and does only the basics of init, compile, dist, and clean. I committed these two files to my CVS repository at the top level of my project directory, since they don't conflict with other project files and serve as a reminder in case something needs to be updated. Now I can build my project on my CI server with "ant -f server-build.xml" and everything just works.
My whole init section looks like this, giving my server paths priority, but including the necessary information from the NetBeans project properties.
I also had to do something similar when defining the ant tasks for my nested projects:
I had to copy the j2ee.platform.classpath from project.properties to my server.properties file to ensure the references to j2ee.server.home resolved as I needed. I didn't expect to have to do this, but the classpath was wrong otherwise, causing the build to fail.
Thanks for the information on this question, as it helped guide me to this solution.
我刚刚遇到了同样的问题。 我希望我可以摆脱netbeans去eclipse和maven,只是为了这个。
但是这里有一个很好的链接来导出蚂蚁将 netbeans 项目构建到持续集成服务器中(或者也可以构建到任何其他 IDE 中)。
技术进展顺利。 总结如下:
-silent
)nbproject
它应该有效。
I just faced the same problem. I hope I could get rid of netbeans to go to eclipse and maven, just for that.
But here is a good link to export a ant built project from netbeans into a continuous integration server (or could be into any other IDE too).
Technique is going pretty well. Here is a summary:
-silent
on the netbeans installer)nbproject
in SVNAnd it should work.