How to make an Executable ".exe" file from a java Code - java

I have an application that works fine and that I can execute from a .jar file. But I want to know how to make it runnable from any computer even if there is no JRE or the JRE version is not the good one. I thought about a .exe file but don't know how to do it.
I made my code with Eclipse and it use jxl,jdom and jfx librairies.
I tried to use Inno Setup 5.5.6 but when in Eclipse I run my build.xml as Ant Build it return me an error that says :
"'Launching JFX Build - Myapp' has encountered a problem.
The achive : C:/Program%20Files/eclipse/plugins/org.eclipse.swt.win32.win32.x86_64_3.104.0.v20150528.jar which is referenced by classpath, does not exist."

JavaFX provides specific utilities for bundling your application as a native package, which is referred to as "Self contained application packaging". These utilities are provided as a command-line tool, or as ant tasks. Additionally, the common IDEs support this via wizards, either out of the box (NetBeans) or via a plugin (e(fx)clipse for Eclipse). The details of how to use any of these are far beyond the scope of a stack overflow question, but the basic documentation is available here. A tutorial for e(fx)clipse is here.
Briefly, for e(fx)clipse, you should double-click the build.fxbuild file that is created in your project. Under the "Overview" tab, find the "Packaging format" option, and select "All" (or the specific type of package you want to create).
Note that you can only create a package targeted at the platform on which you are building, so if you want to create packages for windows, Mac, and Linux, you will need access to all three types of machine.

I know I am late. I faced same problem a trick worked for me. Look at the given directory in the error message. It contains a space (C:/Program Files/...). Move your e(fx)clipse to another directory where the directory doesn't contains any space.
Not sure it will work your everyone or not but it worked for me.
Thanks

There are various tools that let you wrap your Java application in a Windows executable. Some tools are only simple installers, others allow you to bundle your application with a specific JRE version.
A widely used but commercial tool is install4j, but there is a bunch of other tools, such as WinRun4J.

Related

Journey browser Java Chromium Embedded framework throwing error?

I am trying to use a library called Journey browser which uses the Java Chromium Embedded Framework. I first created a Java Maven Project with Netbeans and I edited the pom.xml to match the values on the library's guide, which is here: https://github.com/CodeBrig/Journey, to add the maven dependencies. (No errors detected by Netbeans) I then built the project to download the maven dependency and put their default code (modified slightly) in the main class. Netbeans found no errors in the code. However, when I run the project I get a "no chrome_elf in java.library.path". I think this has something to do with embedding JCEF, but I am not sure how to add this to the "java.library.path" in Netbeans.
How do I fix this "chrome_elf" problem?
Also, if I am able to fix this will it be an error for production if someone doesn't have "chrome_elf" installed?
For Windows
This happens because the chrome_elf.dll (on Windows) file cannot be found.
Java is looking for this file on java.library.path - which (on my machine, anyway) refers to all the locations referenced by the Windows %path% environment variable.
One way to fix this is to download one of the pre-built distributions from that GitHub page (for example the Windows one, referred to here):
https://github.com/CodeBrig/Journey/releases/download/0.4.0-78-assets/jcef-distrib-windows64.zip
Then unzip the resulting jcef-distrib-windows64.zip. In the win64\bin\lib\win64 directory under that main directory you will find the chrome_elf.dll you need - and other binaries which are also needed.
Add this directory to your path - either by adding it to the Windows environment variable or via java -Djava.library.path=....
For example, the path may be similar to this:
C:\your\path\to\jcef-distrib-windows64\win64\bin\lib\win64
This should allow you to run the demo code provided in the JourneyBrowser class. A browser window should open as a result.
Here is the browser:
The above steps worked for me - and the only files I needed to keep from the (large) distribution download were those in the jcef-distrib-windows64\win64\bin\lib\win64 directory. It's possible that I already have some other dependencies which may be needed - so I cannot guarantee this process will also work for you.
For Linux (and MacOS)
I have not tried this on a Linux machine. But in that case, I believe you will need to download and unzip the jcef-distrib-linux64 release - and then point to the jcef-distrib-linux64\linux64\bin\lib\linux64 directory, containing libcef.so and other libraries.
Similarly for MacOS, there is a distribution which can be downloaded and unzipped.
Alternative
An alternative is to simply use the pre-built distributions provided on GitHub, using the commands provided. Obviously, in this case, you will not be creating your own customized implementation (so, no JourneyBrowser class).
copy scr/native/Release to jcef_build/native/Release from the default output directory of VS.check whether the Release exists in java.lib.path

How to get Java standalone app with eclipse? [duplicate]

I've recently started learning SWT (on class #4, to be precise) due to business requirements, and previously I had been developing with Swing for 2 years.
We deployed Swing applications as jars with resource dependencies. In SWT, what are the deployable forms and equivalents?
I have questions but since my training is online, I'm on a course-ware and there is no instructor, except StackOverflow:
Can SWT apps be deployed as independent EXE's? And what's with the "Eclipse EXE" thing people talk about? Does it mean that all SWT outputs will be Eclipse based EXEs? Or can they be completely independent EXEs?
If the answer to 1 is yes, how does the compiler produce native win32 executable code? This is one area where I'm thoroughly confused. Typically, a deployable jar is fed to the VM which reads the manifest and does its stuff, but an EXE as output? What's really behind the scenes?
How are external resource bundles managed? At the time of deployment?
Internationalization support?
Thanks.
Deploying an SWT application is exactly like deploying a Swing app, with the addition of several jars and a native library. You must currently be using some tool to make exe files for your Swing app; that tool may or may not be competent to also package up a native code library. It is unlikely that the tool is creating 'native win32 executable code'. Rather, it is packaging up Java class files along with the JRE and a stub Windows PE file.
SWT is developed as part of Eclipse. Eclipse has the Rich Client Platform, or RCP. If you build your Java application as an RCP application, you can use the Eclipse tools to generate an executable package for Windows (or anywhere else). It is not a single executable, it's a directory with an executable in it. However, you don't have to use Eclipse to use SWT.
An RCP application has to use much more than just SWT. It has to be constructed as a set of OSGi bundles that depend on the core Eclipse platform. Once you have such a thing running inside Eclipse, there is a wizard in Eclipse that will create a Windows 'executable' (a directory containing your code in JAR file(s), a lot of Eclipse code in JAR files, the JRE, and a PE .exe stub). You can automate that process from ant, though I've never done it myself. You will need to do book-length reading to get up to speed on all of this, I fear.
There no difference between SWT and Swing in terms of resources and internationalization. Other Eclipse-related libraries include an I18N discipline, but not the core SWT. You just use locales and property files as in any other Java application.
SWT is not Eclipse-based, but the Eclipse UI is SWT-based. Eclipse uses the SWT library for its drawing. It is used a GUI library from the Eclipse consortium, available for many systems. If you want to deploy your normal Java Application with an SWT GUI you just add the corresponding libs and .dll's or .so's. Therefore, everything you can do (deployment) with Java respectively speaking Swing, can be done with SWT, if you provide the according libraries. There are tools and ways to compile everything into .exe's but that is not necessarily needed.
I do not really get the Eclipse EXE thing you are talking about, but eclipse just provides a starter exe, which is basically just a wrapper. Otherwise, some people refer to Eclipse RCP als Eclipse EXE but this is not correct. You CAN use the Eclipse RCP to base your App and this would use SWT as UI library. But you can use SWT all by yourself just as library without the Eclipse trail.
I hope this helps.
You can use a java to EXE wrapper like this one http://jsmooth.sourceforge.net/.
Hope it helps.
Basically you need to get your project running with the conventional java -jar command.
Then create an exe bootstrap program that runs the command when you double click it.
Extra things can be done like checking JVM versions inside the exe program.

Setup file for application using QT Jambi

I want to use QT Jambi for GUI (Java project). The GUI needs to have animations (similar to Iphone apps). That is why, I do not want to use Java Swing.
My question is, after I develop the application, is there any automatic mechanism which would create a setup file which could be used to install my application in any computer (may be separate "setup" files for separate OS). In other words, I would like my users to download just one file: setup.exe. This should install the app in their computer.
I know there is one such app for .jar files (I forgot the name). But QT is a C++ library and I do not like bothering the users, asking them to download QT just to use my app.
I presume you are tagetting win32 only on the desktop and looking for free/open tools. With no response to this questio so far I thought I'd provide some info towards this point even if it is not the answer you really want.
I have been looking over the QtJambi ecosphere for the past couple of years and I'm not aware of such a tool to provide you with a process to follow that results in an EXE. There are all kinds of caveats.
The task:
Ensure the JRE5+ is installed on target system.
Ensure QtJambi files and perform things like extraction of native JAR.
Ensure QtJambi pre-reqs are installed on the target system (such as MSVCxxxx runtimes).
Finally install your application and fixup the startup configuration to make use of information above.
Setup desktop fo reasy access (Program Group, Desktop Icon, Menu items, Shortcuts)
You will find that NSIS http://nsis.sourceforge.net/ can be a tool to get some parts of the process and maybe provide a framework to write modules for NSIS that do other parts of the work. But I have found NSIS somewhat lacking when you step outside of a simple unzip of data and setup of desktop install process.
Another solution for you would be to simply provide everything that works in one ZIP file, this would include a copy of the Java JRE embedded, a copy of QtJambi embedded, the rest of your JAR and then write a toplevel *.BAT file to setup %PATH% and other arguments to run your supplied java.exe against your application. Obviously now the JRE is not likely to get updated so at some point will be considered insecure.
NSIS isn't the only such windows installer that exist.
Maybe there is a fully automatic one click install wrapper with custom parts to help setting up QtJambi, but I doubt it at this time.
Good question, and one good attempt at an answer.
I've gone down a slightly different route: embed the Qt Jambi libraries, but not a JRE. I have some basic sh/bat launch scripts which configure the resources required and am using IzPack for the installer (though NSIS might be a good alternative).
Problem: how to find the JRE
Solution: the IzPack installer needs a JRE to run, so guarantees the availability of one. It can update a variable in scripts during installation.
Solution (Windows): use the registry
Last resort: use the path
The ideal would be to integrate all three into a batch file. Anyone done this?
Problem: Qt & Qt Jambi libraries
Solution: distribute with your application and link from the shell/batch file.
The problem with this is how to make sure your libraries get used when binary-incompatible Qt libraries are already installed on the system. On Linux, extracting the libraries and exporting LD_LIBRARY_PATH seems to work. On Windows I haven't solved this and on the Mac I haven't tried.
Problem: most appropriate Qt libraries
32-bit Qt libraries probably won't work with a 64-bit JRE; this is a problem I haven't yet had to deal with. Probably the best solution would be to include both 32-bit and 64-bit Qt libraries and select between them from a script at run-time (or possibly install-time).
Another issue is related to themes: Qt has support for using native themes, but only from the platforms it's compiled on. Thus, compiling Qt on an old Windows version and using the libraries on a modern version of Windows seems to work but results in ugly Windows-98-esque widgets. The easiest solution seems to be to launch with -style Plastique (or cleanlooks) to get nicer-looking widgets.

Java lib to change the icon used by an .exe

We have a netbeans-platform application, that creates a custom runnable .exe with the default NetBeans icon - as you can guess, when customers install it, they are not happy.
This NetBeans Wiki article and this NetBeans Bug (closed as wontfix) indicate that the platform can't do it natively, and suggest the use of a third-party executable to do it.
However, having a binary executable in our svn repo being called by maven during build time leaves me (and my boss) quite unhappy.
Is there a library in Java, preferably available in maven, that can change the icon an .exe file uses?
EDIT: Upon further research, I found this SO question... that wasn't answered either.
EDIT2: We are also not looking for another packager that can create an .exe for us. We are happy with the default NetBeans' Platform one, and it's already quite well integrated with our dev/release cycle.
It's not a library that accomplishes what you want, but the closest I could find was this - it'll read PE files and it's open source and Java. You may be able to look through the source to find the code that you need.
If you are already using maven you might use launch4j for creating an .exe. There is a maven plugin available. You also might take a look at this netbeans plugin.
Is there a reason you're not simply calling Window.setIconImages() on startup, and loading some images, possibly stored right within the JAR?

How do I create an Installer for a Java Application?

This is still awhile down the road for me but for my Project Implementation class we have to create a program and then distribute it. I have written an application in Java and from the specification I have made in the previous class (Project Design) my application will need to be platform-independent.
For mac and linux the user can just run the jar file from the terminal, but for windows I would like to have the Application installed to the path user chooses (default: C:\Program Files(x86)\NameOfApplication), Create a desktop shortcut (if the user wishes to have one), install under the start menu (if the user wants it to) and then also show up in the add\remove programs list.
Is there any easy way to do this?
Is it any harder if I did decided to create an installer for mac and linux?
Thanks in Advance.
You can create an installer with NSIS, even for a Java application.
You might also consider distributing your application via Java Web Start.
There are opensource installer generators for java. I have never used one before. Here is a good resource of links
I recommend using Java Web Start.
It has several advantages.
Available for all major desktop platforms
Single distribution for all JWS-enabled platforms
Code-signing and sandboxing
Versioning and incremental updates
Automatic installation of JREs and optional packages
It has one major disadvantage.
Internet connectivity is required if JWS, JRE, and/or an Optional
Package is not present on the system
Have a look here and here
Install4j does what you want, although you have to pay for it. Personally, I am not aware of any free alternatives. You can make installers for Linux and Mac OS as well.
you can use Exe4J, see http://www.ej-technologies.com/products/exe4j/overview.html
You can do most of that using standard JNLP:
http://docs.oracle.com/javase/1.4.2/docs/guide/jws/developersguide/syntax.html
You make a JNLP file that takes the executable JAR from some local (or remote) location and creates a Desktop icon for it (of your chosing). Only difference is that the actual JAR will be placed in the JDK's jar cache directory (not in a directory of your choice - I don't think the user would care much).
The huge advantage with this is that if you make a JNLP that installs the jar from a remote location, you can remotely upload a new version of the jar to that location, and when the user next accesses the jar locally, your latest version will be downloaded and placed into local cache.
Also I recommend you use a smart "fat JAR" builder, which packages all dependency jars inside the executable jar. Eclipse IDE has a way to export a project in this format (and also adds the necessary class-loader so that all works ok from on fat jar).
If your target OS is windows I highly recommend Advanced Installer. It's very very easy to use and will let you create your own native microsoft installer (.msi) with specific target Java VM and a bunch of useful windows features, even in the free version. Note you can also include a private jre into the package.
http://www.advancedinstaller.com/top-freeware-features.html
If you want a "package one deploy everywhere" solution then IzPack is the way to go, platform independant, free and open source.
http://izpack.org/
Depending on the complexity of your project Java Web Start could be a very good option, it's very simple configure and maintain but it relies on the browser's java plugin and believe me... most users DON'T like being warned about certificates and risks everytime they launch an application.

Categories