Here we will record the packaging problems encountered today...
So that you forget or may help people who need help...
My problems include:
1. fatjar packaging problems
If you use a third-party jar package and want to package your project into a jar package at a time, you need to download fatjar. I will not go into details about how to install fatjar.
2. Image Display Problems
Images are referenced in the interface of my project, which can be displayed normally in eclipse, but cannot be displayed after being packaged.
One of the reasons is that the reference address in my code is "src/xxx.jpg". This is an error because it will be placed in the bin directory after compilation, "src/xxx.jpg" cannot be found"
In addition, it is best to use a special folder to store such files as "resource/xxx.jpg"
When the address is referenced, write the relative path strength of the resource "/resource/xxx.jpg.
Toolkit tk = Toolkit.getDefaultToolkit();Image image = tk.createImage("/resource/xxx.jpg");
Later, I wrote a class to put these static variables and referenced them elsewhere for maintenance purposes.
3. How to reference external images in jar
I want to package my images not into jar, but out of jar, so that I can replace them later.
The createimage of Tk. createimage ("/resource/xxx.jpg ");
URL I started to use
This. class. getResource ("/resource/xxx.jpg"); image path strength,
However, no matter how you obtain this method, you can only get my project/bin/directory.
You cannot get the bin directory at the same level or above. I wonder if it is correct.
Last changed
String filename = System.getProperty("user.dir") + "/resource/xxx.jpg";createImage(filename);
To solve the problem.
I feel that if the jar package references an external image, it will never work until filename is used as a URL...
4. Class-Path Problems
The fatjar package is not good, and the package contains about 30 kb of more fatjar packages.
It's good to modify Class-Path in MANIFEST. MF.
Note Space
Manifest-Version: 1.0Main-Class: hnysms.ShowMeClass-Path: . lib/log4j-1.2.15.jar lib/jdsmsserver-3.4.jar lib/mysql-connector-java-5.1.3-rc-bin.jar
5. How to read the external configuration file in jar
I want to keep the configuration files in my project, such as dbconfig. properties log4j. xml, not packaged into jar.
Because the package is not much different from the hard encoding ..
Dbconfig. properties can be directly written in the read code
InputStream ins = getClass().getResourceAsStream("/resource/dbconfig.properties");
In this way, errors may be packaged in eclipse.
However, log4j. xml must be written in your main method.
PropertyConfigurator.configure(System.getProperty("user.dir") + "/resource/log4j.xml");
This solves the problem...
Make a program
^_^ Very small dish