ImageVerifierCode 换一换
格式:DOCX , 页数:39 ,大小:3.02MB ,
资源ID:7593694      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7593694.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(如何创建和使用Runnable Jar File.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

如何创建和使用Runnable Jar File.docx

1、如何创建和使用Runnable Jar FileRunnable Jar PackageContents1, For project without referenced jar filesMethod1Method 2(this method helps you understand the structure of jar file)2, For project with referenced jar filesIntroductionMathod 1Method 2Method 3Method 4 (this method helps you understand the structu

2、re of jar file)Note: You will see many text “back to top” in this document, it only helps you jump to contents part, does not have any real meaning.1, For project without referenced jar files:Method 1A most simple project which prints “Hello World!”:public class Hello public static void main(String

3、args) System.out.println(Hello World!); Right-click on “src”, select“Export”, then select Java/JAR fieBack to topSpecify the path of the new created jar file:Back to topNextNextBack to topFinishBack to topBack to topSee what we have in folder test:See the content of “MANIFEST.MF”Backto topMethod 2(t

4、his method helps you understand the structure of jar file)Step 1:Create a text file, rename it to“Hello.java”, which simply prints “Hello World!”:public class Hello public static void main(String args) System.out.println(Hello World!); Step 2:Compile it using javac.exe, and we get Hello.class,Delete

5、 “Hello.java”, because wedont need it any more:Back to topBack to topStep 3:Move “Hello.class” to folder “test”Step 4:Create a new folder called “META-INF” in folder “test”Step 5:Create a new text file called “MANIFEST.MF” in folder “META-INF”Back to topStep 6:Edit file “MANIFEST.MF”, add a new line

6、:Main-Class: HelloNote: a line break is necessary at the end of above line.Above picture shows the correct input, Following picture shows the wrong input:Difference:position of the cursor.In another word, after input “Main-Class: Hello” in the file, we need hit “Enter” key to input a new line, which

7、 is necessary!Step 7:Run “jar cvfm a.jar META-INF/MANIFEST.MF .” in directory of “test” to get jar file.Back to topNote: the dot is necessary, it means current directory.By above command, we get followingexecutable jar file: a.jarStep 8:Run the jar package by “java jar ”Back to topQuestion:What will

8、 happen if we dont input a new line in step 6?Answer:We will get following error:2, For project with referenced jar files:IntroductionThis project is called test, the code is like below:package com.t;importcom.person.Person;publicclass Hello publicstaticvoid main(String args) Person person=newPerson

9、(); person.setName(args0); person.setGender(args1); person.setAge(Integer.parseInt(args2); System.out.println(Hello!nname: +person.getName()+ngender: +person.getGender()+nage: +person.getAge(); Back totopIt required another library called person.jarBack to topCode in project “person”:packagecom.pers

10、on;publicclass Person private String name=null; private String gender=null; privateintage=0; public String getName() returnname; publicvoidsetName(String name) this.name = name; public String getGender() returngender; publicvoidsetGender(String gender) this.gender = gender; publicintgetAge() returna

11、ge; publicvoidsetAge(int age) this.age = age; Back to topWe need make a runnable jar package:My eclipse version:Eclipse Java EE IDE for Web Developers.Version: Helios Service Release 2Build id: 20110218-0911(c) Copyright Eclipse contributors and others 2005, 2011. All rights reserved.Visit http:/www

12、.eclipse.org/webtoolsMathod 1Step 1Right-click on “src” ExportStep 2Select “Runnable JAR File” NextBack to topStep 3Specify export destination:Back to topFinishSelect “OK”Then we get the JAR file in the specified path:Back to topStep 4Run “java -jar test.jar tim male 31” in directory “C:Tim”Result :

13、 succeed Step 5Extract test.jar to folder test, and check what are in itBack to topBack to topContent of “MANIFEST.MF”:Manifest-Version: 1.0Class-Path: .Main-Class: com.t.HelloMethod 2Step 1 : the same as Method 1Step 2: the same as Method 1Step 3Back to topStep 4Back to topResult : also succeed Ste

14、p 5Back to topContent of “MANIFEST.MF”Manifest-Version: 1.0Rsrc-Class-Path: ./ person.jarClass-Path: .Rsrc-Main-Class: com.t.HelloMain-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoaderMethod 3Step 1 : the same as Method 1Step 2 : the same as Method 1Step 3Back to topBack to topAs you can

15、see, in addition to “test.jar”, a new folder is created: “test_lib”Step 4Result: also succeedStep 5Back to topContent of “MANIFEST.MF”:Manifest-Version: 1.0Class-Path: .test_lib/person.jarMain-Class: com.t.HelloBack to topMethod 4(this method helps you understand the structure of jar file)Step 1: th

16、e same as Method 1Step 2Select “JAR File” instead of “Runnable JAR File”Back to topBack to topStep 3NextNextBack to topBack to topStep 4But when we run it, well get an error: “NoClassDefFoundError”Why? After you see step 5, you will understandStep 5Check the content of test.jar , extract it to folde

17、r “test” firstBack to topContent of “MANIFEST.MF”:Manifest-Version: 1.0Main-Class: com.t.HelloAs you can see, There is no person.jar in the test.jarThere is also no Class-Pathdefinition in “MANIFEST.MF”.This is why the main class cannot find class “Person”What is the solution? See Step 6 please:Step

18、 6Export project “person” to a JAR file:Back to topBack to topBack to topSo now, we have two jar files, see above picture.Create a new folder called “all”, move the two jar file into folder “all”Right-click on “test.jar”, extract here Note :compression tool such as “winrar” is needed.Back to topDele

19、te “test.jar”Back up file “C:TimallMETA-INFMANIFEST.MF” to other place.The content of which is:Manifest-Version: 1.0Main-Class: com.t.HelloBack to topRight-click on “person.jar”, extract here When you are asked if replace existing files, select “Yes to All”Back to topDelete “person.jar”Check content

20、 of “C:TimallMETA-INFMANIFEST.MF” again:Manifest-Version: 1.0Here we can see, the key part (definition of Main-Class) is not in MANIFEST.MF any more.Replace file “C:TimallMETA-INFMANIFEST.MF” with the backed up one.Therefore, we have Main-Class definition in file MANIFEST.MF again:Manifest-Version:

21、1.0Main-Class: com.t.HelloBack to topRun “jar cvfm newtest.jar meta-inf/manifest.mf .” in directory “all”:And now we have a new JAR file called “newtest.jar”:Back to topRun the jar file in directory “all”:Succeed again.Now, lets see the files structure:Back to topConclusion: by this method, we can make this file structure manually.Put main class Hello.class and referenced class Person.class and its parents folder in same mother folderAnd keep content of META-INF/MANIFEST.MF correct, pointing out the correct main class.Back to top

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1