I recently wrote a small program of stock yield analysis in Java to calculate the benefits of my stock operation. Here, a procedure is recorded to package the source code into an executable command.
1: Generate the executable jar file
Select the project, select Export from the menu, select runnable JAR file, and then, depending on the situation, select the Export method for the third-party library, then you can, I choose the package required Libraries into generated JAR, In this case, the resulting jar file will contain the third-party library files required by the program, and no additional classpath will be required on the subsequent command line.
2: Run the jar file in the Windows Environment script script
Create a new batch file, enter
Java-jar Stockearningsapp_v1.0.1.jar%1%2
This command means: Run the Stockearningsapp_v1.0.1.jar file in the current directory,%1 and%2 are the parameters that are required for the program to run, and these parameters originate from the command-line arguments of the script.
configuration file and directory structure
The operation of the program requires a configuration file, and my program determines that the configuration file needs to be placed under "current path".
InputStreamReader InputStreamReader = new InputStreamReader (New FileInputStream ("Config.properties"), encoding);
This means that you need to create a subdirectory in the current directory stock, which is used to save files generated during program processing
String outputFile = new String ("Stock\\stock_exchange_all.txt");
Using Eclipse to create and use an executable jar file