In Eclipse, package a project containing image resources into a jar file,

Source: Internet
Author: User

In Eclipse, package a project containing image resources into a jar file,

Preface:

Recently I learned GUI programming and UDP protocol, and I was eager to develop a chat software in the LAN. It was still quite smooth in the early stage, and it was difficult to package the entire project into a jar file.

 

The icon you set is missing, but there is no default icon. This indicates that the image is not exported to the jar file. After some searches, I finally found a solution.

Tools and materials:

1. Eclipse

2. Images and projects using them

 

Solution:

First, click the Eclipse window -- preference -- Java -- Build Path (Windows -- Performance -- Java -- Build Path) and change it to the following (this should be the default)

Below is the position of my picture in the project

      

This is the code I called. It is written in UIUtil. java under the util package and can be called wherever necessary.

// Modify the public static void setFrameIamge (JFrame jf) {Toolkit tk = Toolkit. getdefatooltoolkit (); Image I = tk. getImage (jf. getClass (). getResource ("/resource/user.jpg"); // note that "/" jf. setIconImage (I );}

 

Then, package the project, click "File -- Export", and select "executable JAR Files"

      

Select the project to be exported, that is, to select the "STARTUP configuration" (note that its naming format is "class name-Project Name". For example, if my project name is ChatOne, the main function is located in the LoginOne class), Click Browse to view the hanging export directory and name the jar file, select the second library processing, and click Finish.

      

Open "run" with Win + R, Enter cmd, switch to the desktop (because I export the file to the desktop, it is actually to switch to the directory where the jar file is located), and run the jar File

C:\Users\Administrator>cd DesktopC:\Users\Administrator\Desktop>java -jar Chat_One.jar

You can see that the program has an icon.

      

 

Conclusion:

The above is the process of exporting a project containing image resources as a jar file. I am a little bit white and the level is limited. If there is any error above, please point it out.

 

  

      

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.