簡體   English   中英

如何使用Netbeans 6.5將文件添加到jar中?

[英]How do you add files to a jar using Netbeans 6.5?

我是第一次使用Netbeans進行Java項目。 我想使用Netbeans 6.5創建一個包含約50個文本文件的jar。 有一個簡單的方法嗎?

您需要在驅動器上找到項目目錄。 然后將所有50個文本文件放入src文件夾。 返回到Netbeans。 現在,您應該已經在源程序包下看到了文本文件。 然后構建項目。 新創建的JAR應該位於項目目錄的dist文件夾中。

編輯:這是從“默認”包中的文本文件讀取的示例源代碼。 文件名為“ 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));
    }

}

如果您熟悉ant,則ant可以做到這一點,而Netbeans可以運行ant腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM