Using. bat to perform Java program basics

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.