I am working on car radios to convert them from US to EU. Currently I am stuck with a problem to show radio logo's. Originally radio should download logos from online servers, however USA converted car into EU can't connect to servers anymore.
There is a JAR file which is processing radio logo's: /opt/arc/bundles/service.dsi.hybridradio.jar
If I open this file with any java class decompiler (for example Recaf) I can find lot of classes, but I need this one: de.eso.mib.online.hybridradio.events.GetOfflineLogosEvent, as it contains private void addLogoToStation(RadioStation tmpStation, RadioStationLogo logo), and I need to call it somehow with parameters, but there is a problem.
/opt folder is under DM-Verity protection, I can't remount it as read write, or modify. I started digging how these jar's are executed and found:
export FW_JAVA_DIR=/usr/share/esofw/
................................................
echo "looking for fw jars in: ${FW_JAVA_DIR}"
if [[ -d $FW_JAVA_DIR ]]; then
JARS=$(find $FW_JAVA_DIR -name '*.jar')
if [[ ! "x$JARS" == "x" ]]; then
for jar in $JARS; do
BOOTCLASSPATH="$BOOTCLASSPATH:$jar"
done
fi
fi
................................................
## Launch Java VM
echo "starting vm ...."
echo "java: ${JAVA}"
echo "VMOPTIONS: ${VMOPTIONS}"
echo "bootclasspath: ${BOOTCLASSPATH}"
exec $JAVA $VMOPTIONS -Xbootclasspath/a:$BOOTCLASSPATH de.dreisoft.lsd.LSD
What do I see from this, that I can add my own jar file into /usr/share/esofw and it will be added into Java bootclasspath. Also /usr/share/esofw is not under DM verity and is writeable.
If I compile simple jar file and add under this folder, then run ps aux, I see my jar under boot classpath:
/opt/java/bin/java -Xmx48m Xbootclasspath/a::/opt/java/lib/otherjarshere.jar:/usr/share/esofw/MINECUSTOMJARISEXECUTEDHERE.jar de.dreisoft.lsd.LSD
It means I can execute my own jar together with rest, correct? Now question appears, how can I call addLogoToStation function from another, new created jar? is it even possible at all? Thanks in advance.
Related
I've made an executable jar file for a terminal game that can be opened by typing java -jar name.jar in the Terminal.
Then I made a .sh file inside the same folder as the jar file to open it by double-clicking the .sh. I asked how to do this here, where people told me to use the following code in the .sh.
#! /bin/bash
DIR=$(dirname "$0")
java -jar "$DIR/game.jar"
This worked for a while, but when I renamed the folder, I realised if I move the folder to a pen drive the whole thing stops working and I get this in the Terminal.
Error: Unable to access jarfile /Volumes/Hard
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
So how to find the file path to the folder the .sh and the jar are in, regardless of where it is, what its name is and what drive it is on?
Also, I'm using MacOS Mojave 10.14.4 if that's of any importance.
The error looks like the path does contain spaces, like probably /Volumes/Hard Drive/Users/something. The solution is to quote the command substitution.
Tangentially, don't use upper case for your private variable names.
But of course, the variable isn't really necessary here, either.
#!/bin/sh
java -jar "$(dirname "$0")/game.jar"
Nothing in this script uses Bash syntax, so it's more portable (as well as often slightly faster) to use sh in the shebang. Perhaps see also Difference between sh and bash
You can store the full path of the working directory using the environement variable $PWD, like in this example (done in 5min, it is just to show you how it is works) :
#!/bin/bash
DIR=$PWD
gamePath='java -jar '$DIR'/game.jar'
echo $gamePath
Wherever I will execute this script, it will shows up the working directory even if I change the name of the parent. Let me show you :
You can see that $PWD environnment variable works great.
Now, I will change the directory name from TestFolder to TestFolderRenamed and execute the script again :
So, in your case, change your code as following :
#! /bin/bash
DIR=$PWD
java -jar "$DIR/game.jar"
It should works.
I'm having a strange issue trying to run classes from an executable .jar file on Linux that none of the existing question threads I've sorted through seem to be able to resolve. I'll preface this in that I've never had to use Linux before and am only using it in this situation out of necessity, so it's possible I have overlooked something simple that I just didn't know could be causing the problem.
I can launch the classes from my .jar file without any issues on Windows via a .bat file with the following settings:
start "MyServer1" java -classpath ./*;Server.jar infoServer/StartInfoServer
start "MyServer2" java -classpath ./*;Server.jar loginServer/StartLoginServer
start "MyServer3" java -classpath ./*;Server.jar chatServer/start
start "MyServer4" java -classpath ./*;Server.jar gameServer/start
However, when I move to trying to launch these classes from the .jar on Linux, I get a "could not find or load main class" error. My .sh file is set up like this, and is placed in the same directory as my .jar file:
echo Starting Servers
java -cp Server.jar infoServer.StartInfoServer
java -cp Server.jar loginServer.StartLoginServer
java -cp Server.jar chatServer.start
java -cp Server.jar gameServer.start
echo All Done Starting Server
I've used ls from the Terminal to verify the .jar and .sh were being recognized as existing where they should be. (For future note, I'm using the Terminal from inside the directory containing my files.) I've made sure to make use of chmod to be sure both the .jar and the .sh have read/write/execute permissions and used ls -l to verify those permissions were indeed present. I've tried various forms of explicitly defining the classpath, such as using "/home/machine/Desktop/Folder/MyJar.jar", using pwd from the Terminal to ensure I'm getting the filepath correct. I've checked over my Java compatibility. (1.7.0_65 on Linux, 1.8.0_45 on Windows, with the .jar being created in Eclipse using 1.7 Compliance settings.) I can use unzip MyJar.jar from the Terminal and it will properly extract all my class files, allowing me to verify that my .jar isn't corrupted on my Linux machine and that the paths to the classes I'm trying to run are still the same on Linux as they are on Windows.
I do apologize if this is just a problem of inexperience overlooking something, but I can't think of or find any indication of what the problem could possibly be.
EDIT:
I've updated the question with some screenshots related to the problem:
https://gyazo.com/0ae2a2701aae734db21ef7c29200283b - General File Setup.
https://gyazo.com/d735d9cee57b4a92078c4b624d012b8c - Running the Shell via Terminal.
Other notes: jar -tf Server.jar works from the Terminal but not from inside the Shell script, which leads me to believe this may be some kind of visibility or pathing error, but I can't find any reason why that would be the case.
I have written a Java application, and I have created an executable Jar file that successfully runs my application with java -jar myJar.jar. I have an executable shell script called launchMyProgram that wraps the launching of this Jar (and offers various flags like --help etc.). My target output directory looks like this:
$ ls /path/to/MyProject/target/
archive-tmp/ classes/ myJar.jar
What is the standard method for me to write an installer for my Unix-only application? I assume that I would be correct to drop the launchMyProgram executable in /usr/local/bin. But where do I put the Jar file? Should I make my own subdirectory somewhere for my program's files? Do I need to copy the classes directory from the above output into the same directory as the Jar? This will run via a Makefile so of course users may override my choices.
Basically, I want a user to be able to run make && make install, and be able to run my application with launchMyProgram, and I want place my files (one jar, a 'classes' folder, and a shell script) in the most typical places possible.
One of the best ways to do it has been reinvented many times but is unfortunately not yet standard.
Since a JAR is a ZIP file which is allowed to have an arbitrary prefix, you can prepend a launcher shell script to your jar, mark it executable, and treat that as a standalone binary.
$ echo '#!/bin/bash' > launchMyProgram
$ echo 'exec java -cp "${0}" com.example.program.Main "${#}"' >> launchMyProgram
$ cat myJar.jar >> launchMyProgram
$ chmod +x ./launchMyProgram
$ ./launchMyProgram
Hello, world!
See Simple & Easy Executable Jars for more details.
You should be able to pack everything in the classes/ folder into your jar and still have things work.
Also, if you want to provide RPMs or DEB packages or something for users, fpm makes that really easy.
One of my friend told me that he used a batch program to install a java program on the machine,that placed the necessary files in a particular directory and also planted a shortcut on the desktop. How can it be done ? If there are tutorials that teach this please link me to them
All you need to do is use some basic windows commands to make this work. I'm not going to write the script for you but I can point you in the right direction. A batch script on windows is a simple text file ending with the .bat extension.
You can use any command typically available on the windows command prompt (AKA cmd.exe). A good starting point is learning how to move and copy files around so you want to take a look at the commands by the same name on the Command-line reference from Microsoft. There is also a handy guide linked on the same page to batch files and how they work.
The documentation linked is for Widows XP and the syntax of the commands should be back and forwards compatible with other Windows versions.
Installing a Java program is the same thing as installing a ... program ;-)
You can create a batch installer from scratch with a .bat file or use an installer builder tool.
I use NSIS because it's free and simple to use ... but there's others.
You also may want to build an .exe instead of a jar file (sometime, windows open the jar archives instead of launching java). I use Launch4J to wrap my java application in a .exe file.
If the app. has a GUI, install/launch it using Java Web Start. It works on Windows, OS X & *nix, and can install both desktop shortcuts and menu items to launch the app. on platforms that support such things.
JWS is supported & supplied by Oracle.
This code is a simple batch script. Customize this code.
Code:
#echo off
color f0
:: overwrite your program name after the '=' ::
set ProgramNameHere=ProgramNameHere
goto start
:start
cd/
cd users
cd %username%
cd desktop
md %ProgramNameHere%
:: overwrite your file path on the 'DATA' ::
:: overwrite your file name on the 'file1', 'file2'...
:: overwritw your file name after the 'extracting'.
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file1.txt
echo extracting file 1
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file2.txt
echo extracting file 2
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file3.txt
echo extracting file 3
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file4.txt
echo extracting file 4
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file5.txt
echo extracting file 5
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file6.txt
echo extracting file 6
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file7.txt
echo extracting file 7
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file8.txt
echo extracting file 8
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file9.txt
echo extracting file 9
ping localhost>nul
echo DATA>>C:\Users\%Username%\Desktop\%programNameHere%\file10.txt
echo extracting file 10
ping localhost>nul
goto exit
:exit
exit
I use Eclipse to develop Java so I have a folder full of Eclipse Java Project folders. The /bin folder resides in each folder, so to run the project from Cygwin, the classpath must be set (on my system) to: "E:/programming/java/workspace/SomeProject/bin". Since there are ~40 projects in my folder, I'd rather make a script to add the paths to the CLASSPATH. My script seems to add the paths to CLASSPATH, but when I try to run Java I get a class not found error. In my .bashrc here is my script:
JAVAWORKSPACE="/cygdrive/e/programming/java/workspace/*"
BIN="/bin;"
for f in $JAVAWORKSPACE
do
if [ -d $f ] ; then
export CLASSPATH="$f$BIN$CLASSPATH"
fi
done
When I start Cygwin and echo $CLASSPATH, all of the directories show up, but java can't find the classes. I have also tried JAVAWORKSPACE="E:\programming\java\workspace\* but this resulted in nothing being added to CLASSPATH. If I go through the Windows settings and manually enter "E:/programming/java/workspace/MyProject/bin" to the CLASSPATH, command line Java has no trouble finding the classes. What's up with this? I'm not sure if it's a problem with the script or if CLASSPATH doesn't like unix-style paths. If I need to add windows paths, please help me change my script to do this. Thanks!
I don't have Cygwin set up right now, but I ran into this problem a number of years ago. Java knows nothing about Cygwin pathnames, and bash treats a single backslash as an escape character, stripping it before it can be transmitted to java(c). If you do
echo E:\programming\java\workspace\*
You'll see it outputs E:programmingjavaworkspace*, not what you're expecting. The key is to either escape the escape chars, like
E:\\programming\\java\\workspace\\*
or even better, use cygpath like this.