Jpackage issues - Not running - java

I should preface this by saying I'm a novice who got in way too deep trying to make a Swing app an exe. After reading the docs I've sort of gleaned what the meanings of all the parameters are, but I'm still confused. What I'm trying to achieve is an application that can be double clicked and launch the GUI, without creating a JRE (if it is not necessary) No jfx so it is non modular.
I tried to use these following commands:
jpackage --type app-image -i "C:\Users\User\quadAdventGame\out\artifacts\quadAdventGame_jar" -n quadGameTest --main-class Main --main-jar quadAdventGame.jar
Then using that app image:
jpackage -n name --app-image "C:\Users\User\quadGameTest"
This resulted in two things: The installer ran, Norton Antivirus flagged it, saying it stopped the process, and then I told Norton to let it go. Then the installer failed to run, saying it had no access to "main.msi" in my Local disk. I also tried direct msi installing,
jpackage --type msi -i "C:\Users\User\quadAdventGame\out\artifacts\quadAdventGame_jar" -n quadGameTest --main-class Main --main-jar quadAdventGame.jar
which simply doesn't run when double clicked.
BTW, here's what the generated folder looks like, which seems like it may be wrong.
My questions would be:
Is Norton some how involved in the stoppage of my app from running? I'm not sure what Main.msi is in my temp folder.
Are my commands wrong? It seems like they are not correct for what I want to achieve, which is just a simple runnable application. The code is baby stuff, this is literally just me trying to prove I can do this. Does the main class input need to have the .java prefix? It honestly might be me just naming stuff wrong, but the generated folders have a jar that runs fine.
If so, how can these commands be remedied?
I am on the Oracle JDK 14.

Related

.jar file is not working after being published from Eclipse [duplicate]

There was a program that I used that made runnable .jar files.. All the ones I'm finding now are ones that make .exe files.. I remember it also has the option to make the file a .sh script as well. Anyone knows its name? I've been searching for hours with no avail :/
The command line
java -jar file.jar
Will run your jar file if it has a Main-Class defined as explained here.
You can use that command in a shell script.
You can create a runnable jar using NetBeans IDE or Eclipse IDE by just providing the main class to run. Rest of the things it will take automatically. That class must be having a main() method in it. Then you can run that jar file using java -jar yourjarfile.jar
Do you mean actually coding java and then compiling to .jar? If you do try
eclipse code editor
I used eclipse to make minecraft mods. It will work if you want to make .jar programs.
If you want to have a jar that you can execute using the usual syntax ./app.jar (instead of java -jar), here is a post explaining the process: how to create executable jars.
Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it "executable".
Here is a simple example of the process:
# Append a basic launcher script to the jar
cat \
<(echo '#!/bin/sh')\
<(echo 'exec java -jar $0 "$#"')\
<(echo 'exit 0')\
original.jar > executable.jar
# Make the new jar executable
chmod +x executable.jar
With this, you can now run ./executable.jar instead of java -jar original.jar. This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.

how can I run a jar from /usr/local/bin like a Terminal command?

I have made a calculator CLI calculator app in Java that I would like to use. Since I am actually going to use it quite often, I do not like the idea of typing the long path all the time.
I have read an article on StackoverFlow that you can place a .sh command into the /usr/bin folder, but after the El Capitan update, all System folders are locked even for the root user. So, again, I did some more research, and I found that /usr/local/bin folder is specifically made for "home-made" commands for the terminal. I have made a calculator.sh file with the following code:
#!/bin/sh
-jar /Users/mac/Desktop/Данила/my_apps/calculator.jar "$*"
The article said that I should place it in the /usr/bin folder, but because it is locked, I placed it in the /usr/local/bin, thinking that it is practically the same thing, and that it should work. Of course after I placed it in there and tried to run "calculator" command in the terminal, it did not work at all. I figured that it might need a "chmod" command to make it work. So I used chmod +x /path, but afterwards it still would not work. Right now I am stumped, so any help would be welcome.
First, is /usr/local/bin on your path? echo $PATH to find out.
Second, are you sure you pasted the above script properly?
It seems to be missing java on the command line.
I would expect it to look something like:
#!/bin/sh
java -jar /Users/mac/Desktop/Данила/my_apps/calculator.jar "$*"
Also, since you named it calculator.sh, you have to run it using that name.
The .sh extension isn't needed, so you could just call it calculator.
To this I recommend you create an alias.
alias test="java -jar /full/path/to/jar.jar"
And "test" is a command now, if you like get this command allways add it into .bash_profile.

Runtime exec issues in Linux

In an application I am writing, I am launching another application (a runnable JAR) using Runtime.exec(...). Everything launches successfully in Windows, but Linux (specifically certain installations of CentOS - works in Ubuntu) has been giving me some problems. For some reason, the only way the secondary application will successfully launch is if I execute the first through a terminal. All behavior works as expected. However, if I launch the first application by double-clicking its icon (without a terminal open), the button to launch the second application seems to do nothing. I get no exceptions or error output - just a flash of my progress bar saying that it is launching, and then nothing. I can confirm through jconsole that the second application's process is never launched.
I have seen the commonly linked article on the pitfalls of the exec method ( http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html ), but have not been able to solve this problem with anything I have found there. I am in fact reading the output and error streams of the second process, as I see all output when it successfully runs (after launching the first application through a terminal command). Not knowing a lot about deeper workings of Linux, I think this sounds like it may be a permissions issue with the output stream or something, but I am not sure.
In case it helps to diagnose the problem, I am using the command:
rt.exec(new String[]{"\bin\bash", "-c", "java -jar myjarfile.jar myArg1 myArg2 ..."}); Since this works (depending on how the application is launched), I'm not too concerned that anything is wrong with this piece of code...
Anyone have any suggestions? Thanks in advance!
EDIT: The solution was to fix the directory to the JAR I was attempting to run. When launched via the GUI, user.dir was pointing to the parent directory of the folder containing my application. Since I'm using Eclipse RCP, my solution was to use
String currDirPath = Platform.getInstallLocation().getURL().toString(); instead. Thanks for the help everyone!
Since you're just using the jar file name - myjarfile.jar - and not the full path to it, depending on the current working directory, the jar may or may not be found. Try changing your exec command to use the full path to the jar instead. You can debug this by using rt.exec() to write the output of 'pwd' to a text file.
instead of
rt.exec(new String[]{"\bin\bash", "-c", "java -jar myjarfile.jar myArg1 myArg2 ..."});
use
rt.exec(new String[]{"\bin\bash", "-c", "/***path to java***/java -jar myjarfile.jar myArg1 myArg2 ..."});

Execute *.java or *.jar on PHP at website

I have already can execute *.java or *.jar on PHP at my xampp, with this code
exec('java -cp stanford-parser.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser stanford-parser-2012-03-09-models\edu\stanford\nlp\models\lexparser\englishPCFG.ser.gz text.txt > result.txt');
it's localhost in my computer.
And now I want to hosting my coding into website internet. I'm afraid the java don't want to execute and run the exec line. What should I do to make exec *.java or *.jar can run on website?
I hear that I must install tomcat or javabridge. But I don't understand. can you help me? thanks very much.
You don't need tomcat to run the above command, you should be able to run it just like you do on your own machine as long as java is installed on the server you're running on. Of course, you'll want to make sure your paths are set correctly, and even then this is not a good idea, especially if you expect it to be hit by a lot of traffic or if it takes a significant amount of time to complete (> 5 seconds).
The easiest way to do this the 'right' way is to kick off a long running process (outside of the Apache/php request and set some type of flag or indicator when it is complete. You can have the browser refresh if you want them to be immediately notified when it is completed. A simple way to do this is to run the command above as a background process (append & to the end of the command as shown below). Of course, this leave out a lot of error handling that may need to be done.
exec('java -cp stanford-parser.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser stanford-parser-2012-03-09-models\edu\stanford\nlp\models\lexparser\englishPCFG.ser.gz text.txt &> result.txt');

Trying to run a java application from a shell script on Ubuntu 10.04

My java program was written on a windows machine and I am trying to get it installed and running on a Ubuntu 10.04 machine. I have created a .tar.gz file with myProgram.jar in it as well as 5 supporting library .jar files in a lib folder. Where do I put these files? Do I need to extract it on the Linux machine to a usr/bin folder? Does the shell script go inside the tar.gz? I have read that if you write the shell script on a windows machine you can have issues once you move it to the Linux machine, so I am writing the shell script on the Linux machine using gedit. I am just not sure what to do next.
So far in my script I have,
#!/bin/bash
java -jar myProgram.jar
I am going to try and extract the tar.gz file to the usr/bin directory and see if it runs.
Any suggestions or help would be greatly appreciated.
Thanks in advance,
Ray
Your question is quite "broad" :). I hope you find the following useful.
Do not extract the files to /usr/bin. See e.g. http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard on where and where not to put files on a *nix system.
Extract the jar's to e.g. /opt/yourProgram/*.
The shell script should be inside there too. Make sure its executable (i.e chmod 755 script.sh)
In your shell script add cd /opt/yourProgram to have the proper working directory for your program before you invoke java.
If you want this program to be started easily by everyone create a symbolic link in /usr/bin or better in /usr/local/bin pointing to your script. Do this as last step after everything else is working.
In your shell script you'll have to add the other jars to the classpath e.g.
java -cp lib/some.jar:lib/other.jar -jar myProgram.jar
or
java -cp lib/some.jar:lib/other.jar:myProgram.jar com.acme.ClassContainingMain
Recommended practice: Add set -e at the very beginning of your script
As you already mentioned it's considered harmful to edit a shell script using a windows editor. The reason is that the windows editor will encode line-breaks (i.e. you hit the Return key) differently. This will make bash puke :)
Im not too clear of what you are looking for.
The script that you have written should work absolutely fine if you have placed your script and myprogram.jar at the same level.
And also im not sure how your myprogram.jar is referring the dependent libraries. So can't comment on them. Best bet will be to place your script and all jars together and try running the script.

Categories

Resources