mahendra28
Posts: 1
Joined: Wed Nov 01, 2017 4:26 am

About How to Create Executable file in Raspberry Pi

Wed Nov 01, 2017 4:33 am

Hi All,

I just want know How to create executable file in raspberry platform.actually i am creating Java Swing application using Pi4j API
and also i am creating jar file of that all classes but it nt working for me.

so guyz please give me suggestion

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: About How to Create Executable file in Raspberry Pi

Thu Nov 02, 2017 8:44 am

Try searching for creation of 'executable' jar. Depending what build mechanism you are using there are different ways to do so. In Eclipse, for instance, you can select 'Export' -> 'Executable Jar' and select main class. If you are doing things 'properly' and have build set up (maven for instance) then search for your build mechanism how to do it (maven plugin, grails variable, etc).

Such jar file, then, can be 'executed' on RPi with

Code: Select all

java -jar myjar.jar

User avatar
addeswe
Posts: 29
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: About How to Create Executable file in Raspberry Pi

Tue Nov 07, 2017 3:32 pm

What you can do is create a shellscript with the following code:

Code: Select all

#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
    java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "[email protected]"
exit 1 
After that, just cat the jar-file into the shellscript with >> (so you append it). Then all you need to do is make the shell script executeable with chmod +x and run it.
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

User avatar
clicky
Posts: 415
Joined: Thu Oct 25, 2012 7:34 am

Re: About How to Create Executable file in Raspberry Pi

Wed Nov 08, 2017 9:57 am

Brilliant! Do you have any references *why* it works?

Also - maybe calling "java_args" as "JAVA_ARGS" would make more sense but otherwise it is just brilliant!

Return to “Java”