.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. javascript学习-原生javascript的小特效(多个运动效果整理)

    以下代码就不详细解析了,在我之前的多个运动效果中已经解析好多次了,重复的地方这里就不说明了,有兴趣的童鞋可以去看看之前的文章<原生javascript的小特效> <!DOCTYPE ...

  2. mysql概要(六)连接

    内连接 [join on / from 表1,表二 ]效果一样 区别是:可以理解为首先取得笛卡儿积后,再 内连接:取俩表的匹配数据: 左连接:取的俩表匹配数据,并且保留未匹配数据中左表的数据,右表数据 ...

  3. js 返回上一页

    --------2016-6-14 16:37:30-- source:[1]js返回上一页

  4. CentOS下源码安装MySQL

    一.创建mysql用户与组,相关目录 useradd mysql -s /sbin/nologin mkdir /usr/local/mysql chown -R mysql.mysql mkdir ...

  5. WebKit渲染基础(转载 学习中。。。)

    概述 WebKit是一个渲染引擎,而不是一个浏览器,它专注于网页内容展示,其中渲染是其中核心的部分之一.本章着重于对渲染部分的基础进行一定程度的了解和认识,主要理解基于DOM树来介绍Render树和R ...

  6. Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)

      Android 高手进阶(21)  版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明地址:http://blog.csdn.net/xiaanming/article/detail ...

  7. 转:对TCP/IP网络协议的深入浅出归纳

    转自:http://blog.jobbole.com/74795/ 前段时间做了一个开发,涉及到网络编程,开发过程比较顺利,但任务完成后始终觉得有一些疑惑.主要是因为对网络协议不太熟悉,对一些概念也没 ...

  8. [转]Oracle中INITRANS和MAXTRANS参数

    每个块都有一个块首部.这个块首部中有一个事务表.事务表中会建立一些条目来描述哪些事务将块上的哪些行/元素锁定.这个事务表的初始大小由对象的INITRANS 设置指定.对于表,这个值默认为2(索引的IN ...

  9. js boolean 判断

    在写项目的时候出现了一个这样的问题,虽然问题解决了,但是还是有点疑问. 在数据库中设计的表的一个字段为是否审核(is_vaild) 类型 tinyint(1) 对应的在 java中就是布尔类型(boo ...

  10. 数据库索引B+树

    面试时无意间被问到了这个问题:数据库索引的存储结构一般是B+树,为什么不适用红黑树等普通的二叉树? 经过和同学的讨论,得到如下几个情况: 1. 数据库文件是放在硬盘上,每次读取数据库都需要在磁盘上搜索 ...