Netbeans 导出到 Jar,包括所有库文件 [英] Netbeans Export to Jar, include all library files

查看:15
本文介绍了Netbeans 导出到 Jar,包括所有库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真正需要的是 Eclipse with Netbeans 的等效项:

What I really need is an equivalent of this from Eclipse with Netbeans:

我想将所需的库提取到生成的 JAR 中,这样我就可以分发它,而无需随处包含 lib 文件夹.

I want to Extract required libraries into generated JAR so I can distribute it without the need of including the lib folder everywhere it goes.

这是最初的问题.

我正在尝试用 Netbeans 构建一个 jar,它将把所有的库文件打包在里面.我听说 Eclipse 可以通过选择导出来实现.使用 Netbeans,如果我清理并构建",它将在 dist 文件夹中创建一个可执行 jar,但它所依赖的所有库都在名为 lib 的文件夹中.我需要将所有内容都放在一个 jar 文件中.我认为它与 build.xml 文件有关.这是我的话.我在这里做错了什么?

I'm trying to build a jar out of Netbeans that will package all the library files inside it. I've heard it's possible with Eclipse by choosing Export. With Netbeans, if I "Clean and Build" it will create an executable jar in the dist folder, but all the libraries it depends on are in a folder called lib. I need it all to be in one jar file. I'm thinking it has to do with the build.xml file. Here's what mine says. What am I getting wrong here?

感谢您的帮助.

<?xml version="1.0" encoding="UTF-8"?>
<project name="BONotifier" default="default" basedir=".">
  <description>Builds, tests, and runs the project BONotifier.</description>
  <import file="nbproject/build-impl.xml"/>
  <target name="-post-jar">
    <jar jarfile="dist/Combined-dist.jar">
      <zipfileset src="${dist.jar}" excludes="META-INF/*" />
      <zipfileset src="lib/commons-io-1.4.jar" excludes="META-INF/*" />
      <manifest>
        <attribute name="Main-Class" value="controller.MainController"/>
      </manifest>
    </jar>
  </target>
</project>

更新:上面的代码在 build.xml 中.以下内容在 build-impl.xml 中.我猜这意味着 build.xml 在 build-impl.xml 期间运行.

Update: The code above is in build.xml. The following is in build-impl.xml. I'm guessing this means that build.xml is run during build-impl.xml.

<target name="-pre-init">
    <!-- Empty placeholder for easier customization. -->
    <!-- You can override this target in the ../build.xml file. -->
</target>

注意我从这个论坛.

推荐答案

我更喜欢 这个 解决方案,因为没有什么可下载的,全部基于 Ant 构建(约 20 行).这样就没有额外的依赖需要打扰.如果您有几分钟的时间,您也可以了解 Ant.

I prefer this solution since there is nothing to download, all based on Ant build (~20 lines). That way there is no additional dependency to bother with. If you have a couple of minutes, you can learn about Ant too.

原始文章的链接似乎已损坏(感谢 Oracle).这是另一个 链接.

It seems like the link to the original Article is broken (thanks Oracle). Here is another link.

原始文章也可从 Oracle 链接获得.

The original article is also available from Oracle link.

这篇关于Netbeans 导出到 Jar,包括所有库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆