When you make a Java program into a runnable jar, and you want to use a. bat file to invoke the jar, there are a few things to note.
1. Set path and Classpath
The contents of technician in the. bat file are as follows:
@echo offset my_home=%~dp0set CLASSPATH=%my_home%Xxx.jar; %my_home%.. \lib\*;
Set PATH=%~dp0. \jre\binjava Xxx.xxx.MailClass. class
@echo off
When you double-click a. bat file to run, the window does not print output information.
Set my_home=%~dp0
~dp0 refers to the folder where the. Bat is located, assigning the folder path to My_home.
Set classpath=%my_home%Xxx.jar; %my_home%.. \lib\*;
Xxx.jar is a Java program made runnable Jar,lib is a jar package that needs to be referenced, and multiple paths are split with ";".
Set path=%~dp0. \jre\bin,
%~dp0. \jre\bin is the path where programs such as Java.exe,javaw.exe are located. If there is no JRE on the computer running. bat, you can put the JRE and the runnable jar together, and set the appropriate path to find the EXE that runs Java.
2. Set JVM parameters
@echo offset my_home=%~dp0set CLASSPATH=%my_home%xxx.jar;%my_home%. \lib\*;set path=%~dp0. \jre\binset path=%~dp0. \jre\bin
Set java_opts=-xms128m-%java_opts% xxx.xxx.MailClass. class
Set java_opts=-xms128m-xmx256m sets the parameters of the JVM.
Java%java_opts% xxx.xxx.MailClass.class plus the JVM parameters set earlier.
3. Running the GUI program
When running GUI programs, you can use Javaw.exe instead of Java.exe. If you want to be able to display output information when the program is running, you should use Java.exe.
@echo offset my_home=%~dp0set CLASSPATH=%my_home%xxx.jar;%my_home%. \lib\*;set path=%~dp0. \jre\binset PATH=%~dp0. \jre\binset java_opts=-xms128m-xmx256m start javaw %java_opts% xxx.xxx.MailClass. Class
Start Javaw%java_opts% Xxx.xxx.MailClass. class applies to Programs that start the GUI.
Using. bat to perform Java program basics