.jar files are used for archiving, archive unpacking. One of the essential features of jar file is loss-less data compression. Need to know how to run one? Here's how.

STEPS:

  1. Make sure you have Java installed on your system. Check this by typingjava -version into the command terminal. If you don't have the latest version of Java, update it before proceeding.


  2. Make the .jar file executable. A .jar file is made executable by collecting the class files of your Java application; compilers or JVM (Java Virtual Machine) understand these formats. .jar files execute from
    javaw (Java web start). You need to set application's entry point within jar file. (An entry point is a class containing the main function of your application). You will set the entry point using the Manifest file. Here's how to do it:

    • The Jar tool automatically sets meta-inf/manifest.mf as path of the .jar file. When you open a default Manifest file, it should read "Manifest-Version: 1.0, Created-By: 1.6.0 (Sun Microsystems Inc)"
    • Make a manifest addition .txt file. Enter Main Class: [Package Name].[Class Name], with the bracketed portions filled in with your specific information. (This is in the form of an attribute value pair.)
    • Enter this terminal command to modify the Manifest file to include the application's entry point, changing the bracketed portions to your specific file names:jar cfm [jar file name] [manifest-addition] [input files]
    • Review your Manifest file. After you set the entry point, it should read: "Manifest-Version: 1.0,Created-By: 1.6.0 (Sun Microsystems Inc), Main Class: [Package Name].[Class Name]"
    • Alternatively, you can set the entry point using the .jar tool. This overrides the Main-class attribute in the Manifest's file. Enter the following terminal command:jar cfe [jar file name] [Package Name] [Class Name with
      main function]
  3. Run your .jar file. Run the .jar file using the following command (the main method of your java application executes):java -jar [Jar file Name]
  4. Make it so that you can run your.jar file by double-clicking it (optional). To open the .jar file by double-clicking on it, change the directory to the location of javaw (java web start)
    executable. Type the following command into terminal:C:\Program Files\Java\j2rex.y.z\bin\javaw.exe" -jar "%1" %*

Running a .jar File in Linux

  1. Open terminal. With Linux, double-clicking the .jar file opens it in a zip archiver showing the contents of the .jar file. Instead, right-click and select "Open Terminal."
  2. Execute the following command: $>java -jar [jar file name]
  3. Open your .jar file by double-clicking (optional). If you want to run the .jar file by double-clicking, then you might have to try changing the file type association (similar to the
    instructions for Windows) for your flavour of Linux system.

    • Make sure the above command works.
    • Type the following command into terminal: $>/usr/lib/jvm/jre-1.6.0-sun/bin/java -jar %f
    • Set the path according to where Java is located on your system.

hadoop执行jar文件的命令

# hadoop jar HelloWorld.jar

原文地址:http://www.wikihow.com/Run-a-.Jar-Java-File

How to Run a .Jar Java File的更多相关文章

  1. How to Convert a Class File to a Java File?

    What is a programming language? Before introducing compilation and decompilation, let's briefly intr ...

  2. 转:Java.file

    类 java.io.File 的使用 使用 File 的软件包 java.awt 包含用于创建用户界面和绘制图形图像的所有类. java.io 通过数据流.序列化和文件系统提供系统输入和输出. jav ...

  3. jar -- java文档归档工具

    参考文档 http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html http://blog.chinaunix.net ...

  4. Java File类总结和FileUtils类

    Java File类总结和FileUtils类 文件存在和类型判断 创建出File类的对象并不代表该路径下有此文件或目录. 用public boolean exists()可以判断文件是否存在. Fi ...

  5. Java File 类的使用方法详解

    Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对Java File文件操作类进行详细地分析,并将File类中的常用方法进行简单介绍,有需要的Java开发者可以看 ...

  6. Java File 类的使用方法详解(转)

    转自:http://www.codeceo.com/article/java-file-class.html Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对J ...

  7. A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/

    linux系统下jdk是已经安装好的情况之下软件出现 A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be av ...

  8. eclipse 启动问题Eclipse启动时报错:A Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No java virtual machine was found after searching the following locat

    从其他人直接复制的环境导致的问题. 正常双击出现当前异常,以管理员权限启动可以正常启动. ---------------------------Eclipse--------------------- ...

  9. Java:Linux上java -jar xxx.jar&java -cp 区别

    java -cp java -cp 和 -classpath 一样,是指定类运行所依赖其他类的路径,通常是类库和jar包,需要全路径到jar包,多个jar包之间连接符:window上分号“;”.Lin ...

随机推荐

  1. E2 结帐方案如何理解?

    E2 结帐方案如何理解? 此文转载自宇然软件官方网站:http://www.fsyuran.com    

  2. Maven生命周期(插件)

    maven拥有三套相互独立的生命周期,它们分别是clean,default和site.clean生命周期的目的是清理项目,default生命周期的目的是构建项目,而site 生命周期的目的是建立项目站 ...

  3. web设计经验<二>设计华丽的用户体验的6个热门技巧

    你是否曾经下载了一个应用,却发现它“很难使用”?对于大多数智能手机用户来说,答案是肯定的. 有趣的是,每四个手机应用中就有一个应用在下载后被“打入冷宫”. 如果一个应用能够吸引一个人下载并且打开它,但 ...

  4. MyEclipse8.5启动无法选择工作空间的问题

    方法一:打开Window---Preferences---General---Startup and Shutdown,勾选Prompt for workspace on startup 选项,再次登 ...

  5. Linux配置全局环境变量的方法

    总结3种方法: 1.修改/etc/profile    1.1 :首先在此文件中设置环境变量;    1.2:export  设置好的环境变量.  #view /etc/profile export ...

  6. Image Cropper+java实现截图工具

    首先,请移步http://jquery-plugins.net/image-cropper-jquery-image-cropping-plugin下载iamge cropper的有关js文件及css ...

  7. OpenGL的gluLookAt和glOrtho的关系

    OpenGL的gluLookAt和glOrtho的关系 一直不明白gluLookAt()和glOrtho()两者之间的关系:gluLookAt()是观察变换,glOrtho()是正交投影.glLook ...

  8. Oracle 修改一行数据内存主要变化

    向Oracle 数据库发出请求,修改一行数据,在内存中主要有以下变化: 1. 服务器进程将包含该行数据的块读取到内存中 2. 写redo日志.将内存中该数据块指向undo表空间中数据块的变更向量(Ch ...

  9. jQuery内置函数 ready

    jQuery给我们提供了一些非常实用的函数 ready:加载函数 传统事件只能绑定一个函数 后面的函数会把前面的函数覆盖 js中用的是  window.onload = function(){}; j ...

  10. controller 监控Unix性能信息

    linux系统需要有RPC(Remote Procedure Call Protocol),远程过程调用协议,通过安装rpc.rstatd程序,启动其服务,就可以给远程机器提供信息,即Lr可以获取到该 ...