Javapackager tool from command-line on OSX? - java

javapackager and javafxpackager don't seem to be recognised on the command line for me. They don't show up in the terminal, even after I installed the latest 1.8 SDK. (Even 'echo $JAVA_HOME' seems to be drawing a blank, though java -version seems to work fine.)
If I look under /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/ I can see the javapackager and javafxpackager tools are present, but if I follow /usr/libexec/java_home back to it's origin in /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/ , there's no sign of them.
The only other discussions I could find on the subject were a blog post and mailing list from about a year and a half back:
https://devreboot.wordpress.com/2014/11/26/java-desktop-app-packaging-automation/
http://lists.apple.com/archives/java-dev/2015/Nov/msg00009.html
I realise OSX hasn't come with java 'by default' for some time, but that's kinda why I was hoping to release my application as a self-contained bundle with it's own VM. Would it be standard procedure to update my bash profile to point at the tool explicitly? Is there something screwy about my personal setup, or is there some gap in the tool support on OSX?
PS: I realise there's an older thread on this subject below:
What is the best way to deploy JavaFX application, create JAR and self-contained applications and native installers
However, that describes javapackager as a .jar file, and whatever I've got doesn't seem to be a .jar file. I'm legitimately confused about what I'm supposed to do with it.
EDIT: Thanks to everyone for the tips- I think I have enough info to go on for now.

You could try this gist for building, packaging and running a test install on Java client apps from the OS X command line. No guarantees it will work for you, it was just something I whipped up for personal development purposes a long time ago. But, the info in there may help in resolving packager tool locations from the command line and also in performing other packaging related functions.
The key part for locating (and using) the javapackager is:
# select java version
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
$JAVA_HOME/bin/java -version
...
# make an executable jar file
$JAVA_HOME/bin/javapackager -createjar -srcdir . -appclass start.HelloWorldSwing -srcfiles HelloWorldSwing.jar -outdir . -outfile HelloWorld.jar
# package the jar and java runtime as a native application with installer
$JAVA_HOME/bin/javapackager -deploy -srcdir . -srcfiles HelloWorld.jar -outdir . -outfile HelloWorld -appclass start.HelloWorldSwing -native -name HelloWorld
Note, the above is for packaging a Swing application. Packaging a JavaFX application will use slightly different command line options for the packager.
Doing things this way from command line scripts is decidedly old school, usually maven or gradle is used.
My personal preference would be to just use Ant, but I guess that's only slightly less old-school?
Yes, not that there is anything wrong with that. Documentation on using Ant to package java client applications is provided by Oracle.

Related

Asking JRE to run a jarfile on launching the java.exe

I'm creating a game compatible with Discord's Rich Presence, and as Discord uses exe files to launch games, when I'm trying to launch my game from Discord, it starts the java.exe executable coming from the JRE instead of the jarfile of my game.
What I'm asking is, is there any way to copy jre (to bundle it with the game) and setup it to start automatically a specific jarfile ? If yes, how ?
If it's not possible, is there any way to launch a jar from an exe without launching java.exe separately ?
Thanks for your help.
Sorry for bad English, I'm french
Java 14 includes a packaging tool that allows exactly that. There are also tutorials available on how to do that, e.g. here. In short, something like this should work:
jpackage --input target/ \
--name MyApp \
--main-jar myApp.jar \
--main-class com.company.MyApp \
--type exe \
--java-options '--enable-preview'
If you are not yet using Java 14 but an older version, have a look at WinRun4J or Launch4J. Both allow creating exe-wrappers for Jar-Files, or creating an exe-file along with a JRE and a jar-File to run it independently. Those two only work for Windows, whereas the Java packaging tool will create executables for each platform (Windows, macOS, Linux) when run on the respective platform (it's not cross-platform capable, e.g. creating a macOS executable on Windows).
For macOS, there is appbundler which is able to create a .app with JRE and jar-File included, so users can just double click the application to start the java application.

Could not find or load main class com.nabinbhandari.lam.Main

I've read a lot of troubleshooting for similar occurrences of this error, but what is causing it for this particular .jar?
https://download.cnet.com/android/nabin-bhandari/3260-20_4-10982661-1.html
It works on Windows, but when attempting to run the file on a raspbian (linux) system running java version 1.8.0_65 with the command java -jar Local\ Area\ Messenger\ Desktop.jar it throws the error about not being able to find or load the main class.
The MANIFEST.MF defines Main-Class: com.nabinbhandari.lam.Main and there doesn't appear to be any issues with case sensitivity.
What am I missing? Do I need to install something more than Java Runtime Environment?
Edit: In case it is not clear, I am not the developer of this file. I am simply a user trying to run the file. This question has nothing to do with Eclipse and I don't understand why people are linking to that other question. I am not running Eclipse. Please stop linking to that. Please examination the .jar file I have provided.
Edit 2: I have followed the instructions and in this answer:
https://stackoverflow.com/a/1238173/2407742
It gives the error no main manifest attribute, in test.jar
Is there something missing from my java runtime environment? It seems like nothing works.
The Local Area Network Messenger application was developed using JavaFX, which is not included in the Oracle Java build for Rasperry Pi. I had to reinstall Java and then openjfx by doing the following:
sudo apt-get purge openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre
sudo apt-get install openjfx
It runs fine now.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.

java how to check version being used by 'jar launcher.app' on Mac OS

I have several .jar files that run successfully when opened with Mac's built in 'Jar Launcher' (Version 15.0.1) but when ran from terminal they error out.
Looking online the error messages might be down to the incorrect version of Java being linked to the terminal version, so I'd like to check if the options set for 'Jar Launcher' and the Java used within terminal are the same.
Does there exist any way to do this?
This question is two years old, but as there is no answer to it, I thought I'd put my two cents here since I've had issues myself, and have made some observations.
It seems that the Jar Launcher doesn't necessarily use the same JVM version as the one shown by the command /usr/libexec/java_home: If there is a JRE /Library/Internet Plug-Ins/JavaAppletPlugin.plugin, then the Jar Launcher will use it and ignore anything in /Library/Java/JavaVirtualMachines.
I've solve my problem of version mismatch between the Jar Launcher and the terminal by removing the JRE:
Go to /Library/Internet Plug-Ins.
Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
Go to /Library/PreferencePanes.
Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.
Source: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm

Android building: JarJar can't find or load main class

I'm trying to build AOSP from source (With a few modifications) but my build stops with
[ 0% 1/35196] JarJar: out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar
FAILED: /bin/bash -c "java -jar out/host/linux-x86/framework/jarjar.jar process external/conscrypt/jarjar-rules.txt out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-full-debug.jar out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes-jarjar.jar"
Error: Could not find or load main class com.tonicsystems.jarjar.Main
ninja: build stopped: subcommand failed.
make: *** [build/core/ninja.mk:149: ninja_wrapper] Error 1
and i can't get to fix it. My source is hosted here and the path of external/jarjar is the stock one on googlesource.
Can anyone help?
I had the same problem until I realized that it's due to the wrong path where com.tonicsystems.jarjar.Main is located. At ~/android/system, JarJar's com.tonicsystems.jarjar class is located in:
external/jarjar/src/main/com/tonicsystems
When it should be
external/jarjar/src/main/java/com/tonicsystems
Like it's source (from GitHub)
src/main/java/com/tonicsystems/jarjar
P.S: I had to create the external/jarjar/src/main/java directory and then move the source.
I've run into this with an AOSP fork (I think Qualcomm's tree) before - that was caused by the Makefile fragments that generate the file lists for the jar files not dealing properly with localized versions of the "sort" utility (causing removal of important class files in addition to the duplicates that were supposed to be removed).
I don't remember all the details or the proper fix, but the workaround that got me going initially was simply disabling localization while building.
rm -rf out
export LANG=C
export LC_ALL=C
export LC_COLLATE=C
. build/envsetup.sh
lunch whatever
make droidcore -j8
What fixed this for me was something completely unrelated to jarjar itself.
I was building AOSP 7.1.1 on Ubuntu 20.04. The default python command on Ubuntu 20.04 points to python3 [1], but AOSP 7.1.1 builds using python (which is really python 2.7.5).
I updated my system with sudo apt install python which linked the python command to python2 correctly instead of python3. After this, I built successfully.
AOSP is shipped with python under the prebuilts/python directory and I'm still confused as to why the build system doesn't point to that python version.
Edit
I had more trouble with adjusting my system to use the correct version of python, ultimately I had to add python and python3 as alternatives.
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
$ sudo update-alternatives --config python
Select python2

Trying to install zgrviewer to view DOT files

I am trying to install zgrviewer on my Ubuntu machine,to view DOT files. I have already installed java jdk 1.6 and Graphviz (sudo apt-get install graphviz).
The java installation path i notice after typing "which javac" is /usr/bin/javac.
I checkout the zgrviewer from sourceforge.net:
svn co https://zvtm.svn.sourceforge.net/svnroot/zvtm/zgrviewer/trunk zgrviewer
I am supposed to launch zgr viewer by running the run.sh script. The contents of the run.sh script is:
#!/bin/sh
# If you want to be able to run ZGRViewer from any directory,
# set ZGRV_HOME to the absolute path of ZGRViewer's main directory
# e.g. ZGRV_HOME=/usr/local/zgrviewer
ZGRV_HOME=/usr/local/zgrviewer
java -Xmx1024M -Xms512M -jar $ZGRV_HOME/target/zgrviewer-0.9.0-SNAPSHOT.jar "$#"
I am not sure how to edit this script to point to a specific Java Virtual Machine ; right now, it just says java and therefore uses the first JVM it finds in my PATH.
so when i run the script it says: Unable to access jarfile /usr/local/zgrviewer/target/zgrviewer-0.9.0-SNAPSHOT.jar
Please help me install zgrviewer successfully.
I like graphviz a lot, but I eventually gave up on the native "dot" viewers. Instead, I build (or obtain) graphviz with pdf support, and translate .dot to pdf. From there, many PDF viewers work well (and they tend to be more polished than dot viewers, probably because the need is more common), even for large documents. I'm mostly a gnome 2.x person, but I find KDE's okular to be the best PDF viewer I've encountered for large PDF's so far.
If this can help, I've written a guide on how to install a Graphviz viewer (ZGRViewer) and thumbnailer on Ubuntu/Gnome.
It is available at http://bernaerts.dyndns.org/linux/74-ubuntu/287-ubuntu-graphviz-viewer-gnome-thumbnailer
I've been able to use ZGRViewer 0.8.2 without any problem, but no success till date with version 0.9.0.

Categories

Resources