﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-IT Life-文章分类-J2se-&gt;jar</title><link>http://www.blogjava.net/tony/category/13564.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 03 Mar 2007 08:55:57 GMT</lastBuildDate><pubDate>Sat, 03 Mar 2007 08:55:57 GMT</pubDate><ttl>60</ttl><item><title>如何使用jar文件当中的资料</title><link>http://www.blogjava.net/tony/articles/60663.html</link><dc:creator>tony-dl</dc:creator><author>tony-dl</author><pubDate>Fri, 28 Jul 2006 14:43:00 GMT</pubDate><guid>http://www.blogjava.net/tony/articles/60663.html</guid><wfw:comment>http://www.blogjava.net/tony/comments/60663.html</wfw:comment><comments>http://www.blogjava.net/tony/articles/60663.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tony/comments/commentRss/60663.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tony/services/trackbacks/60663.html</trackback:ping><description><![CDATA[
		<p>利用this.getClass().getClassLoader().getResource(string) <br />取得资料，开启stream。</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<pre>
						<font color="#00a000">
								<b>public</b>
						</font>
						<font color="#00a000">
								<b>class</b>
						</font> ReadInnerFile <font color="#00a000">{</font><font color="#00a000"><b>public</b></font> ReadInnerFile() <font color="#00a000"><b>throws</b></font> IOException <font color="#00a000">{</font>
        URL u = this.getClass().getClassLoader().getResource(<font color="#00ed0">"xd.xml"</font>);
        BufferedReader br = <font color="#00a000"><b>new</b></font> BufferedReader(<font color="#00a000"><b>new</b></font> InputStreamReader(u
                .openStream()));
        String line = <font color="#00ed0">""</font>;
        <font color="#00a000"><b>while</b></font> ((line = br.readLine()) != <font color="#00a000"><b>null</b></font>) <font color="#00a000">{</font>
            System.out.println(line);
        <font color="#00a000">}</font>
        br.close();
 
    <font color="#00a000">}</font><font color="#00a000"><b>public</b></font><font color="#00a000"><b>static</b></font><font color="#00a000"><b>void</b></font> main(String[] args) <font color="#00a000"><b>throws</b></font> IOException <font color="#00a000">{</font><font color="#00a000"><b>new</b></font> ReadInnerFile();
    <font color="#00a000">}</font><font color="#00a000">}</font></pre>
		</div>
<img src ="http://www.blogjava.net/tony/aggbug/60663.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tony/" target="_blank">tony-dl</a> 2006-07-28 22:43 <a href="http://www.blogjava.net/tony/articles/60663.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何让自己的jar文件运行</title><link>http://www.blogjava.net/tony/articles/60662.html</link><dc:creator>tony-dl</dc:creator><author>tony-dl</author><pubDate>Fri, 28 Jul 2006 14:34:00 GMT</pubDate><guid>http://www.blogjava.net/tony/articles/60662.html</guid><wfw:comment>http://www.blogjava.net/tony/comments/60662.html</wfw:comment><comments>http://www.blogjava.net/tony/articles/60662.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/tony/comments/commentRss/60662.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/tony/services/trackbacks/60662.html</trackback:ping><description><![CDATA[
		<p>如何让自己的jar文件运行？<br />具体布局如下 :<br /><br />在 jar 文件的 manifest 文件中可以指定当 JVM 运行 jar 文件 </p>
		<p>时调用的类,这个类必须有 main(). <br /></p>
		<p>---------------------------------------------</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span> <span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.awt.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">; <br /></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> java.awt.event.</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">; <br /></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> MyClass { <br /></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> main(String[] args) { <br /></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">Frame f </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Frame(); <br /></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000">f.addWindowListener <br /></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> WindowAdapter() { <br /></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> windowClosing(WindowEvent e) { <br /></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">System.exit(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">); <br /></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">} <br /></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">} <br /></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">); <br /></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">f.add(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Label(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Hello world</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">)); <br /></span><span style="COLOR: #008080">26</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">27</span> <span style="COLOR: #000000">f.setSize(</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">200</span><span style="COLOR: #000000">); <br /></span><span style="COLOR: #008080">28</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">29</span> <span style="COLOR: #000000">f.setVisible(</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">); <br /></span><span style="COLOR: #008080">30</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">31</span> <span style="COLOR: #000000">} <br /></span><span style="COLOR: #008080">32</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">33</span> <span style="COLOR: #000000">} <br /></span><span style="COLOR: #008080">34</span> <span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">35</span> <span style="COLOR: #000000"></span></div>
		<p>--------------------------------------------- </p>
		<p>然后创建这个manifest 文件(manifest.mft) </p>
		<p>---------------------------------------------- </p>
		<p>Manifest-Version: 1.0 </p>
		<p>Main-Class: MyClass </p>
		<p>Classpath: .\MyJar.jar </p>
		<p>---------------------------------------------- </p>
		<p>在 dos 窗口下运行 </p>
		<p>jar cvfm MyJar.jar manifest.mft MyClass.class </p>
		<p>创建 jar 文件 </p>
		<p>运行 java -jar MyJar.jar 测试 </p>
		<p>在 explorer 内用鼠标双击 MyJar.jar 可以运行程序 </p>
		<p>如果在环境变量内加入 </p>
		<p>set PATHEXT=.EXE;.BAT;.CMD;.JAR </p>
		<p>并且 MyJar.jar 在 path 下 </p>
		<p>则在 dos 窗口内运行 MyJar 则会调用 java -jar MyJar.jar </p>
		<p>
				<br /> </p>
<img src ="http://www.blogjava.net/tony/aggbug/60662.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/tony/" target="_blank">tony-dl</a> 2006-07-28 22:34 <a href="http://www.blogjava.net/tony/articles/60662.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>