Java:将库和 txt 首选项文件添加到项目中

发布于 2024-10-31 12:57:52 字数 804 浏览 3 评论 0原文

我正在使用 NetBeans 从我的 Arduino IDE 导入一系列库。我按照以下链接的指示进行操作:

http://silveiraneto.net/ 2009/03/01/arduino-and-java/

如果我使用 Arduino-0013 版本的 IDE 安装,此方法有效,更多当前版本不使用此方法进行编译。

我发现,如果我手动将“preferences.txt”、“keywords.txt”和“librxtxSerial.so”文件移动到我的 Java dist 中的 lib 文件夹中,则不需要使用 Arudino-0013 设置作为工作目录(build )文件夹,并将整个 Arduino-0013“硬件”文件夹也移动到我的 Java dist(构建)文件夹中。

当我这样做时,我可以在命令行上从 dist 目录运行 Java 程序。使用命令:

java -jar myProgram.jar

而不是必须进入 Arudino-0013 作为我的工作目录并使用 -cp 让我的程序工作(我还没有弄清楚如何做):

是当我使用 NetBeans 构建项目时,有办法包含这些 .txt 文件和 Arudino 硬件文件夹及其包含的所有文件吗?我问的原因是因为每次进行新构建时都必须手动执行此操作,这很烦人。

I'm using NetBeans to import a series of libraries from my Arduino IDE. I'm following directions from the following link:

http://silveiraneto.net/2009/03/01/arduino-and-java/

This works provided I use the Arduino-0013 version of the IDE install, more current versions do not compile using this method.

I have found that using the Arudino-0013 set as the working directory is NOT necessary if I manually move the "preferences.txt" and "keywords.txt" and "librxtxSerial.so" files into the lib folder in my Java dist (build) folder, and also move the entire Arduino-0013 "Hardware" folder also into my Java dist (build) folder.

When I do this I can run the Java program from the dist directory on the command line. Using the command:

java -jar myProgram.jar

rather than having to go into the Arudino-0013 as my working directory and use -cp to get my program to work (which I haven't worked out how to do incidentally):

Is there a way to include these .txt files and the Arudino hardware folder with all the files it contains when I build the project with NetBeans? The reason I ask is because it's getting annoying having to do this manually every time I do a new build.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

总以为 2024-11-07 12:57:52

我的答案不是特定于 netbeans,但您可以尝试:

制作一个 Apache ANT 构建文件来构建您的项目。在该文件中创建一个复制任务,它将复制构建中的 txt 文件。通过这样做,您将不必手动进行。请参阅此处:http://wiki.netbeans.org/NetbeansedAnt 了解如何在 NetBeans 中使用 ANT 。

My answer is not specific to netbeans but you can try:

Make an Apache ANT build file to build your project. In that file make a copy task which will copy txt files in your build. By doing this you will not have to so it manually. See here: http://wiki.netbeans.org/NetbeansedAnt to know how to work with ANT in NetBeans.

雨后咖啡店 2024-11-07 12:57:52

在 Netbeans 中,如果从“项目”选项卡切换到“文件”选项卡,您将看到有一个 build.xml 文件。这是一个 Ant build.xml 文件。您可以将 Ant 配置为在构建项目时自动为您复制文件。您基本上会得到这样的内容:

<project ...>
    <target name="-pre-compile">
        <copy file="some/path/preferences.txt" todir="../some/dir"/>
        <copy file="some/path/keywords.txt" todir="../some/dir"/>
        <copy file="some/path/librxtxSerial.so" todir="../some/dir"/>
    </target>
    <target name="-post-compile">
        <copy todir="build/dir">
            <fileset dir="some/path/Arduino-0013"/>
        </copy>
    </target>
</project>

build.xml 文件中有更多关于您可以连接和不能连接的信息。 Ant 文档很好,Ant 手册 的任务部分特别有用。

In Netbeans, if you switch from the Projects tab to the Files tab, you'll see that you have a build.xml file. This is an Ant build.xml file. You can configure Ant to automatically copy the files for you whenever your build your project. You would essentially have something like this:

<project ...>
    <target name="-pre-compile">
        <copy file="some/path/preferences.txt" todir="../some/dir"/>
        <copy file="some/path/keywords.txt" todir="../some/dir"/>
        <copy file="some/path/librxtxSerial.so" todir="../some/dir"/>
    </target>
    <target name="-post-compile">
        <copy todir="build/dir">
            <fileset dir="some/path/Arduino-0013"/>
        </copy>
    </target>
</project>

There is more information in the build.xml file about what you can and can't hook into. The Ant documentation is good, and the Tasks section of the Ant Manual will be particularly useful.

少女七分熟 2024-11-07 12:57:52

NetBeans 中应该有您的项目的依赖项部分。然后,您可以将外部库添加到您的项目中,例如您拥有的本地 JAR 文件。最好的方法可能是将文本文件和 Arduino 目录一起打包,然后将该 JAR 文件作为编译时(和/或运行时)依赖项添加到您的项目中。现在,当您在 NetBeans 中编译项目时,它应该在类路径中包含指定的 JAR 文件,瞧。

抱歉,没有为您提供更多特定于 NetBeans 的指导,我只使用过 IDE 几次,但所有 IDE 都允许您添加本地 JAR 文件和第三方库作为项目的依赖项,您只需找到您可以在 IDE 中的哪个位置执行此操作。

另一个可行的想法是将 NetBeans 设置为使用本地 Java 副本进行编译,而不是与 IDE 捆绑在一起的 Java,这样您就无需为项目依赖项而烦恼。同样,我不知道在 NetBeans 中的何处进行设置,但从“常规设置”(或者可能是“项目特定设置”)开始,找到“Java/编译”部分;希望有一个选项可以指定要使用哪个 JDK,然后将其指向您的本地副本。

There should be a dependencies section in NetBeans for your project. You can then add external libraries to your project, such as local JAR files you've got. The best way would probably be to jar up the text files and Arduino directory together, then add that JAR file as a compile-time (and/or run-time) dependency to your project. Now, when you compile your project in NetBeans it should include the specified JAR file on the classpath and voila.

Sorry to not give you more NetBeans-specific direction, I've only used the IDE a couple of times, but all IDEs will allow you to add local JAR files and third-party libraries as dependencies to your project, you just need to find where in the IDE you can do that.

Another idea that might work is to set NetBeans to use your local copy of Java for compilation instead of the one that came bundled with the IDE, that way you don't need to fuss with project dependencies. Again, I don't know where in NetBeans to set this, but start in the General Settings (or perhaps the Project-specific Settings) and find the Java/compilation section; hopefully there's an option to specify which JDK to use, then point it at your local copy.

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