I am working on a project recently. In general, the project is to deal with the database and fetch out the data and submit it to an interface through the HTTP protocol. I won't talk about the specific functions, I just talk about one point here - the encoding issue
In the project, it involves getting the MD5 value of all data.
In Java projects, I personally like to change the default encoding of the project to UTF-8. The development tools used are mainly Eclipse. However, strange problems arise. When I debug the project in the IDE, there was no problem, but after it was typed into a jar package, it passed
java -jar project.jar
When running, every time the data is submitted, the interface will return the data and say that my signature is incorrect. In other words, it was my last step, something went wrong when doing MD5 operations.
Why can’t I do it after I get a jar package? After several twists and turns, I checked the hashCode of the parameters and checked the hexadecimal data of all submitted contents. I found that there was a problem with the text encoding. It is correct in Eclipse, but after typing out the jar package, the command line starts without setting the default string encoding, so the java virtual machine runs according to the default encoding of the system. I'm using a Windows environment, so naturally it's GBK encoding.
Later, by looking up the information, the solution was to add a parameter to specify the encoding:
java -Dfile.encoding=utf-8 -jar project.jar
That's all. The tool is running normally.
Thank you for reading, I hope it can help you. Thank you for your support for this site!