<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>wolfg&#039;s Weblog &#187; Java</title>
	<atom:link href="http://guoyong.me/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://guoyong.me</link>
	<description>wolfg&#039;s journey with open source, linux, programming, sysadm ...</description>
	<lastBuildDate>Wed, 04 Apr 2012 12:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/cn/</creativeCommons:license>		<item>
		<title>使用Eclipse Memory Analyzer(MAT)解决Java Web应用故障</title>
		<link>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/</link>
		<comments>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 14:54:11 +0000</pubDate>
		<dc:creator>guoyong</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[heap dump]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[mat]]></category>

		<guid isPermaLink="false">http://guoyong.me/?p=928</guid>
		<description><![CDATA[这周一我负责维护的一个系统突然出现故障，用户反映系统很慢，浏览器加载半天最后进了错误页面。登录到系统查看，发现系统负载很高，用sar命令进一步明确了是java进程在某一时刻后突然占据了大量CPU资源。查看应用日志，发现了OutOfMemory异常，然后使用jstat的gcutil确认JVM heap工作不正常，已经有上千次的full gc了。 用VisualGC或者jmap工具生成Headp dump文件，然后用MAT打开，生成内存泄露的分析报告，查找占用内存最大的对象并通过Thread call stack就可以定位导致问题出现的类和方法。 由于系统属旧系统，代码一直没有改动，显然是数据出了问题。最终发现是用户输入的格式不规范的数据，使得对数据做查找替换的一段代码不断地扩大1个字符串对象，导致内存消耗不断增长，gc频繁。 # sar # sar -P ALL 1 5 # jstat -gcutil &#60;pid_of_jvm&#62; 1000 # jmap -dump:format=b,file=HeapDump.hprof &#60;pid_of_jvm&#62; 参考: http://wiki.eclipse.org/index.php/MemoryAnalyzer]]></description>
			<content:encoded><![CDATA[<p>这周一我负责维护的一个系统突然出现故障，用户反映系统很慢，浏览器加载半天最后进了错误页面。登录到系统查看，发现系统负载很高，用sar命令进一步明确了是java进程在某一时刻后突然占据了大量CPU资源。查看应用日志，发现了OutOfMemory异常，然后使用jstat的gcutil确认JVM heap工作不正常，已经有上千次的full gc了。</p>
<p>用VisualGC或者jmap工具生成Headp dump文件，然后用MAT打开，生成内存泄露的分析报告，查找占用内存最大的对象并通过Thread call stack就可以定位导致问题出现的类和方法。</p>
<p>由于系统属旧系统，代码一直没有改动，显然是数据出了问题。最终发现是用户输入的格式不规范的数据，使得对数据做查找替换的一段代码不断地扩大1个字符串对象，导致内存消耗不断增长，gc频繁。</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># sar<br />
# sar -P ALL 1 5<br />
# jstat -gcutil &lt;pid_of_jvm&gt; 1000<br />
# jmap -dump:format=b,file=HeapDump.hprof &lt;pid_of_jvm&gt;</div></div>
<p>参考: <a href="http://wiki.eclipse.org/index.php/MemoryAnalyzer" target="_blank">http://wiki.eclipse.org/index.php/MemoryAnalyzer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>再谈使用Commons HttpClient产生大量CLOSE_WAIT</title>
		<link>http://guoyong.me/dev/%e5%86%8d%e8%b0%88%e4%bd%bf%e7%94%a8commons-httpclient%e4%ba%a7%e7%94%9f%e5%a4%a7%e9%87%8fclose_wait/</link>
		<comments>http://guoyong.me/dev/%e5%86%8d%e8%b0%88%e4%bd%bf%e7%94%a8commons-httpclient%e4%ba%a7%e7%94%9f%e5%a4%a7%e9%87%8fclose_wait/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 07:16:12 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[CLOSE_WAIT]]></category>
		<category><![CDATA[HttpClient]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[tcp]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=572</guid>
		<description><![CDATA[默认情况下(即用默认构造方法建立HttpClient对象)，httpMethod.releaseConnection()方法并不会关闭连接的Socket，目的是可以重用这个连接。网上有不少讨论： Re: CLOSE_WAIT, logging Re: [httpclient] CLOSE_WAIT sticking around Re: tcp connections left with CLOSE_WAIT apache httpclient与close_wait 这些讨论里提出了关闭Socket的方法，即在请求头里加上&#8221;Connection: close&#8221;，具体可见HTTP协议规范里的说明。 其实HttpClient 3.x 里还可以通过下面的方式建立HttpClient对象，来保证关闭Socket连接： HttpClient httpClient = new HttpClient(new SimpleHttpConnectionManager(true)); 具体可见HttpClient源码和API文档。 当然，使用HttpClient的多线程连接管理器时就不用这么做了。]]></description>
			<content:encoded><![CDATA[<p>默认情况下(即用默认构造方法建立HttpClient对象)，httpMethod.releaseConnection()方法并不会关闭连接的Socket，目的是可以重用这个连接。网上有不少讨论：</p>
<ul>
<li><a href="http://www.mail-archive.com/commons-httpclient-dev@jakarta.apache.org/msg04338.html">Re: CLOSE_WAIT, logging</a></li>
<li>
<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html">Re: [httpclient] CLOSE_WAIT sticking around</a></li>
<li>
<a href="http://www.mail-archive.com/httpclient-user@jakarta.apache.org/msg04467.html">Re: tcp connections left with CLOSE_WAIT</a></li>
<li><a href="http://swordinhand.javaeye.com/blog/149408">apache httpclient与close_wait</a></li>
</ul>
<p>这些讨论里提出了关闭Socket的方法，即在请求头里加上&#8221;Connection: close&#8221;，具体可见<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html">HTTP协议规范里的说明</a>。</p>
<p>其实HttpClient 3.x 里还可以通过下面的方式建立HttpClient对象，来保证关闭Socket连接：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">HttpClient</span><span style="color: Gray;"> </span><span style="color: Blue;">httpClient</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">HttpClient</span><span style="color: Olive;">(</span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">SimpleHttpConnectionManager</span><span style="color: Olive;">(</span><span style="color: Green;">true</span><span style="color: Olive;">))</span><span style="color: Gray;">;</span></li></ol></div>
<p>具体可见HttpClient源码和API文档。</p>
<p>当然，使用HttpClient的多线程连接管理器时就不用这么做了。</p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/%e5%86%8d%e8%b0%88%e4%bd%bf%e7%94%a8commons-httpclient%e4%ba%a7%e7%94%9f%e5%a4%a7%e9%87%8fclose_wait/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>遭遇&#8221;java.io.IOException: Too many open files&#8221;</title>
		<link>http://guoyong.me/linux/sysadm/%e9%81%ad%e9%81%87java-io-ioexception-too-many-open-files/</link>
		<comments>http://guoyong.me/linux/sysadm/%e9%81%ad%e9%81%87java-io-ioexception-too-many-open-files/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 08:47:21 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[ulimit]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=520</guid>
		<description><![CDATA[今天下午，线上的Jetty服务宕机了，日志里大量的&#8221;java.io.IOException: Too many open files&#8221;错误。搜索到Freddy Chu的博客里正好有关于此的解决办法。 $ sysctl fs.file-max$ lsof -u jetty -nn &#124; wc -l$ ulimit -a$ sudo vi /etc/security/limits.conf* soft nofile 65535* hard nofile 65535 同时发现了系统里也有Freddy Chu提到的&#8221;Too many CLOSE_WAIT&#8221;问题，谢谢Freddy Chu。 $ sudo vi /etc/sysctl.confnet.ipv4.tcp_fin_timeout = 30net.ipv4.tcp_keepalive_intvl = 2net.ipv4.tcp_keepalive_probes &#8230; <a href="http://guoyong.me/linux/sysadm/%e9%81%ad%e9%81%87java-io-ioexception-too-many-open-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>今天下午，线上的Jetty服务宕机了，日志里大量的&#8221;java.io.IOException: Too many open files&#8221;错误。搜索到<a href="http://tux.hk/">Freddy Chu</a>的博客里正好有关于此的解决办法。</p>
<div class="hl-surround"><div class="hl-main">$ sysctl fs.file-max<br />$ lsof -u jetty -nn | wc -l<br />$ ulimit -a<br />$ sudo vi /etc/security/limits.conf<br />* soft nofile 65535<br />* hard nofile 65535</div></div>
<p>同时发现了系统里也有Freddy Chu提到的&#8221;Too many CLOSE_WAIT&#8221;问题，谢谢Freddy Chu。</p>
<div class="hl-surround"><div class="hl-main">$ sudo vi /etc/sysctl.conf<br />net.ipv4.tcp_fin_timeout = 30<br />net.ipv4.tcp_keepalive_intvl = 2<br />net.ipv4.tcp_keepalive_probes = 2<br />net.ipv4.tcp_keepalive_time = 1800<br /><br />$ sudo sysctl -p</div></div>
<blockquote><p>Update(2010-01-21): root用户要特殊设置</p>
<div class="hl-surround"><div class="hl-main">$ sudo vi /etc/security/limits.conf<br />root soft nofile 65535<br />root hard nofile 65535</div></div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/%e9%81%ad%e9%81%87java-io-ioexception-too-many-open-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决Maven Jetty Plugin在Windows下的“文件锁定”问题</title>
		<link>http://guoyong.me/dev/jie-jue-maven-jetty-plugin-zai-windows-xia-di-wen-jian-suo-ding-wen-ti/</link>
		<comments>http://guoyong.me/dev/jie-jue-maven-jetty-plugin-zai-windows-xia-di-wen-jian-suo-ding-wen-ti/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 05:31:04 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jetty]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=360</guid>
		<description><![CDATA[使用Maven进行Java的web开发，Jetty Plugin是必不可缺的插件，可以极大的提到开发效率。但在Windows环境下会遇到静态文件（html、css、js）被锁定、无法即时更新的问题。要想更新这些文件，只能先停掉Jetty，保存修改，再启动Jetty，非常不方便。 解决办法是这样的： 1、从jetty.jar中解出webdefault.xml（位于org.mortbay.jetty.webapp包下）这个文件，把这个useFileMappedBuffer参数设为false &#60;init-param&#62;&#160;&#60;param-name&#62;useFileMappedBuffer&#60;/param-name&#62;&#160;&#60;!-- change to false --&#62;&#160;&#60;param-value&#62;true&#60;/param-value&#62;&#60;/init-param&#62; 2、把修改后的webdefault.xml文件跟pom.xml放在一起 3、修改pom.xml里的Jetty Plugin的配置，加入webdefault.xml ...&#60;plugin&#62;&#160;&#160; &#60;groupId&#62;org.mortbay.jetty&#60;/groupId&#62;&#160;&#160; &#60;artifactId&#62;maven-jetty-plugin&#60;/artifactId&#62;&#160;&#160; &#60;version&#62;6.1.7&#60;/version&#62;&#160;&#160; &#60;configuration&#62;&#160;&#160; &#160; &#60;contextPath&#62;/&#60;/contextPath&#62;&#160;&#160; &#160; &#60;webDefaultXml&#62;webdefault.xml&#60;/webDefaultXml&#62;&#160;&#160; &#160; ...&#160;&#160; &#160;&#60;/configuration&#62;&#160;&#160; &#160;...&#60;/plugin&#62;...]]></description>
			<content:encoded><![CDATA[<p>使用Maven进行Java的web开发，Jetty Plugin是必不可缺的插件，可以极大的提到开发效率。但在Windows环境下会遇到静态文件（html、css、js）被锁定、无法即时更新的问题。要想更新这些文件，只能先停掉Jetty，保存修改，再启动Jetty，非常不方便。<br />
解决办法是这样的：<br />
1、从jetty.jar中解出webdefault.xml（位于org.mortbay.jetty.webapp包下）这个文件，把这个useFileMappedBuffer参数设为false</p>
<div class="hl-surround"><div class="hl-main">&lt;init-param&gt;<br />&nbsp;&lt;param-name&gt;useFileMappedBuffer&lt;/param-name&gt;<br />&nbsp;&lt;!-- change to false --&gt;<br />&nbsp;&lt;param-value&gt;true&lt;/param-value&gt;<br />&lt;/init-param&gt;</div></div>
<p>2、把修改后的webdefault.xml文件跟pom.xml放在一起<br />
3、修改pom.xml里的Jetty Plugin的配置，加入<webDefaultXml>webdefault.xml</webDefaultXml></p>
<div class="hl-surround"><div class="hl-main">...<br />&lt;plugin&gt;<br />&nbsp;&nbsp; &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;<br />&nbsp;&nbsp; &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;<br />&nbsp;&nbsp; &lt;version&gt;6.1.7&lt;/version&gt;<br />&nbsp;&nbsp; &lt;configuration&gt;<br />&nbsp;&nbsp; &nbsp; &lt;contextPath&gt;/&lt;/contextPath&gt;<br />&nbsp;&nbsp; &nbsp; &lt;webDefaultXml&gt;webdefault.xml&lt;/webDefaultXml&gt;<br />&nbsp;&nbsp; &nbsp; ...<br />&nbsp;&nbsp; &nbsp;&lt;/configuration&gt;<br />&nbsp;&nbsp; &nbsp;...<br />&lt;/plugin&gt;<br />...</div></div>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/jie-jue-maven-jetty-plugin-zai-windows-xia-di-wen-jian-suo-ding-wen-ti/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web页面自动打印PDF文件的实现</title>
		<link>http://guoyong.me/dev/web-e9-a1-b5-e9-9d-a2-e8-87-aa-e5-8a-a8-e6-89-93-e5-8d-b0pdf-e6-96-87-e4-bb-b6-e7-9a-84-e5-ae-9e-e7-8e-b0/</link>
		<comments>http://guoyong.me/dev/web-e9-a1-b5-e9-9d-a2-e8-87-aa-e5-8a-a8-e6-89-93-e5-8d-b0pdf-e6-96-87-e4-bb-b6-e7-9a-84-e5-ae-9e-e7-8e-b0/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 15:01:55 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[iText]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://guoyong.org/2008/02/29/350</guid>
		<description><![CDATA[借助iText和Adobe Acrobat的Javascript支持，可以实现PDF文档的自动打印（可以做到不显示打印对话框） ...... &#160; PdfReader&#160;reader = new PdfReader(pdfStream); [1] &#160; StringBuffer&#160;script = new StringBuffer(); [2] script.append(&#34;this.print({bUI: false,bSilent: true,bShrinkToFit: false});&#34;) &#160; .append(&#34;\r\nthis.closeDoc();&#34;); &#160; ByteArrayOutputStream&#160;bos = new ByteArrayOutputStream(pdfStream.length); try&#160;{ &#160; PdfStamper&#160;stamp = new PdfStamper(reader, bos); [3] &#160; stamp.setViewerPreferences(PdfWriter.HideMenubar&#160; &#160; &#160; &#124; PdfWriter.HideToolbar &#8230; <a href="http://guoyong.me/dev/web-e9-a1-b5-e9-9d-a2-e8-87-aa-e5-8a-a8-e6-89-93-e5-8d-b0pdf-e6-96-87-e4-bb-b6-e7-9a-84-e5-ae-9e-e7-8e-b0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>借助iText和Adobe Acrobat的Javascript支持，可以实现PDF文档的自动打印（可以做到不显示打印对话框）</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Gray;">......</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Blue;">PdfReader</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">reader</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">PdfReader</span><span style="color: Olive;">(</span><span style="color: Blue;">pdfStream</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">[</span><span style="color: Maroon;">1</span><span style="color: Olive;">]</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Blue;">StringBuffer</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">script</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">StringBuffer</span><span style="color: Olive;">()</span><span style="color: Gray;">; </span><span style="color: Olive;">[</span><span style="color: Maroon;">2</span><span style="color: Olive;">]</span></li>
<li><span style="color: Blue;">script</span><span style="color: Gray;">.</span><span style="color: Blue;">append</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">this.print({bUI: false,bSilent: true,bShrinkToFit: false});</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span></li>
<li><span style="color: Gray;">&nbsp; .</span><span style="color: Blue;">append</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Navy;">\r\n</span><span style="color: Red;">this.closeDoc();</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Blue;">ByteArrayOutputStream</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">bos</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ByteArrayOutputStream</span><span style="color: Olive;">(</span><span style="color: Blue;">pdfStream</span><span style="color: Gray;">.</span><span style="color: Blue;">length</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Green;">try</span><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">PdfStamper</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">stamp</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">PdfStamper</span><span style="color: Olive;">(</span><span style="color: Blue;">reader</span><span style="color: Gray;">, </span><span style="color: Blue;">bos</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: Olive;">[</span><span style="color: Maroon;">3</span><span style="color: Olive;">]</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">stamp</span><span style="color: Gray;">.</span><span style="color: Blue;">setViewerPreferences</span><span style="color: Olive;">(</span><span style="color: Blue;">PdfWriter</span><span style="color: Gray;">.</span><span style="color: Blue;">HideMenubar</span><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">&nbsp; &nbsp; | </span><span style="color: Blue;">PdfWriter</span><span style="color: Gray;">.</span><span style="color: Blue;">HideToolbar</span><span style="color: Gray;"> | </span><span style="color: Blue;">PdfWriter</span><span style="color: Gray;">.</span><span style="color: Blue;">HideWindowUI</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">stamp</span><span style="color: Gray;">.</span><span style="color: Blue;">addJavaScript</span><span style="color: Olive;">(</span><span style="color: Blue;">script</span><span style="color: Gray;">.</span><span style="color: Blue;">toString</span><span style="color: Olive;">())</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">stamp</span><span style="color: Gray;">.</span><span style="color: Blue;">close</span><span style="color: Olive;">()</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">catch</span><span style="color: Gray;"> </span><span style="color: Olive;">(</span><span style="color: Blue;">DocumentException</span><span style="color: Gray;"> </span><span style="color: Blue;">e</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Blue;">logger</span><span style="color: Gray;">.</span><span style="color: Blue;">error</span><span style="color: Olive;">(</span><span style="color: Blue;">e</span><span style="color: Gray;">.</span><span style="color: Blue;">getMessage</span><span style="color: Olive;">()</span><span style="color: Gray;">, </span><span style="color: Blue;">e</span><span style="color: Gray;">.</span><span style="color: Blue;">getCause</span><span style="color: Olive;">())</span><span style="color: Gray;">;</span></li>
<li><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Green;">return</span><span style="color: Gray;">&nbsp;</span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">StreamingResolution</span><span style="color: Olive;">(</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">application/pdf</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;">,&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp; </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">BufferedInputStream</span><span style="color: Olive;">(</span><span style="color: Green;">new</span><span style="color: Gray;"> </span><span style="color: Blue;">ByteArrayInputStream</span><span style="color: Olive;">(</span><span style="color: Blue;">bos</span><span style="color: Gray;">.</span><span style="color: Blue;">toByteArray</span><span style="color: Olive;">())))</span><span style="color: Gray;"> ;</span></li>
<li><span style="color: Gray;">&nbsp;</span></li>
<li><span style="color: Gray;">......</span></li></ol></div>
<p>代码说明：<br />
1、pdfStream是用iText生成的PDF文档字节流<br />
2、script是要加入到PDF文档里的Javascript代码。这段Javascript代码先调用PDF文档对象的print方法，然后用closeDoc方法关闭文档。print方法的参数指定了不要显示打印对话框，参数含义参考<a href="http://partners.adobe.com/public/developer/pdf/topic_js.html">Acrobat JavaScript Scripting Reference</a><br />
3、bos用来保存加入Javascript后的PDF文档字节流，它作为PdfStamper对象的输出流。PdfStamper对象调用addJavaScript方法将Javascript代码加入到PDF文档中。</p>
<p>Web页面嵌入PDF文档:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;">&lt;</span><span style="color: Green;">embed</span><span style="color: Gray;"> </span><span style="color: #00008b;">type</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">application/pdf</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;"> </span><span style="color: #00008b;">src</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">/PrintPdf.action</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;"> </span><span style="color: #00008b;">width</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">1</span><span style="color: #8b0000;">&quot;</span><span style="color: Gray;"> </span><span style="color: #00008b;">height</span><span style="color: Gray;">=</span><span style="color: #8b0000;">&quot;</span><span style="color: Red;">1</span><span style="color: #8b0000;">&quot;</span><span style="color: Olive;">&gt;&lt;/</span><span style="color: Green;">embed</span><span style="color: Olive;">&gt;</span></li></ol></div>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/web-e9-a1-b5-e9-9d-a2-e8-87-aa-e5-8a-a8-e6-89-93-e5-8d-b0pdf-e6-96-87-e4-bb-b6-e7-9a-84-e5-ae-9e-e7-8e-b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>发布jar包到自己设立的Maven Repository</title>
		<link>http://guoyong.me/dev/%e5%8f%91%e5%b8%83jar%e5%8c%85%e5%88%b0%e8%87%aa%e5%b7%b1%e7%9a%84repository/</link>
		<comments>http://guoyong.me/dev/%e5%8f%91%e5%b8%83jar%e5%8c%85%e5%88%b0%e8%87%aa%e5%b7%b1%e7%9a%84repository/#comments</comments>
		<pubDate>Sat, 08 Dec 2007 07:28:47 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://guoyong.org/2007/12/08/348</guid>
		<description><![CDATA[使用Artifactiry为自己的开发团队设立了repository镜像。有时需要把本地的一些第三方的jar包发布到服务器，使用maven-deploy-plugin的deploy:deploy-file目标可以完成这个任务。 比如，要发布jta的jar包jta-1.0.1B.jar $ mvn deploy:deploy-file -DgroupId=javax.transaction \&#160;&#160; -DartifactId=jta \&#160;&#160; -Dversion=1.0.1B \&#160;&#160; -Dpackaging=jar \&#160;&#160; -Dfile=~/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar \&#160;&#160; -DrepositoryId=central \&#160;&#160; -Durl=http://host.of.your.repository[:port]/artifactory/ibiblio@repo 说明： repositoryId在工程的pom文件里设置 url由Artifactiry的配置决定，注意不能使用virtual repository的地址 如果远程repository需要身份验证，用户名和密码需要在maven的settings.xml里设置 参考: http://maven.apache.org/guides/mini/guide-deploying-3rd-party-jars.html http://www.jfrog.org/sites/artifactory/latest/import.html]]></description>
			<content:encoded><![CDATA[<p>使用Artifactiry为自己的开发团队设立了repository镜像。有时需要把本地的一些第三方的jar包发布到服务器，使用maven-deploy-plugin的deploy:deploy-file目标可以完成这个任务。</p>
<p>比如，要发布jta的jar包jta-1.0.1B.jar</p>
<div class="hl-surround"><div class="hl-main">$ mvn deploy:deploy-file -DgroupId=javax.transaction \<br />&nbsp;&nbsp; -DartifactId=jta \<br />&nbsp;&nbsp; -Dversion=1.0.1B \<br />&nbsp;&nbsp; -Dpackaging=jar \<br />&nbsp;&nbsp; -Dfile=~/.m2/repository/javax/transaction/jta/1.0.1B/jta-1.0.1B.jar \<br />&nbsp;&nbsp; -DrepositoryId=central \<br />&nbsp;&nbsp; -Durl=http://host.of.your.repository[:port]/artifactory/ibiblio@repo</div></div>
<p>说明：</p>
<ul>
<li>repositoryId在工程的pom文件里设置</li>
<li>url由Artifactiry的配置决定，注意不能使用virtual repository的地址</li>
<li>如果远程repository需要身份验证，用户名和密码需要在maven的settings.xml里设置</li>
</ul>
<p>参考: </p>
<ul>
<li> http://maven.apache.org/guides/mini/guide-deploying-3rd-party-jars.html </li>
<li> http://www.jfrog.org/sites/artifactory/latest/import.html </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/%e5%8f%91%e5%b8%83jar%e5%8c%85%e5%88%b0%e8%87%aa%e5%b7%b1%e7%9a%84repository/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EasyEclipse的console中文乱码问题的解决</title>
		<link>http://guoyong.me/dev/easyeclipse%e7%9a%84console%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/</link>
		<comments>http://guoyong.me/dev/easyeclipse%e7%9a%84console%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/#comments</comments>
		<pubDate>Mon, 14 May 2007 16:49:59 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://guoyong.org/2007/05/15/321</guid>
		<description><![CDATA[EasyEclipse的console中输出中文是乱码，原因是它自带的jre不是多语言版本，从多语言版本的JDK里复制charsets.jar文件到%Easy_Eclipse_Home%\jre\jre\lib目录下，重新启动一下EasyEclipse就好了。]]></description>
			<content:encoded><![CDATA[<p>EasyEclipse的console中输出中文是乱码，原因是它自带的jre不是多语言版本，从多语言版本的JDK里复制charsets.jar文件到%Easy_Eclipse_Home%\jre\jre\lib目录下，重新启动一下EasyEclipse就好了。</p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/easyeclipse%e7%9a%84console%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98%e7%9a%84%e8%a7%a3%e5%86%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.578 seconds -->

