Running an Java application after it has been packaged requires attention to coding issues

  • 2020-05-24 05:36:03
  • OfStack

Recently, I have been working on a project. In general, the project is to deal with the database, extract the data and submit it to an interface through the HTTP protocol. I won't say much about the specific functions, but only about one point here -- the coding problem

In the project, it involves fetching MD5 values for all data.

In the Java project, individuals prefer to change the default encoding of the project to UTF-8. The development tools used are mainly Eclipse. However, a strange question arises. When I debugged the project in IDE, there was no problem, but I typed the jar package and passed it


java -jar project.jar

At run time, every time I submit data, the interface returns data saying my signature is incorrect. In other words, my last step, MD5, went wrong.

Why can't you pack the jar? After several twists and turns, I looked at the hashCode parameter and the hexadecimal data of all the submitted content, and found that there was something wrong with the text encoding. This is true in Eclipse, but after you type the jar package, starting command line 1 does not set the string default encoding, so the java virtual machine runs according to the default encoding of the system it is on. I'm using an Windows environment, so GBK is the natural encoding.

Later, through the access to data, the solution is to add 1 parameter to specify the code:


java -Dfile.encoding=utf-8 -jar project.jar

That's it. The tool is working properly.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: