如何使用Netbeans 6.5将文件添加到jar中? [英] How do you add files to a jar using Netbeans 6.5?

查看:103
本文介绍了如何使用Netbeans 6.5将文件添加到jar中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次使用Netbeans进行Java项目.我想使用Netbeans 6.5创建一个包含约50个文本文件的jar.有没有简单的方法可以做到这一点?

I am working on a Java project using Netbeans for the first time. I would like to use Netbeans 6.5 to create a jar including about 50 text files. Is there a simple way to do this?

推荐答案

您需要在驱动器上找到项目目录.然后将所有50个文本文件放入 src 文件夹.返回到Netbeans.现在,您应该可以在源代码包下看到您的文本文件.然后构建该项目.新创建的JAR应该位于项目目录的 dist 文件夹中.

You need to locate the project directory on your drive. And then put all your 50 text files into src folder. Go back to Netbeans. You should see your text files under your source package by now. Then Build the project. Your newly created JAR should be in your project directory's dist folder.

编辑:这是从默认"包中的文本文件读取的示例源代码.文件名为"hello.txt".

Here is example source code which reads from text file in "default" package. The file name is "hello.txt".

package testtextfile;

import java.io.InputStream;
import java.util.Scanner;
import javax.swing.JLabel;
import javax.swing.JOptionPane;


public class Main {

    public static void main(String[] args) {
        InputStream s = Main.class.getClassLoader().getResourceAsStream("hello.txt");
        Scanner sc = new Scanner(s);
        sc.useDelimiter("\\Z"); // read to the end of file. all at one.
        String contents = sc.next();
        JOptionPane.showMessageDialog(null, new JLabel(contents));
    }

}

这篇关于如何使用Netbeans 6.5将文件添加到jar中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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