简体   繁体   中英

Including files in a netbeans project

I'm new to Java and I need to compile my programme and the dependent files (a .png and a .tff) into one jar so it can be run from any place on the system. I'm using the Netbeans IDE and I have no idea how to go about this. The way I'm importing the files is as follows:

        //IMPOT FONT
    try {
        Raleway = new BufferedInputStream(new FileInputStream(fontPath));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Select.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        font = Font.createFont(Font.TRUETYPE_FONT, Raleway);
    } catch (FontFormatException | IOException ex) {
        Logger.getLogger(Select.class.getName()).log(Level.SEVERE, null, ex);
    }

    //IMPORT ICON   
    try {
    Pidgeon.myImg = ImageIO.read(new FileInputStream(imagePath));
    } catch (IOException ex) {
        Logger.getLogger(Pidgeon.class.getName()).log(Level.SEVERE, null, ex);
    }

The variable "fontPath" is "font\\Raleway-Regular.tff" and "imagePath" is "image\\icon.png".

Simply with command line:

javac MyApp.java

jar -cf myJar.jar myApp

This command will generate a compressed JAR file and place it in the current directory. The command will also generate a default manifest file for the JAR archive.

And if you are using Netbeans, follow these steps:

1 Click on Properties

2 Click on Packaging

3 Click on Compress JAR File

4 Accept changes, click ok

5 Click the button in the ribbon tab with the hammer/broom. (clean and build project)

6 Go to the directory where your project is stored

7 Look in the dist folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM