Jar to exe with an external library

2019-02-19 10:40发布

I've been trying to convert a jar to exe. The program - the jar - uses a bluetooth library 'Bluecove' which is another jar in some directory. The program also uses Java Swing, typically JFrame and stuff. The program works perfectly when run from within Netbeans or Eclipse. It's time for me to deploy it, hence I need to convert it to exe. But I've been unable get the final executable to link with 'Bluecove'. I tried JSmooth and Launch4j , but with both, though I could complete the process and create the 'exe', the final program isn't running, because it can't find the Bluecove classes.

Any suggestions on how to get around this? None of these converters have any documentation about linking with libraries. Any help is appreciated.

Solution: Thanks guys for the answers! I used Andrew Thompson's suggested method to deploy my program, which worked beautifully. And to create the JAR, I preferred to have everything in one JAR, as suggested by Abdullah Shaikh. I used Fat-Jar Eclipse plugin for that.

4条回答
Explosion°爆炸
2楼-- · 2019-02-19 11:25

Make sure you added bluecove JAR into classpath when creating launcher: setting classpath in JSmooth, setting classpath in Launch4j.

查看更多
爷、活的狠高调
3楼-- · 2019-02-19 11:26

It's time for me to deploy it, hence I need to convert it to exe.

Those two statements do not make sense together. We cannot deploy a Swing desktop app. to *nix or OS X using a Windows based executable. The best option for deploying a Java desktop app. is typically from a link on a web page using Java Web Start.

From BlueCove Documentation: Installation:

Installation

BlueCove rely upon already installed native Bluetooth stack that comes with you operating system or Bluetooth USB device.

Installation of the binary (already compiled) version of BlueCove is as follows:

  • Download BlueCove binary release
  • Add bluecove.jar to your classpath
  • Also add bluecove-gpl.jar to your classpath if you are running application on Linux

This would imply something like the following. 2 Java Web Start based JNLP extensions:

  1. An extension for the BlueCove main API (bluecove.jar) to support Windows and OS X, as well as the core classes needed for Linux. This 'main' JNLP file would have a resources section specific to Linux, which in turn references the 'Linux only' extension JNLP.
  2. An extension for the Linux specific API (bluecove-gpl.jar) which includes an installer element to pop a license prompt for the user (if needed, this entire extension is necessary only for producing a license prompt). Here is a small demo. of the ExtensionInstallerService that would show a license agreement.

..would this require the user to always have an internet connection when using the application, or is it just the first time activation that requires internet?

The Java Web Start client (the app. that launches an appropriate JVM and your app.) would typically check back with the home server for updates to the application Jars relevant to that OS. Fortunately it is configurable as to when and how the check is done, and whether the application can be run 'off-line' as you require, by specifying an element in the JNLP:

<offline-allowed />

The offline-allowed element (part of the jnlp element) ensures that after initial installation, the app. can be used off-line.

查看更多
虎瘦雄心在
4楼-- · 2019-02-19 11:34

To resolve this issue you put all dependent jars inside your final jar file.
In eclipse, you can do this in following way: File -> Export -> Java -> Runnable Jar File -> (Select the option) Package required libraries into generated jar
Now use this jar to create an exe using any jar to exe converter of your choice!
hope this helps

查看更多
神经病院院长
5楼-- · 2019-02-19 11:36

Inside the jar you need to put all dependant jars or you can have manifest for your jar use the Class-Path header.

You can also try fat-jar extension or One Jar

查看更多
登录 后发表回答