仅使用 ant 运行 NetBeans 项目

发布于 2024-07-21 07:54:30 字数 338 浏览 7 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

地狱即天堂 2024-07-28 07:54:31

只是添加到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.

時窥 2024-07-28 07:54:31

我正在使用 Netbeans 6.8,并且使用 Netbeans 创建的 java 项目可以通过 Netbeans 自动生成的构建文件运行,只需在 cli 上使用 ant 即可。 所有常规目标,如 antcompileantrunantclean 等“都可以工作”。 (如果重要的话我正在使用 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)

半衬遮猫 2024-07-28 07:54:31

您可以仅使用此存储库https://github.com/albfan/ant-netbeans

它克服了 netbeans 包装的 ant 配置的所有奇怪之处,所以你只需要:

编译:

$ ant.sh compile

运行:

$ ant.sh run

到任何(自动完成):

$ ant.sh <tab><tab>

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:

$ ant.sh compile

To run:

$ ant.sh run

To whatever (autocompletion):

$ ant.sh <tab><tab>
韶华倾负 2024-07-28 07:54:30

可以直接从 Java/ANT 运行 NetBeans 生成的项目,但您可能需要手动设置一些属性和/或添加 jar 文件的路径。

不幸的是,NetBeans 倾向于使用自己的 JAR 文件和引用属性来包含任务定义,这些属性仅在 /nbproject/private/private.properties 文件中定义,这些属性通常在您第一次打开 NetBeans 项目或当您在 IDE 中编辑项目时进行修改。

如果您检查 build-impl.xml,您应该能够找到该属性并导出需要设置的值(操作系统平台),然后:


  • /nbproject/private.properties
  • 在中添加该属性定义
    build.xml
  • 在调用 ant 时传入命令行
    使用 -DPlatform=Foo 进行目标

就我个人而言,我喜欢 NetBeans 生成的 ANT 文件和目标的结构,但讨厌它们中塞满了多少自定义/专有的东西,这使得没有 NetBeans 就很难运行。

例如:

ant -Dplatforms.JDK_1.7.home=/opt/jdk 

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:

  • create/set the property in the
    /nbproject/private.properties
  • add that property definition in the
    parent build.xml
  • pass in the commandline when invoking your ant
    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 -Dplatforms.JDK_1.7.home=/opt/jdk 
谜泪 2024-07-28 07:54:30

我刚刚用 ant 成功构建了 NetBeans 项目。 这些是我必须做的事情:

  • /java2/ant 复制到“Netbeanless”机器
  • 将 nbproject/project.properties 复制到 ant.properties
  • 替换每个 ${ ant.properties 中的表达式及其值
  • 添加 platform..home=<平台路径>
  • 添加 libs.CopyLibs.classpath=/extra/org-netbeans-modules-java-j2seproject-copylibtask.jar
  • 将其他需要的类路径添加到 javac.classpath 中(例如 servlet-api.jar 的路径)
  • ant -propertyfile ant.properties

它有效,但并不让我高兴。 我要么想找到重用project.properties的方法,要么自动将其转换为“已解决”版本(步骤3)。 然后构建可以自动化。

I've just successfully built NetBeans project with ant. These were the things I had to do:

  • Copy <NetBeans-folder>/java2/ant to a "Netbeanless" machine
  • Copy nbproject/project.properties to, say, ant.properties
  • Replace every ${} expression in ant.properties with it's value
  • Add platform.<platform-name>.home=<path to platform>
  • Add libs.CopyLibs.classpath=<path to nb-ant>/extra/org-netbeans-modules-java-j2seproject-copylibtask.jar
  • Add other needed classpaths into javac.classpath (e.g. path to servlet-api.jar)
  • ant -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.

夜光 2024-07-28 07:54:30

我刚刚在我的 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 项目属性的必要信息。

<target name="init">
    <property file="server.properties"/>
    <property file="nbproject/project.properties"/>
</target>

在为嵌套项目定义 ant 任务时,我还必须执行类似的操作:

<target name="compile">
    <ant antfile="${project.MyProj-common}/build.xml" inheritall="false" target="jar">
        <property location="${build.dir}" name="dist.ear.dir"/>
        <property file="server.properties"/>
        <property file="${project.MyProj-common}/nbproject/project.properties"/>
    </ant>
    ...
</target>

我必须将 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.

<target name="init">
    <property file="server.properties"/>
    <property file="nbproject/project.properties"/>
</target>

I also had to do something similar when defining the ant tasks for my nested projects:

<target name="compile">
    <ant antfile="${project.MyProj-common}/build.xml" inheritall="false" target="jar">
        <property location="${build.dir}" name="dist.ear.dir"/>
        <property file="server.properties"/>
        <property file="${project.MyProj-common}/nbproject/project.properties"/>
    </ant>
    ...
</target>

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.

猫卆 2024-07-28 07:54:30

我刚刚遇到了同样的问题。 我希望我可以摆脱netbeans去eclipse和maven,只是为了这个。

但是这里有一个很好的链接来导出蚂蚁将 netbeans 项目构建到持续集成服务器中(或者也可以构建到任何其他 IDE 中)。

技术进展顺利。 总结如下:

  1. 在 CI 服务器上安装 netbeans(有一个选项可以在没有 gui 的情况下完成,在 netbeans 安装程序上使用 -silent
  2. 在 SVN 中包含 nbproject
  3. 添加到忽略列出私有文件夹
  4. 在 CI 服务器上创建您自己的私有文件夹
  5. 使其指向 CI 服务器的文件夹(模仿用于 CI 的帐户中的私有用户文件夹)
  6. 将真实文件夹从用户复制到此文件夹并更改每个路径(替换字符串)指向 CI 服务器上安装的 netbeans。

它应该有效。

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:

  1. install netbeans on the CI server (there is an option to do it without gui, use -silent on the netbeans installer)
  2. include nbproject in SVN
  3. add to ignore list the private folder
  4. create your own private folder on CI server
  5. make it point to a folder of your CI server (mimicking a private user folder in the account used for CI)
  6. copy a real folder from a user to this folder and change every path (replace strings) to point to your netbeans install on your CI server.

And it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文