One-JAR Quick Start

[b]Quick Start[/b]
There are various approaches to getting started with One-JAR. Ant users will find the "Application Generator Approach" most useful, Maven users the "Maven Approach", command-line tool users may prefer the "Command Line Approach".
[b]Application Generator Approach[/b]
This approach provides you with a complete Eclipse/Ant application directory, which you can use as a starting point for your own One-JAR application. The application generator is driven by a template built into the one-jar-appgen.jar file (see one-jar-appgen)

Download one-jar-appgen-0.97.jar
Generate application, build, and run it.

$ java -jar one-jar-appgen-0.97.jar

Enter project path (project name is last segment): c:/tmp/test-one-jar
Enter java package name: com.example.onejar

$ cd c:/tmp/test-one-jar
$ ant
$ cd build
$ java -jar test-one-jar.jar

test_one_jar main entry point, args=[]
test_one_jar main is running
test_one_jar OK.

Add source code to the src directory, library jars to the lib directory, and rebuild.
[b]Command-Line Approach[/b]
The use of Ant is not required: a One-JAR archive is simple to build using just the jar tool using the following steps.

Create a working directory to act as the "root" of the one-jar with main, lib sub-directories.
Copy your main application jar file into root/main and library dependencies into root/lib
Unjar the one-jar-boot-0.97.jar file into the root directory, and delete the "src" tree
Edit the boot-manifest.mf file and add a new line: One-Jar-Main-Class: your-main-class
cd root; jar -cvfm ../one-jar.jar boot-manifest.mf .

You should end up with a One-JAR archive which mirrors the "root" tree:

one-jar.jar
| META-INF/MANIFEST.MF
| .version
| com/simontuffs/onejar
| Boot.class, ...etc.
| doc/one-jar-license.txt
| main/main.jar
| lib/a.jar ...etc.

Thats it: no code to write, just a directory tree, some copy operations, and a file edit. The One-JAR classloader discovers the libraries and main code based on their position in the archive, and ignores any other Jar files should you need to embed archives which should not be on the classpath. Embedding the one-jar-license.txt ensures compliance with the BSD-style license.
[b]Maven Approach[/b]
There is a Maven2 plugin for One-JAR. It is easy to use for Maven projects. Please consult the documentation here: http://code.google.com/p/onejar-maven-plugin/
[b]Ant Taskdef Approach[/b]
Detailed use of the One-JAR Ant Taskdef is discussed here. Note that the one-jar-appgen approach uses the Ant taskdef.
[b]SDK Approach[/b]
Use of the (deprecated) SDK is discussed here
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值