How to control LD_LIBRARY_PATH
earlthesquirrel opened this issue · comments
I'm finding it hard to configure the building of the capsule to support the following:
Compiling on Mac, with a package that needs JNI support and deploying to a Raspberry Pi.
I can't figure out how to:
- include the platform specific jar into the package (it's not a Maven based artifact. I don't want to artificially force it into Maven or a Repo, that will make the configuration more confusing long term)
- how to add a value to the LD_LIBRARY_PATH so that on the Pi it will pick up the library directory.
The only tweak that's helped is to sent the environment variable on the Raspberry Pi. But that defeats part of the purpose of building the capsule.
I don't currently have a fix for #1. I've taken the output from the verbose output and tweaked it to to see how to change it to make it work (so I can try to reproduce it).
Note :
This is the current verbose command that comes out : /usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java -Djava.library.path=/usr/lib/jni:/usr/java/packages/lib/arm:/lib:/usr/lib:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.app=weather-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.dir=/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.jar=/home/pi/weather-1.0.0-SNAPSHOT-capsule-fat.jar -classpath /home/pi/weather-1.0.0-SNAPSHOT-capsule-fat.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/weather-1.0.0-SNAPSHOT.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/thingspeak-0.0.1-SNAPSHOT.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/wunderground-0.0.1-SNAPSHOT.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/log4j-1.2.17.jar:/home/pi/.capsule/deps/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar:/home/pi/.capsule/deps/com/mashape/unirest/unirest-java/1.4.7/unirest-java-1.4.7.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar:/home/pi/.capsule/deps/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar:/home/pi/.capsule/deps/commons-codec/commons-codec/1.6/commons-codec-1.6.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpasyncclient/4.0.2/httpasyncclient-4.0.2.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpcore-nio/4.3.2/httpcore-nio-4.3.2.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpclient/4.3.5/httpclient-4.3.5.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpmime/4.3.6/httpmime-4.3.6.jar:/home/pi/.capsule/deps/org/json/json/20140107/json-20140107.jar org.baugh.hal.weather.WeatherUpdater
When in fact I need something like this :
/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/jre/bin/java -DPORT=/dev/ttyACM0 -DWUPASS=dog -Djava.library.path=/usr/lib/jni:/usr/java/packages/lib/arm:/lib:/u
sr/lib:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.app=weather-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.dir=/home/pi/.capsule/apps/weathe
r-1.0.0-SNAPSHOT-capsule-fat -Dcapsule.jar=/home/pi/weather-1.0.0-SNAPSHOT-capsule-fat.jar -classpath /home/pi/weather-1.0.0-SNAPSHOT-capsule-fat.jar:/home/p
i/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/RXTXcomm-2.2pre2.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/weather-1.0.0-SNAPSHOT.jar:
/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/thingspeak-0.0.1-SNAPSHOT.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/wundergroun
d-0.0.1-SNAPSHOT.jar:/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/log4j-1.2.17.jar:/home/pi/.capsule/deps/com/google/code/gson/gson/2.2.4/gson-2
.2.4.jar:/home/pi/.capsule/deps/com/mashape/unirest/unirest-java/1.4.7/unirest-java-1.4.7.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpclient/4.3
.6/httpclient-4.3.6.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar:/home/pi/.capsule/deps/commons-logging/commons-log
ging/1.1.3/commons-logging-1.1.3.jar:/home/pi/.capsule/deps/commons-codec/commons-codec/1.6/commons-codec-1.6.jar:/home/pi/.capsule/deps/org/apache/httpcompo
nents/httpasyncclient/4.0.2/httpasyncclient-4.0.2.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpcore/4.3.2/httpcore-4.3.2.jar:/home/pi/.capsule/de
ps/org/apache/httpcomponents/httpcore-nio/4.3.2/httpcore-nio-4.3.2.jar:/home/pi/.capsule/deps/org/apache/httpcomponents/httpclient/4.3.5/httpclient-4.3.5.jar
:/home/pi/.capsule/deps/org/apache/httpcomponents/httpmime/4.3.6/httpmime-4.3.6.jar:/home/pi/.capsule/deps/org/json/json/20140107/json-20140107.jar org.baugh
.hal.weather.WeatherUpdater
DIfferences being the jar that I need to add and two defines. Not sure how you're passing defines that are specified in the plugin into the system properties, but I don't see the command as I would expect them to be.
Capsule will run the jar like so (scroll right):
[path/to/java] [jvmArgs] [-Djava.library.path=] [systemProperties] [-Dcapsule.app=] [-Dcapsule.dir=] [-Dcapsule.jar=] [-classpath] [mainClass]
You can define the jvm args by customising the manifest entry JVM-Args
like so:
<manifest>
<entry>
<key>JVM-Args</key>
<value>-Xmx512m</value>
</entry>
</manifest>
Just include the above in the <configuration>
tag of the plugin section in the pom.xml. See more here.
You can define the system properties similarly like so:
<properties>
<property>
<key>PORT</key>
<value>/dev/ttyACM0</value>
</property>
<property>
<key>WUPASS</key>
<value>dog</value>
</property>
</properties>
Just include the above in the <configuration>
tag of the plugin section in the pom.xml. See more here.
Regarding the additional dependency you want included in the -classpath
, namely, RXTXcomm-2.2pre2.jar
, you should simply include that as a dependency in the pom.xml in the normal way. Did you do that?
If you'd like, you can also share a project that I can play with to help out with your issue.
Ok first problem found. I didn't have the wrapping key spelled correctly. So that wasn't seen.
Should I SEE the -D in the output with : java -Dcapsule.log=verbose -jar weather-1.0.0-SNAPSHOT-capsule-fat.jar ?? Right now I do not.
Second : I can't reference the jar because it's not a Maven accessible artifact. No repo has the particular version I'm using. It's not published that way for the version for the Pi. There IS a version that's available via Maven for the Mac, but that version won't sync up to the JNI lib on the Pi. So I have to use the particular jar (RXTXcomm.jar, the pre version was the jar that I used to test on the Mac).
I'd like to be able to run on the Mac and Pi, but I don't know if that's going to be possible given this issue. But I can live with that, as I can have the dependency for the Mac in the Pom and comment it out when I'm building for the Pi (if I can get the Pi version to work via capsule)
BTW, with this specified :
<properties>
<property>
<key>Repositories</key>
<value>central</value>
</property>
<property>
<key>PORT</key>
<value>/dev/ttyACM0</value>
</property>
<property>
<key>WUPASS</key>
<value>dog</value>
</property>
</properties>
I only see : -DRepositories=central in the verbose output.
Two things: One, just noticed there was a newer version (1.0.5) vs (1.0.3) that I was using. So updated to that. I'm now seeing the -D params.
Second, the ONLY piece I'm unable to configure for is adding the RXTXcomm.jar into the build so that it unpacks as /home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/RXTXcomm.jar and then adding /home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/RXTXcomm.jar to the classpath.
If I can get that to happen, it'll work.
Try the latest version (1.1.2) and use fileSets to copy over your local jar:
<fileSets>
<fileSet>
<directory>lib/</directory>
<includes>
<include>RXTXcomm.jar</include>
</includes>
</fileSet>
</fileSets>
So from the above, create a folder called lib
in the root folder of your project and dump your RXTXcomm.jar
in there. This will tell the plugin to embed it in the capsule jar. Capsule should then pick it up and add it to the classpath automatically (and will also copy it to your /home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/RXTXcomm.jar
automatically when run too).
FYI : This really helped! Awesome update, thanks!!
The only thing I'm fighting "slightly" is getting the proper shell
configuration so that the LD_LIBRARY_PATH variable that I'm having to
update for the local library (for the 2nd 1/2 of the RMI library pair) is
set for when the program executes.
I'm trying to figure out how to run the command with gotty (so that I can
run the command and see output via the web page when I want to...)
Earl
On Mon, Apr 11, 2016 at 1:26 AM, Chris Christo notifications@github.com
wrote:
Try the latest version (1.1.2) and use fileSets to copy over your local
lib/ RXTXcomm.jar
jar:So from the above, create a folder called lib in the root folder of your
project and dump your RXTXcomm.jar in there. This will tell the plugin to
embed it in the capsule jar. Capsule should then pick it up and add it to
the classpath automatically (and will also copy it to your
/home/pi/.capsule/apps/weather-1.0.0-SNAPSHOT-capsule-fat/RXTXcomm.jar
automatically when run too).—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#48 (comment)
Hmm I'm not quite what it is you're trying to achieve (I'm unfamiliar with pi & gotty). Perhaps again share the command you're getting and the command you need, so I can try and help...
Well, gotty web site is here : https://github.com/yudai/gotty
I have a weather station that I have hooked up to a Raspberry Pi.
Standard Unix/Linux install. I do dev work on a Mac or PC and push to it.
Use capsule.io to do the run.
When I invoke the module "inside" gotty, I'm not able to get the
LD_Library_Path set properly.
Basically I'm not sure if Gotty executes a proper "shell" and sources what
I'd expect to get loaded (i.e. what environment is loaded)
I've also looked at tmux ( https://tmux.github.io/ ) and thought about
somehow combining that with gotty.
Basically the goal is to be able to easily monitor the data coming into the
Pi from the weather station (which is an Arduino and a shield connected to
sensors)
The RXTX serial library is used to read the data from the USB connector
(serial port) that feeds into the Pi.
That all works. However when the output from the program that is
monitoring the stream writes data simply to stdout. In the current case, I
redirect it to /dev/null.
Works fine, but if there is an issue, I'd like to see what had happened,
etc. If I drop and re-connect the program, that restarts what was running
on the Arduino, so
I can't find the exact state of things when it went down.
I've had some issues when things hang. I've been slowly working to iron
them out so the configuration stays up 24/7 stable for a long time. I've
had it run for
a week and then maybe 3 weeks continuously. But that was with an earlier
configuration. This one has run for a number of days. I just fixed on
thing (the possibility of
a log file filling up /var/log -- I didn't inspect the file system before I
bounced the Pi, so I'm not 100% sure...dumb me for not checking that...)
This make some sort of sense?
Earl
On Fri, Apr 22, 2016 at 7:15 AM, Chris Christo notifications@github.com
wrote:
Hmm I'm not quite what it is you're trying to achieve (I'm unfamiliar with
pi & gotty). Perhaps again share the command you're getting and the command
you need, so I can try and help...—
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#48 (comment)
This to me seems out of scope. Let me know if there is something specifically you'd like implemented.