I'm having some trouble getting IntelliJ to output my packaged JAR file so I can run it directly from the command line.
Are there any free stand alone packagers which I can use to manually add all my JARs and specify my main class which will properly package the JAR? I'm really only interested in a packager, not an installer with fancy windows etc.
I'm using Ubuntu and developing JavaFX applications.
I did find these and these links... I'll give Install Builder and lzPack a go and hopefully report back with a positive result.
UPDATE
Install Builder seems to require a paid license to distribute your packaged jars. Unfortunately izPack does not seem to work when I execute it from the command line using Java 9. Crashes out.
Trying Oracle's javapackager command tool next.
Looks like I need to use Ant to deploy standalone JavaFX applications.
Related
I am attempting to build an application in NetBeans that can be deployed to and end user. I am still pretty new to deploying projects and this is by far the most complicated one I have done so please bear with me. I currently have a working application in NetBeans which utilizes JDK 15 and JavaFX 15. As long as I run things inside of NetBeans everything works as intended. I have reached a point where I want to make sure I can distribute this application outside of NetBeans. To this end I did some searching and found the following tutorial.
https://netbeans.org/kb/articles/javase-deploy.html
I was able to follow the tutorial and build the example. The build works in NetBeans, I am able to run the executable jar file in the dist folder from the command line, and I am able to run the jar file by executing it from the file explorer. Now when I attempt to do the same process with my own project I run into the following errors.
When I attempt to run the jar file in the dist folder absolutely nothing happens.
When I attempt to run the jar file from the command line using the command
java -jar "C:\Workspace\HandyAndyVersion1_2\dist\HandyAndyVersion1_2.jar"
I receive the following error,
Error: JavaFX runtime components are missing, and are required to run this application.
I am currently under the assumption that the first problem is a by product of the second. If anybody has a solution to this problem or any ideas on what I could have configured wrong please let me know and thank you all in advance.
To package a Java desktop application these days, you should be using the jpackage tool and optionally the jlink tool. These will generate a JRE image that is packaged with the application and contains the modules you need.
I suspect the issue you are running into is that the native libraries for JavaFX are not present. Most distributions of JDK 15 do not contain the JavaFX modules, though some do. (See the Full and FX bundles of the JDK from Azul and Bellsoft). I find it is easier to use a JDK with JavaFX bundled rather than have to manage a separate module path during development for the jmod files of JavaFX, but that is another option. Either method can be used with jlink to create a suitable JRE for your application that includes the JavaFX modules.
we have developed GUI tool using Java SE 11 , packaged using Maven. Recommend user to download and set Java in system path to launch the tool. Batch file for windows and .command file for Mac and Linux. Do we need to get notarize approval from apple to use it in Mac OS. Please advice
Thanks
You don't need Notarization for the script files. For your GUI Tool it highly depends on your projects dependencies. If your project only use common java packages, then everything should be fine. But there are libaries which require notarization. I personally had this issue with the net.java.dev.jna dependency. My experience is based on a jar bundled within an application. I am not sure if it is the same for a jar excuted from a script only. I recommend to just build your app and try to run it on a catalina machine.
I am working on a large JavaFX application which is due for deployment. I want to wrap the .jar files with Launch4j and create an installer using Inno Setup. However, I am having trouble with the process.
When using Launch4j, it spits out these errors (see 1). However, despite these errors, everything works perfectly fine using an MWE I created to verify that Launch4j wraps jar files properly. The MWE is just a small JavaFX application, where I use Launch4j to generate an .exe file and use Inno Setup to generate an installer. I can install this MWE with no issues using the generated installer and run the app. As mentioned, however, when I follow this exact same approach for my large application, which does have a lot more dependencies, I am not able to run the application after using the generated installer.
I searched for solutions to this and found this work-around using Inno Setup (see ban-geoengineering's answer):
How do I bundle a JRE into an EXE for a Java Application? Launch4j says "runtime is missing or corrupted."
I followed the steps mentioned but am still not able to run the application after generating the jar wrapper with Launch4j and running the generated installer created by Inno Setup. When I try to run the app, simply nothing happens.
Application information and development environment
The application utilizes custom-made java libraries developed in-house which act as an intermediary to communicate with a device's eSW through a custom interface. These java libraries and device drivers are needed in order to communicate with the device and need to be delivered with the application, as in included with the installer. I am using IntelliJ IDEA 2018.1 under Windows 10 Enterprise. The JDK is version 9.0.4.
Steps taken prior to using Launch4j and Inno Setup
I have followed the steps mentioned here https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html#package to package the application. I can successfully run the application via the commandline using java [options] -jar nameOfJar. The application needs certain VM options in order to communicate with the device drivers, and I am suspecting the issue lies here when generating the .exe file and generating the installer.
Addition 1
I have tried to add a custom classpath in Launch4j. It seems that Launch4j does identify the jars that the main class is dependent on, as it includes all the proper jar files (see 3).
I have in addition to this tried to mimic the JVM options I use to run the application via the commandline (see 4).
When executing the application it spits out NoClassDefFoundError and says it is due to the com/demant/gearbox/corona/model/GBCManager. However, this should already be included via the jar file com.demant.gearbox.corona.model.jar, as you can see in 3.
But, as you can see from both 3 and 4 the NoClassDefFoundError is still thrown.
Can I execute Eclipse Java development tools as a standalone process? I need to get Java program's AST structure using Eclipse JDT from another program, and to do that, I need to execute eclipse plugin as a stand-alone process behind the scene.
Is that possible? If so, how one can do that?
Eclipse/jdt and eclipse/ast is nothing more than a jar file, so one can use them to build standalone java application.
Example
I googled to find ASTExplorer as an example to make eclipse/ast plugin as a standalone java project.
The program was targeted for pretty old eclipse (3.0.2), I downloaded the 3.0.2 for Mac OS X this site - http://archive.eclipse.org/eclipse/downloads/drops/R-3.0.2-200503110845/
You need to setup ECLIPSE_HOME classpath variables in Preference -> Java -> Classpath variables
The .classpath has those classpath variables already, you can refer to this post - .classpath contents update in eclipse. As you can see it refers eclipse/jdt(art) jar files. I'm pretty sure one can change the reference to the newest version of jdt/ast without downloading the 3.0.2 version.
As I use Mac, I need to replace the swt for PC with swt for Mac. I could do that in BuildPath/Configure Build path
First remove the PC swt reference.
Then add the correct Mac swt reference.
Compile the example with the eclipse indigo/on mac
When the setup is correct, eclipse starts building the project. You can use Project -> Build Project menu. Then, you can check the application works fine in eclipse.
Generate the executable jar
Export to executable jar file.
You'll get some warnings, but you'll have a jar file.
Execute the generated jar
Just executing java -jar ast.jar doesn't work on Mac, I got a hint from this post.
Running SWT based, cross-platform jar properly on a Mac
In short, you need to run java -XstartOnFirstThread -jar ast.jar
Does it have to be Eclipses's AST? Or is any AST generation o.k.? If it doesn't have to be eclipse, I'd suggest Habelitz open source Java AST Compiler. http://www.habelitz.com/ I'm using it myself for some projects....
Well, of course you can launch eclipse just like any other process : How to create a process in Java
And then the problem becomes relaying the information back to the original process, which gets kind of messy. My suggested approach in this case would probably be to create a plugin in eclipse and have that plugin do whatever it is you think you need the AST for. You can work out messages with command line options to eclipse, or a shared file or something.
I'm new to the programming scene. Been working with C++ for about 5 months now, and have decided I want to start getting into Java. I'm using Eclipse as my IDE, and obviously Java for the language. I'm trying to write a simple HelloWorld application, which can be run through a command prompt executable.
In Visual Studio, it seems it's rather easy to create an executable. All I've ever had to do is use a pull down arrow and choose Release, and then run my build. The purpose of wanting to be able to write/run Java in command prompt is so that I'm able to practice some of the language basics before I go in full force with Swing.
So bottom line, what is the easiest way to create a command prompt .exe written with Java?
Thanks in advance!
Java doesn't natively allow building of an exe, that would defeat its purpose of being cross-platform.
AFAIK, these are your options:
Make a runnable JAR. If the system supports it and is configured appropriately, in a GUI, double clicking the JAR will launch the app. Another option would be to write a launcher shell script/batch file which will start your JAR with the appropriate parameters
There also executable wrappers - see How can I convert my Java program to an .exe file?
See also:
Convert Java to EXE: Why, When, When Not and How
Creating a native installer using jpackage
A java packaging tool named jpackage was released as part of the Java Development Kit (JDK) version 16.
This tool works in conjunction with native packaging tools for various platforms (e.g. WIX for Windows, RPM, and DEB for Linux distributions, DMG for Mac) to allow building native installers for Java applications which can then be run as executables. For distribution, it may be possible to distribute just the executable for the application, independent of the installer (I don't know, I didn't try that).
A nice, tutorial style, blog post that describes the use of the jpackage tool to create a native Windows installer for a Java application is:
How to create a Windows Native Java application (generating .exe file)?
Customizing the runtime image using jlink and jdeps
The packaging tool can (optionally) be combined with the jlink tool:
jlink - assemble and optimize a set of modules and their dependencies into a custom runtime image
This allows you to customize the runtime image for your application to only include the required custom selected modular parts of your application code, java runtime, and 3rd party libraries, rather than distributing a complete java runtime.
Optionally, you can also use the jdeps tool to determine inputs to jlink.
Complete discussion of usage of jdeps + jlink + jpackage + a native bundle creator (e.g. wix/rpm/deb/dmg) is outside of scope for a StackOverflow answer, but various resources can be found on the web if you search.
Creating a standalone .exe instead of an installer
This can be done using warp-packer to create a exe out of the image and app launcher created by jlink.
How to create a standalone .exe in Java (that runs without an installer and a JRE)
Third party tools can help deliver a solution
If you wish to use all these tools in combination, things can get complicated, and I'd advise using a 3rd party utility or template to help perform this task. For example:
badass-jlink-plugin (documentation) -> "allows you to create custom runtime images for modular applications with minimal effort. It also lets you create an application installer with the jpackage tool."
For JavaFX specific applications (as your question has a JavaFX tag), you could review:
JPackageScriptFX -> "demonstrates how projects can use scripts to build self-contained, platform-specific executables and installers of their JavaFX applications via the jdeps, jlink, and jpackage tools."
For native mobile deployments, see Gluon Mobile
This question was Windows specific, but for completeness, if your target is native application deployment on a mobile device, then likely you will need to use a 3rd party solution such as Gluon Mobile.
Background Rationale (ignore if not needed)
creating a native installer using jpackage might be a bit of work, so why would you do it?
Here are some reasons:
When an application is distributed via an installer created using jpackage, that application can be installed on a target system without requiring the user to manually install other dependencies (such as a Java Runtime). The installer will take care of ensuring that your application and any dependencies it requires are installed.
The application ships with its own customized version of the Java Runtime. This means that if the user doesn't install a JRE, and, if they have installed a version of the JRE which is incompatible with your application, your application will still function correctly.
The application can be installed and uninstalled using standard OS facilities for the target platform. Most users of those platforms are familiar with these.
Yes, Java is cross-platform for the most part, but many users don't care much about that, instead they just want a smooth and familiar installation (and uninstallation) experience for their application and jpackage can help accomplish that.
Typical Java programs compile into .jar files, which can be executed like .exe files provided the target machine has Java installed and that Java is in its PATH. From Eclipse you use the Export menu item from the File menu.
Creating .exe distributions isn't typical for Java. While such wrappers do exist, the normal mode of operation is to create a .jar file.
To create a .jar file from a Java project in Eclipse, use file->export->java->Jar file. This will create an archive with all your classes.
On the command prompt, use invocation like the following:
java -cp myapp.jar foo.bar.MyMainClass