JAVA程序的四种运行方式

1.在 eclipse或myeclipse中运行程序。

 

2.在命令控制台cmd中输入命令运行程序。

先编译类,在运行

javac example.class---->java example.

 

3.将JAVA程序以.bat形式运行。

界面.bat

在脚本中,你只需要设置CLASSPATH和依赖的jar包的位置

(set CLASSPATH=%CLASSPATH%;%.\lib\ibatis-sqlmap-2.jar);

程序的主入口(set _MAINCLASS=com.jrj.genius.api.client.action.HKStockGUI)

 

4.以可执行文件(.exe)的形式运行

思路:将程序打成jar包,用软件(如j2ewiz)将jar包打成可执行文件(.exe)。其中你需要在软件中设置程序的主入口以及添加依赖的jar包。

j2ewiz下载地址为:

http://d.download.csdn.net/down/1481815/hugejiletuhugejiltu

 

界面.bat的脚本如下:

@echo off
if "%OS%" == "Windows_NT" setlocal

rem --------------------------------------------------------------------------
rem Start script for the Reaper Server
rem
rem $Id: mercury2.bat,v 1.0 2009/5/7 19:50:38 darkhe$
rem ---------------------------------------------------------------------------

rem 设置java运行环境
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJavaHome
echo The JAVA_HOME environment variable is not defined
echo This environment variable is needed to run this program
goto end
:gotJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
goto okJavaHome
:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto end

:okJavaHome
rem 打印JAVA_HOME变量
rem echo JAVA_HOME=%JAVA_HOME%
rem 设置CLASSPATH
set CLASSPATH=%JAVA_HOME%\lib\tools.jar
set CLASSPATH=%CLASSPATH%;%.\lib\ibatis-sqlmap-2.jar
set CLASSPATH=%CLASSPATH%;%.\lib\ibatis-common-2.jar
set CLASSPATH=%CLASSPATH%;%.\lib\ibatis-dao-2.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-beanutils-1.7.0.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-codec-1.4.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-collections-3.2.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-httpclient-3.1.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-lang-2.5-javadoc.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-lang-2.5-sources.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-lang-2.5.jar
set CLASSPATH=%CLASSPATH%;%.\lib\commons-logging-1.0.4.jar
set CLASSPATH=%CLASSPATH%;%.\lib\dataservice-shared-1.0.1.jar
set CLASSPATH=%CLASSPATH%;%.\lib\dom4j-1.6.1.jar
set CLASSPATH=%CLASSPATH%;%.\lib\ezmorph-1.0.2.jar
set CLASSPATH=%CLASSPATH%;%.\lib\httpclient-4.0.jar
set CLASSPATH=%CLASSPATH%;%.\lib\httpcore-4.0.1.jar
set CLASSPATH=%CLASSPATH%;%.\lib\json-lib-2.3.jar
set CLASSPATH=%CLASSPATH%;%.\lib\log4j-1.2.14.jar
set CLASSPATH=%CLASSPATH%;%.\lib\spring-2.5.6.jar
set CLASSPATH=%CLASSPATH%;%.\lib\sqlserver-1.1.jar
set CLASSPATH=%CLASSPATH%;%.\demo.jar


rem 打印CLASSPATH变量
rem echo CLASSPATH=%CLASSPATH%


set _EXECJAVA="%JAVA_HOME%\bin\java"
set _JAVA_OPTS=-Xms128m -Xmx256m -XX:PermSize=128M -XX:MaxPermSize=128m
set _MAINCLASS=com.jrj.genius.api.client.action.HKStockGUI
goto doExec

:doExec
rem %_EXECJAVA%  %_JAVA_OPTS%  -classpath  "%CLASSPATH%"  %_MAINCLASS%
%_EXECJAVA%  -classpath  "%CLASSPATH%"  %_MAINCLASS%

:end
PAUSE

 

 

你可能感兴趣的:(JAVA基础知识,开发工具IDE,java,开发工具)