<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Welcome to XP Link Co., Ltd. &#187; Tomcat</title>
	<atom:link href="http://www.xp-link.com/category/java/tomcat/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xp-link.com</link>
	<description>XP Link Co., Ltd is a software consultant company specializes in Java Technology from Thailand.</description>
	<lastBuildDate>Tue, 10 Jan 2012 09:11:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Setting multiple JAVA_OPTS in Tomcat</title>
		<link>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/</link>
		<comments>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 11:34:39 +0000</pubDate>
		<dc:creator>Sorawit Laosinchai</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/?p=45</guid>
		<description><![CDATA[ Every JAVA Developer should know how to set Java runtime options. Tomcat&#8217;s document said that setting Tomcat&#8217;s Java runtime options is as easy as setting ordinary Java runtime options by set those options in environment variable named JAVA_OPTS. When I try to set multi Java runtime options in Tomcat core script, catalina.bat, it appear that [...] ]]></description>
			<content:encoded><![CDATA[<p> Every JAVA Developer should know how to set Java runtime options. Tomcat&#8217;s document said that setting Tomcat&#8217;s Java runtime options is as easy as setting ordinary Java runtime options by set those options in environment variable named <span style="color: #ff9900;">JAVA_OPTS</span>. When I try to set multi Java runtime options in Tomcat core script, catalina.bat, it appear that I cannot start my Tomcat Server due to fault configuration in <span style="color: #ff9900;">JAVA_OPTS</span> that lead to fault execute command in the last part of core script. What is happening here?<br />
<span id="more-45"></span></p>
<h4>First</h4>
<p>I have to mention about setting multiple Java runtime options. We know each option is separate by space</p>
<h3>example:</h3>
<pre class="code">java -Xms128M -Xmx512M</pre>
<p>The problem is having a space in JAVA_OPTS leading to having a space in  execute command in the last part of core script.</p>
<h3>If you use normal setting, Tomcat will execute by this line.</h3>
<pre class="code">%_EXECJAVA% %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%</pre>
<p>If you trace back to find the real command of this line you will see that the <span style="color: #ff9900;">%_EXECJAVA%</span> is set by this statements</p>
<pre class="code">if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA=start "Tomcat" %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%</pre>
<p>Thats mean the real command that execute in execution line is <span style="color: #ff9900;">start </span>with a lot of arguments. So the <span style="color: #ff9900;">%JAVA_OPTS%</span> is only an argument of <span style="color: #ff9900;">start</span> command. This explained why setting value of multiple Java runtime options in <span style="color: #ff9900;">%JAVA_OPTS%</span> as normal multiple Java runtime options when you call <span style="color: #ff9900;">java</span> is not working here. Because a space in normal multiple Java runtime options will treat as argument separator of <span style="color: #ff9900;">start</span> command and your second Java runtime options will treat as an argument next to <span style="color: #ff9900;">%JAVA_OPTS%</span>. Now we know what is the problem and everyone know how to fix the problem ?Just add double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span>? but is it enough?.<br />
<br />
While our propose now is printing double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span> in execution command but the double quote is a wrapper sign of batch script. So the line</p>
<pre class="code">set JAVA_OPTS="-Xms128M -Xmx512M"</pre>
<p>will print</p>
<pre class="code">-Xms128M -Xmx512M</pre>
<p>without double quote around it in the <span style="color: #ff9900;">%JAVA_OPTS%</span> part of <span style="color: #ff9900;">start</span> command. Yes, have or have not double quote around the value of <span style="color: #ff9900;">set JAVA_OPTS=</span> is the same.<br />
<br />
You have two easy options to force printing double quote around value of <span style="color: #ff9900;">%JAVA_OPTS%</span> in execution command.</p>
<h6>One is</h6>
<p>add  double quote around <span style="color: #ff9900;">%JAVA_OPTS%</span> in each execution line. The fixed version of the above execution line will look like this</p>
<pre class="code">%_EXECJAVA% "%JAVA_OPTS%" %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%</pre>
<p>But don&#8217;t forget that it has 4 execution line in Tomcat&#8217;s core script. Luckily they are at the last part of the script.</p>
<h6>The other way</h6>
<p>is adding double quote around double quoted value of <span style="color: #ff9900;">set JAVA_OPTS=</span>. The fixed version of <span style="color: #ff9900;">set JAVA_OPTS=</span> line will look like this</p>
<pre class="code">set JAVA_OPTS=""-Xms128M -Xmx512M""</pre>
<p>Yes, its look funny but its work because double quote mean using everything inside double quote as is. As a result, the value of <span style="color: #ff9900;">%JAVA_OPTS%</span> is <span style="color: #ff9900;">&#8220;-Xms128M -Xmx512M&#8221;</span> with double quote around it and it will print those double quote in to execution line.<br />
<br />
I prefer to latter way because we do not edit any Tomcat&#8217;s core script. We only fix our added line</p>
<pre class="code">set JAVA_OPTS=""-Xms128M -Xmx512M""</pre>
<p>in order to make our application usable. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2010/01/15/setting-multi-java_opts-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

