• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Installing Apache-Commons-net library on raspberry pi

 
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
Hello all,

I developed much of a java program using JavaFX for use on a raspberry pi. In the process, I used an open-source apache library for some handy telnet methods. That library is here: https://commons.apache.org/proper/commons-net/download_net.cgi

My issue is that my code runs perfectly on my macbook, but crashes on the rPi. Commenting out the apache content allows it to run flawlessly on the Pi. I know I need to put the apache library jars somewhere on the rPi, but I have no idea where.

Any feedback is much appreciated.

Thanks.
 
Ranch Hand
Posts: 218
5
  • Number of slices to send:
    Optional 'thank-you' note:
if you want to use an external lib in your application you just have to add it to the classpath - where this lies in the filesystem is up to you
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:

Matt Wong wrote:if you want to use an external lib in your application you just have to add it to the classpath - where this lies in the filesystem is up to you



The library jars are imported into the project folder. They must be in the class path then, right?
 
Marshal
Posts: 4533
572
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:My issue is that my code runs perfectly on my macbook, but crashes on the rPi.


What does crashes mean?  Any error message, stack trace, etc.?
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
I get this monolith to console:



Connecting to 10.18.20.119:22
cmd : cd '/home/pi/NetBeansProjects//WITPhoneHome'; '/opt/jdk1.8.0_211/bin/java'  -Dfile.encoding=UTF-8   -jar /home/pi/NetBeansProjects//WITPhoneHome/dist/WITPhoneHome.jar
Exception in thread "JavaFX Application Thread"
java.lang.NoClassDefFoundError: org/apache/commons/net/telnet/TelnetClient
at Path.<clinit>(Unknown Source)
at GUI.callConstructors(Unknown Source)
at GUI$5.lambda$handle$0(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3761)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3489)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2498)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:391)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.monocle.MonocleView.notifyMouse(MonocleView.java:119)
at com.sun.glass.ui.monocle.MouseInput.notifyMouse(MouseInput.java:314)
at com.sun.glass.ui.monocle.MouseInput.lambda$postMouseEvent$101(MouseInput.java:227)
at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:93)
at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:52)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.telnet.TelnetClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 53 more
"
 
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:The library jars are imported into the project folder. They must be in the class path then, right?



I don't know what "project folder" means. Is that something on your Pi?

But anyway when your command looks like "java ... -jar some.jar" then the only thing in the class path is "some.jar". If you need other jars in your classpath (as you do) then you need a command like "java Thing -classpath some.jar,other.jar,another,jar..." where Thing is the class you want to run.

Or alternatively, when you create "some.jar" you could put a "Class-Path" header in it which identifies the other jars which you need it to use.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
The project folder is the project directory on netbeans on my work station. I am compiling the project to pi in netbeans over SSH. I should have mentioned this.

Is it possible to add it to the class path so that all library jars are included in the jar which runs on the Pi?
 
Ron McLeod
Marshal
Posts: 4533
572
  • Number of slices to send:
    Optional 'thank-you' note:
Examine the contents of your jar and determine if the Apache classes are present.

For example:
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
No, that apache jars are not in the runnable jar. Any advice as to where I should put them?

Many thanks for your help.
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:
I'm unclear as to what you are trying to do. You have Netbeans on the Pi, right? So is your intention to develop this application there and then send a jar file over to the Macbook and run it there as well? Or are you developing on the Macbook?

I don't really like the idea of having Netbeans in both places for development, unless you have taken care of the issue of keeping the two development environments synchronized.

You shouldn't have to have Netbeans on the Pi if all you want to do there is to run your program there. All you should need to do is to copy all of the necessary jars over from the development environment.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
I only have Netbeans on the macbook. From netbeans on the macbook, I compile on the pi over SSH.
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:
That's what I sort of thought. Your folder names on the Pi made me think you had Netbeans over there, though.

Anyway what I would do is to transfer all of the needed jars over to the Pi -- WITPhoneHome.jar, the apache jar, and anything else you need. Put them all in the same folder. Which could be your dist folder if you like.

Then you can use class-path wildcards to say "All of the jars in this folder are in my classpath" instead of having to enumerate them.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
When I compile over SSH to the Pi, netbeans creates a runnable jar on the Pi in the directory:

home/pi/NetBeansProjects/WITPhoneHome/dist/WITPhoneHome.jar

I try to put the apache jars inside the WITPhoneHome folder, but that doesn't work. Putting things in the dist folder also didn't work. Any other ideas?

Many thanks for your help.
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:
"Doesn't work"? Could you be a bit more specific?
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
Precisely the same error results when I run with the jars in the WITPhoneHome folder.
 
Ron McLeod
Marshal
Posts: 4533
572
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:I try to put the apache jars inside the WITPhoneHome folder, but that doesn't work. Putting things in the dist folder also didn't work. Any other ideas?


Is this a NetBeans issue then, where the libraries are not getting packaged in to your runnable jar?
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
It's possibly a netbeans problem, but I assume I'm doing something wrong. I also tried to put the jars directly in the runnable jar and running on the pi from terminal. That resulted in the same errors.

To apply libraries, I right click the project folder --> properties --> Libraries (under "categories") --> add (the "+" sign) compile-time class path jar

Please somebody tell me I'm a dummy and I've done something simple and incorrect.

Screen-Shot-2019-07-12-at-5.11.21-PM.png
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:Precisely the same error results when I run with the jars in the WITPhoneHome folder.



Well, as I said earlier, "java -jar yadayada.jar" isn't going to include any other jars in its classpath. Were you still using that version of the "java" command?

And jars inside a jar, which it sounds like you tried, aren't part of the classpath even if the containing jar is.

I don't know much about Netbeans but if you could get it to include a Class-Path header in the runnable jar it's generating, that would solve your problem. I don't know what that would look like in the component which generates the runnable jar but looking around at some of its options which you aren't using yet might help.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
I was still using that version of the java command, yes.

What is a simple way to run our jar on the Pi through terminal while including multiple 3rd-party library jars in the class path?
 
Bartender
Posts: 208
14
  • Number of slices to send:
    Optional 'thank-you' note:
I use Maven shade plugin. Nice and easy
 
Sheriff
Posts: 7125
184
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:What is a simple way to run our jar on the Pi through terminal while including multiple 3rd-party library jars in the class path?


This is a guess, but I would try putting the third-party jars in src/main/resources on the Pi.  That way you don't have to worry about a CLASSPATH.
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:

andrew mcnamara wrote:What is a simple way to run our jar on the Pi through terminal while including multiple 3rd-party library jars in the class path?



java -classpath /jarpath/* YourMainClass



Put all of your jars into the /jarpath folder. "YourMainClass" is the name of the class with the main() method which you want to run. Don't forget to put the package name before it.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
@ Paul : The Java file with the main method is called GUI.java, but the package name in NetBeans where all the source files are is simply “<default package>” (I know, bad move on my part, this is from a while ago). Is there a way we can tell that to the terminal (i.e. something like WITPhoneHome.GUI or main.GUI) since it won’t recognize “<default package>”?

$ java -classpath /home/pi/Desktop/Jars/ <default package>.GUI
-bash: default: No such file or directory
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:
If the class isn't in a package then you just need to put the class name in that command. Like so:

java -classpath /home/pi/Desktop/Jars/* GUI



Don't forget the wild-card symbol to tell Java that the classpath includes all jars in that folder.
 
Saloon Keeper
Posts: 27868
196
  • Number of slices to send:
    Optional 'thank-you' note:
Common thread here.

NONE of the issues I see relate to the Raspberry Pi. They're all related to Java and to the dependence on an IDE. The main issue with the Pi is that as far as I can tell, it's NOT running the IDE, it's running the actual application. As it should.

Java does not ever look at jars that are inside other jars for classes. The only way to make it do so is by adding extra support code to the application or its framework. For example, webapp servers dig around in the WEB-INF/lib jars for class resources as well as the WEB-INF/classes directory for loose class resources.

To make a stand-alone executable jar work like that, as I said, some external magic has to be injected. That's what the Maven Shade plugin does when it builds an executable jar. In addition to copying the included jars into the product jar file, it also injects extra classloader logic into the app startup so that the contents of those included jars will appear on the app's classpath. Simply building with the java "jar" command isn't enough.

And just to make things perfectly clear: Java on the Raspberry Pi is no different than Java on any other hardware platform. It has exactly the same write-once/run anywhere rules as for the larger Linux desktop and server systems.

I say that as a person who right this moment is literally surrounded by Pi systems. I'm doing a home automation server project on them.
 
Paul Clapham
Marshal
Posts: 28262
95
  • Number of slices to send:
    Optional 'thank-you' note:

Tim Holloway wrote:NONE of the issues I see relate to the Raspberry Pi. They're all related to Java and to the dependence on an IDE.



This is absolutely true. Somebody added the thread to the Netbeans forum but yes, it's just another question about how to set the classpath.
 
andrew mcnamara
Greenhorn
Posts: 22
  • Number of slices to send:
    Optional 'thank-you' note:
Hello all,

Many thanks for your responses. Yes, I see now that this was purely a class path issue. I was able to resolve it last night by building a fat jar:

https://stackoverflow.com/questions/18451052/how-to-include-jars-in-lib-into-project-jar-file-in-netbeans/30172972

Your advice here led me to the solution.

Thanks again,
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic
vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |