Eclipse exports executable Java projects/executable Jar files (including third-party Jar packages)
The senior brother has deployed a new virtual machine and started to do it in the new semester! Before, because the crawler code was unstable, I always used Eclipse to run it directly, and then modified it when I encountered problems. But this is quite troublesome, and Eclipse itself takes up a lot of memory, it's falling! So this afternoon, I cleared the previous code and replaced log4j for many frustrated System.out.println. The path, database connection, and the configuration file were processed, and finally it was turned into an executable Jar, so that you can show off your skills on the new virtual machine^_^Y
Biu~After talking nonsense, I got to the point. There are various methods to package Java projects into executable Jars. There are many online examples, such as configuring MANIFET files. In fact, there is the easiest and feasible method, which is to directly export the Runnable JAR file using Eclipse.
My Eclipse version is Indigo Service Release 1 (it seems to be the legendary 3.7, not sure)
1. First, right-click your Java project, select Export, and select Runnable JAR file in the Java folder, as shown in the figure below:
2. After selecting the Runnable JAR file, the dialog box shown below will pop up. After selecting the export path, the default Finish is actually enough. But there are two things to note:
The JVM parameters you set in run configuration no longer work after packaging is completed and need to be specified on the command line when executing the jar (see 4);
There are three ways to deal with third-party packages since then. In fact, no one will affect your use. I use the first one by default, which will unzip the third-party jar packages into src.
3. After Finish, the executable jar package is generated. If your project contains configuration files, such as conf/xx.properties, then create a conf directory in the same layer as the jar package, and put xx.properties in the conf directory, as shown in the figure below:
4. Finally, run the packaged jar file, execute the start java command on the command line, and specify JVM parameters, such as setting the initial allocation memory of 128M, with a maximum of 256M:
start java -Xmx256m -Xms128m -jar spider.jar
In the above picture, we can see that there is a run.bat file, which actually has only one line of command: start java -Xmx256m -Xms128m -jar spider.jar, so that you can execute the jar by double-clicking. When you need to change the startup parameters, just edit run.bat and it will be OK.
Okay, it's a mark process. It's actually very simple. It just needs to search for information when you don't know, and it's a bit of a waste of time to try it over and over again. :)
Thank you for reading, I hope it can help you. Thank you for your support for this site!