How to Run a .Jar Java File
.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:
- 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.
- 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]
- 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]
- 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
- 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."
- Execute the following command: $>java -jar [jar file name]
- 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的更多相关文章
- How to Convert a Class File to a Java File?
What is a programming language? Before introducing compilation and decompilation, let's briefly intr ...
- 转:Java.file
类 java.io.File 的使用 使用 File 的软件包 java.awt 包含用于创建用户界面和绘制图形图像的所有类. java.io 通过数据流.序列化和文件系统提供系统输入和输出. jav ...
- jar -- java文档归档工具
参考文档 http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/jar.html http://blog.chinaunix.net ...
- Java File类总结和FileUtils类
Java File类总结和FileUtils类 文件存在和类型判断 创建出File类的对象并不代表该路径下有此文件或目录. 用public boolean exists()可以判断文件是否存在. Fi ...
- Java File 类的使用方法详解
Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对Java File文件操作类进行详细地分析,并将File类中的常用方法进行简单介绍,有需要的Java开发者可以看 ...
- Java File 类的使用方法详解(转)
转自:http://www.codeceo.com/article/java-file-class.html Java File类的功能非常强大,利用Java基本上可以对文件进行所有的操作.本文将对J ...
- 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 ...
- 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--------------------- ...
- Java:Linux上java -jar xxx.jar&java -cp 区别
java -cp java -cp 和 -classpath 一样,是指定类运行所依赖其他类的路径,通常是类库和jar包,需要全路径到jar包,多个jar包之间连接符:window上分号“;”.Lin ...
随机推荐
- aop前传之代理
一.jdk提供proxy类对目标对象实现代理,简单的说对方法的调用交给代理对象来操作. 代理目标 代理的具体实现: 代理测试; 简单说:利用proxy生成一个委托类实现代理.这个委托类是目标类的接口的 ...
- jquery使用技巧
1. 禁用右键点击(Disable right-click) <!DOCTYPE html> <html> <head> <meta charset=&quo ...
- linux之稀疏文件
1. Sparse 文件是并不占用磁盘存储空间. 2. rm 某文件后, 文件占用的磁盘空间并不是立即释放, 而是其句柄没有被任意一个进程引用时才回收. 3. ls 的结果是 apparent siz ...
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
Android 高手进阶(21) 版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明出处:http://blog.csdn.net/xiaanming/article/detail ...
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
Android 高手进阶(21) 版权声明:本文为博主原创文章,未经博主允许不得转载. 转载请注明地址:http://blog.csdn.net/xiaanming/article/detail ...
- 解决Win7中第一次HttpWebRequest连接缓慢、超时等问题
在使用HttpWebRequest的时候发现,第一次连接需要15S左右,我的系统是win7,很崩溃,除了我那个用户可以等待的了,但是第二次,就没有问题了,于是百度之...... http://www. ...
- hiho_1061_beautiful_string
题目大意 题目连接:beautiful string 写代码之前,考虑清楚流程,以及需要维护的变量.... 实现 #include<iostream> #include<st ...
- js setTimeout 与 setInterval 以及 for 循环 刷新UI
1. setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式:执行一次: 如果需要执行多次,自身再次调用 setTimeout(): 示例:无穷循环并带停止按钮的 <html&g ...
- mac 下基于firebreath 开发多浏览器支持的浏览器插件
mac 下基于firebreath 开发多浏览器支持的浏览器插件 首先要区分什么是浏览器扩展和浏览器插件;插件可以像本地程序一样做的更多 一. 关于 firebreath http://www.fir ...
- C# 给软件加注册码功能
为自己写的程序加一个注册功能吧.生成的机器号是根据CPU和硬盘号来的,根据自己的需求改成是否是随机生成. 代码直接粘贴到新建类覆盖原代码就能直接用了. using System; using Syst ...