<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>利用脚本启动java程序 - hbcui1984的专栏 - 博客频道 - CSDN.NET</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=description content=用bat文件启动java程序,用shell脚本(sh文件)启动java程序>
<SCRIPT type=text/javascript
src="http://static.blog.csdn.net/Scripts/jquery.js"></SCRIPT>
<SCRIPT type=text/javascript
src="http://static.blog.csdn.net/scripts/plugins.js"></SCRIPT>
<SCRIPT type=text/javascript
src="http://static.blog.csdn.net/scripts/common.js"></SCRIPT>
<LINK rel=Stylesheet type=text/css
href="http://static.blog.csdn.net/skin/default/css/style.css"><LINK id=RSSLink
title=RSS rel=alternate type=application/rss+xml
href="/hbcui1984/rss/list"><LINK rel="shortcut icon" href="/favicon.ico"><LINK
rel=stylesheet type=text/css
href="http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/default.css">
<SCRIPT type=text/javascript
src="http://static.blog.csdn.net/scripts/SyntaxHighlighter/shCore.js"></SCRIPT>
<META name=GENERATOR content="MSHTML 8.00.7600.16853"></HEAD>
<BODY>
<SCRIPT type=text/javascript
src="http://csdnimg.cn/pubnav/js/pub_topnav_2011.js"></SCRIPT>
<DIV id=container>
<DIV id=header>
<DIV class=header>
<DIV id=blog_title>
<H1><A href="http://blog.csdn.net/hbcui1984">hbcui1984的专栏</A></H1>
<H2></H2>
<DIV class=clear></DIV></DIV>
<DIV class=clear></DIV></DIV></DIV>
<DIV id=navigator>
<DIV class=navigator_bg></DIV>
<DIV class=navigator>
<UL><!--<li id="btnHome"><a href="/hbcui1984"><span><img src="http://static.blog.csdn.net/images/ico_home.gif">我的首页</span></a></li>-->
<LI id=btnContents><A
href="http://blog.csdn.net/hbcui1984?viewmode=contents"><SPAN><IMG
src="http://static.blog.csdn.net/images/ico_list.gif">目录视图</SPAN></A></LI>
<LI id=btnView><A
href="http://blog.csdn.net/hbcui1984?viewmode=list"><SPAN><IMG
src="http://static.blog.csdn.net/images/ico_summary.gif">摘要视图</SPAN></A></LI>
<LI id=btnRss><A href="http://blog.csdn.net/hbcui1984/rss/list"><SPAN><IMG
src="http://static.blog.csdn.net/images/ico_rss.gif">订阅</SPAN></A></LI></UL></DIV></DIV>
<SCRIPT type=text/javascript>
var username = "hbcui1984";
var blog_address = "http://blog.csdn.net/hbcui1984";
var static_host = "http://static.blog.csdn.net";
var currentUserName = $.cookie("UserName");
</SCRIPT>
<DIV id=body>
<DIV id=main>
<DIV class=main>
<DIV class=notice><FONT size=2> <A
href="http://blog.csdn.net/blogdevteam/article/details/6774250"
target=_blank><FONT color=red>2011年中国移动开发者大会11月3-4日与您相约北京
</FONT></A>
<A href="http://blog.csdn.net/blogdevteam/article/details/6799983"
target=_blank><FONT color=red>2012年1月微软MVP申请开始了!</FONT></A><BR><A
href="http://blog.csdn.net/csdnproduct/article/details/6740376"
target=_blank><FONT color=red>CSDN博客“准专家勋章”“微软MVP勋章”上线公告</FONT></A>
<A
href="http://g.csdn.net/5197723" target=_blank><FONT
color=red>“IT适合你吗?”智力挑战</FONT></A> </FONT></DIV>
<SCRIPT type=text/javascript
src="http://static.blog.csdn.net/scripts/ad.js"></SCRIPT>
<DIV id=article_details class=details>
<DIV class=article_title><SPAN class="ico ico_type_Original"></SPAN>
<H3><SPAN class=link_title><A title=利用脚本启动java程序
href="http://blog.csdn.net/hbcui1984/article/details/1670775">利用脚本启动java程序</A></SPAN>
</H3></DIV>
<DIV class=article_manage><SPAN class=link_categories>分类: <A
href="http://blog.csdn.net/hbcui1984/article/category/240884">JAVA</A>
</SPAN><SPAN class=link_postdate>2007-06-28 21:23</SPAN> <SPAN class=link_view
title=阅读次数>6647人阅读</SPAN> <SPAN class=link_comments title=评论次数><A
href="http://blog.csdn.net/hbcui1984/article/details/1670775#comments">评论</A>(13)</SPAN>
<SPAN class=link_collect><A title=收藏
onclick="javascript:collectArticle('利用脚本启动java程序','1670775');return false;"
href="javascript:void(0);">收藏</A></SPAN> <SPAN class=link_report><A title=举报
onclick="javascript:report(1670775,2);return false;"
href="http://blog.csdn.net/hbcui1984/article/details/1670775#report">举报</A></SPAN>
</DIV>
<DIV class=article_content>
<H2 align=center>利用脚本启动java程序</H2>
<P>
今天在工作中,需要写一个shell脚本,启动一个socket程序,从而模拟短信网关。查了一些资料,终于搞定了,现在记录一下,方便大家查阅。</P>
<P>
为了说明使用方法,我们就用最简单的程序来实现,比如我们要运行下面这个类的main方法 </P>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
<DIV
style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; PADDING-BOTTOM: 4px; PADDING-LEFT: 5.4pt; WIDTH: 95%; PADDING-RIGHT: 5.4pt; BACKGROUND: #e6e6e6; WORD-BREAK: break-all; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid; PADDING-TOP: 4px">
<DIV><IMG alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><SPAN
style="COLOR: #0000ff">package</SPAN><SPAN
style="COLOR: #000000"> chb.cmd.test;<BR><IMG alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><BR><IMG
alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></SPAN><SPAN
style="COLOR: #0000ff">import</SPAN><SPAN
style="COLOR: #000000"> java.io.File;<BR><IMG alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></SPAN><SPAN
style="COLOR: #0000ff">import</SPAN><SPAN
style="COLOR: #000000"> java.io.IOException;<BR><IMG alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><BR><IMG
alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"></SPAN><SPAN
style="COLOR: #0000ff">import</SPAN><SPAN
style="COLOR: #000000"> org.apache.log4j.Logger;<BR><IMG alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif"><BR><IMG
id=_129_404_Open_Image
onclick="this.style.display='none'; document.getElementById('_129_404_Open_Text').style.display='none'; document.getElementById('_129_404_Closed_Image').style.display='inline'; document.getElementById('_129_404_Closed_Text').style.display='inline';"
alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif"><IMG
style="DISPLAY: none" id=_129_404_Closed_Image
onclick="this.style.display='none'; document.getElementById('_129_404_Closed_Text').style.display='none'; document.getElementById('_129_404_Open_Image').style.display='inline'; document.getElementById('_129_404_Open_Text').style.display='inline';"
alt="" align=top
src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif"></SPAN><SPAN
style="COLOR: #0000ff">public</SPAN><SPAN
style="COLOR: #000000"> </SPAN><SPAN
style="COLOR: #0000ff">class</SPAN><SPAN
style="COLOR: #000000"> TestClass </SPAN><SPAN
style="BORDER-BOTTOM: #808080 1px solid; BORDER-LEFT: #808080 1px solid; BACKGROUND-COLOR: #f