Find the running Jar File in a JPackage Program - java

How can I find the Jar File that my Program is running from, when it is being packed using jpackage (as a URI, URL or File)? I could easily do this on Windows because I know where it is going to be installed, but I would like to make this work on all platforms (Windows, Linux and MacOS). I am unable to experiment with this since I don't have a Mac nor a Linux Machine.
I want to be able to update my Application before/after starting it.
Thanks!

Related

Create executable OSX file on Windows for .jar file

I have created a java program (in Eclipse). I have successfully compiled it to a .jar file which I can run on windows without any problems. I want to give this program to a friend who has a MacOSX. So my aim is to:
Create a file which can be run on MacOSX
The twist is that I have to configure it on my Windows computer since I don't have access to a Mac. Any advice would be of great help!
I am not sure what you are referring as "create a file which can be run on macOSX"
If you want to run on any OS you just need a JRE on that particular system without it you cant run. It will provide a runtime environment to run a jar file. Then use below command to run the jar.
java -jar Myjar_file.jar

JAR is executed with terminal but not with direct clicking

I have tried the following:
in terminal it works
In Intellij it works
I have tried to launch it with javaw.exe but nothing changes
Are there any other options?
This looks like an OS problem that an application building one -- because you said that it works in your IDE and terminal.
Make sure that you installed Java properly in your machine.
In Windows/MacOs, after installing Java, the *.jar files are automatically associated with the java -jar command and makes it runnable via double-click.
In linux, this varies on the flavour or DE you are using. But there's probably a utility in your OS to open *.jar files using java -jar command.

How to execute Carrot2 Document Clustering server

I downloaded the Carrot2 Document clustering server build 3.15.0 for Mac. The read me file says:
The DCS requires a Java Runtime Environment (JRE) version 1.7.0 or later. To
run the DCS, execute the 'dcs' script and point your browser at
http://localhost:8080 for further instructions.
Mac OS Sierra doesn't make it easy, but I got 1.8.0_112 installed.
The problem is that I don't know how to execute the 'dcs' script.
There are .cmd, .sh, .war, and .jar files. I wasn't sure which of those to work with. I thought .jar looked promising, so I followed some of this thread and tried this in a terminal window:
java -jar invoker.jar
I cd-ed to the correct directory, but it just says Provide main class, but I'm not sure what or where that is.
Can anybody provide instructions or a link to how to do this?
Use the dcs.sh (on Linux/Mac) and dcs.cmd (on Windows) to start the server. The scripts will set some extra options for the JVM and then start the DCS. In case of any problems, append the -v option to see diagnostic output.

Creating a Native OSX Executable for Java from Windows

I have a program written in java that I'd like to provide native-style wrappers for. My target platforms are OSX, Windows, and Linux.
I have Windows and Linux working "good enough" right now. It'd be nice to provide a windows installer, a linux rpm, and a linux .deb, but for now I'm relatively satisfied with the package I provide to the user on those two platforms. I think it is relatively intuitive, feels native, and is easy to use.
For Windows
I use launch4j to create a native executable.
I package the native executable, jars, stripped JRE, and resource files in .zip
The user downloads the zip, extracts the folder inside, and double clicks the executable.
While this method doesn't have an installer, I feel it's "native-enough".
For Linux
I have a simple C++ program serving as a native 32-bit executable, which launches java targeting my jar file.
I package the native executable, jars, stripped JRE, and resource files in .tar.gz
The user downloads the .tar.gz, extracts the folder inside, and double clicks the executable (or calls it from the console).
While I think it would be nice to distribute via .rpms and .debs, and to provide native icon support for at least KDE and gnome, I'm also happy with this result for the time being.
Here is the native executable code, for anyone who is interested.
/*Compile this on a linux machine to create a local nix executable
g++ -m32 -o executable-name this-file-name.cpp
-m32 forces 32 bit mode, which should help compatibility
*/
#include <stdio.h>
#include <cstdlib>
int main() {
int result = system( "java -jar TARGET_JAR.jar 2> /dev/null > /dev/null " );
if ( result != 0 ) {
printf ( "PROGRAM_NAME requires Java, but Java isn't in your path. Please make sure Java is installed and 'java' is visible in your path. Once you've done that, please run this executable to run PROGRAM_NAME!\n" );
}
}
I intend to modify this for the upcoming release to also use an embedded jre, but that is a trivial change.
For OSX
I don't have a working system yet. Here is what I'd like:
User downloads a .dmg file, which contains an .app.
I'd like for the .app to:
Have an embedded JRE
Be double clickable
Build can be automated with ANT.
My previous attempts at creating this app failed miserably. I tried:
Appbundler: I could not get the examples to work. I believe the source of the problem was working in a windows environment, but perhaps I was just doing things wrong.
Rolling my own .app: This failed, as you can see in the thread.
javapackager (included with java 8): I similarly could not get this to work. As it's a new tool, there is a sparsity of examples in the wild, and the tool seems immature and focused on webstart; the windows installer I got when trying to create the native windows package was primitive and I could not get it to include other non-jar resources.
webstart: I don't want .jnlps. I can't have icons or embedded jres.
I feel like there should be an easy way to roll my own .app. As far as I can tell, apps are just directories with special structures and a Info.plist.
However, I'm open to any suggestions that work. In the end, as long as I get a package that feels native on OSX and can be automated with ANT, I'll be very happy.
Thank you!
You will need a Mac computer with Xcode installed in order to do this.

java.lang.RuntimeException: Registry initialization file not found

When I work with JAI from the Eclipse (all the classes specified)
it works very fine, but when I bundle everything in a jar and make a shell script file from that and try to run that script I have a problem with javax.media.jai.OperationRegistry
looking for a initialization file.
Has anyone else seen this problem?
Exception:
java.lang.RuntimeException: Registry initialization file not found.
at
javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:365)
at javax.media.jai.JAI.(JAI.java:566)
There is something on this page but I was not able to understand.
Any Help?
So the problem is that the JAI jar exported with the Java application do not work on the Linux. We have to explicitly install JAI on the Linux machine for the installed Java application to use.
The one solution that we found out is we exported our Java Application into a jar file and created a installation script, which when run on the Linux machine install the JAI first and after that it install our application.
So this is a one time installation process while installing the application on any fresh Linux machine.

Categories

Resources