To jar or not to jar?

http://www.javaworld.com/javaworld/jw-07-1998/jw-07-jar.html 

 

 

DOS batch files to compile and run a Java program (and create a jar file)

This isn't the most high-tech way to do things, but I thought I'd share these Windows (DOS) shell scripts that I'm currently using to compile a Java application, create a Jar file to distribute the application, and finally run the application. I ended up creating these scripts because of configuration problems on my Windows PC, but I thought they might be useful samples for others.

As you'll see the mostly correct problems with my JAVA_HOME, PATH, and CLASSPATH configurations. I should use an Ant build script for this, but I'm too lazy today. I'm also overriding my Java compiler settings on this PC, as I have several Java versions installed on this system.

Here's the first script I named 1compile.bat that I use to compile my Java program:

set JAVA_HOME=C:/jdk1.5.0_06
set PATH=C:/Windows;C:/Windows/System32;C:/jdk1.5.0_06/bin
set CLASSPATH=

javac -cp ".;forms-1.0.7.jar" com/devdaily/xylocator/XYLocator.java

Here's the second script I named 2createJar.bat that I use to create a jar file that I distribute with my Java program:

set JAVA_HOME=C:/jdk1.5.0_06
set PATH=C:/Windows;C:/Windows/System32;C:/jdk1.5.0_06/bin
set CLASSPATH=

jar cfm xylocator.jar Manifest.txt com/devdaily/xylocator/*.class

That command also requires a file named Manifest.txt, which looks like this:

Main-Class: com.devdaily.xylocator.XYLocator
Class-Path: forms-1.0.7.jar

The first line in the manifest file tells the JVM where to find the main method to run my program, and the second line helps configure the CLASSPATH, which is required because this is a Java Swing application that uses the JGoodies FormLayout.

That script creates a jar file (with the manifest included) so I can just use the java -jar command to run my program. I include that command in a batch file I named 3runJar.bat that looks like this:

set JAVA_HOME=C:/jdk1.5.0_06
set PATH=C:/jdk1.5.0_06/bin;C:/Windows;C:/Windows/System32
set CLASSPATH=

java -jar xylocator.jar

FWIW, I'm actually very lazy, as you can tell from the file names I've shown. I use the 1, 2, and 3 as filename prefixes to remind me the order things should be run in later. That's pretty lazy. :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值