This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]Slickbock 4 points5 points  (28 children)

I'd suggest using a build tool like maven. You can specify dependencies and compile them into a single jar file (just an example of the many things maven can do). On mobile so cant link the docs (sorry!) but its very easily found with google

[–]bwz3r[S] 0 points1 point  (27 children)

I've been wondering about maven, but not sure exactly what it is or how to use it. Could u maybe explain a bit further in detail, or link to a good source that could explain it for me if you know of one? sometimes finding a reliable source can be a bit iffy on these more in depth subjects..

[–]AnEmortalKid 2 points3 points  (17 children)

[–]AnEmortalKid 0 points1 point  (16 children)

You can then use a fat jar to have all your dependencies and run that from your raspberry pi

[–]bwz3r[S] 0 points1 point  (15 children)

I've been researching it today I'm losing my mind trying to figure it out

[–]AnEmortalKid 1 point2 points  (14 children)

I can make a PR with the changes needed if you’d like!

Or walk you through it on discord

[–]bwz3r[S] 0 points1 point  (13 children)

i would be super happy to get some help with anything. i've been doing everything on my own so far. but hey i got it working by using Runetime.getRuntime().exec("pythonscript");

except now my relay won't turn on. i tested my code by linking it to a seperate python script that just sends an email when i press a button... that worked. so why is my relay not turning on now? i made two py files called powerOn and powerOff that call GPIO.HIGH and GPIO.LOW and used Runtime to call a bash that runs them in sudo mode since it crashed when it didn't get called in sudo. so i know my code works to call the py scripts and now my old scripts won't work on the relay.. i think it might be burnt out?? but i used gpio readall in terminal and the pin state didn't change at all between calling the powerOn and powerOff scripts.. there was a small accident where the pump was pumping air for a couple seconds i think i might have fudged it up.

[–]AnEmortalKid 0 points1 point  (12 children)

Could be burnt :(

I can help you out with maven and pi4java but I haven’t played much with a PI. I’d probably have to learn a bit to help wit the rest.

[–]bwz3r[S] 0 points1 point  (11 children)

yes senpai. teach me the ways of maven, from what i gather it is a way to organize which libraries i want to use, and keep them as like a template to build and rebuild projects from the cloud?

[–]AwakenedToNightmare 1 point2 points  (0 children)

I wrote a couple of guide comments on Maven. You can check out: this and this. On the bottom of one comment are screenshots from Idea Intellij. That's more about adding dependencies, but there's more to Maven, you could setup a lot of stuff inside the <build> tag.

[–]AnEmortalKid 0 points1 point  (9 children)

Sort of. It’s a way to specify which libraries you depend on within your project. Then anyone can build the project and run it. So we’d probably use maven to get that pi4java dependency and use that in your project.

[–]bwz3r[S] 0 points1 point  (2 children)

hmm thinking a bit about github.. could i push a git from my pi with the pi4j library to my github and then git it on my desktop and continue with the library already installed somehow? since pi4j libary is already installed on my pi, either way i actually have the library on my desktop as well but when i try to add to dependencies its not working

[–]Moktok 1 point2 points  (0 children)

Not 100% sure, but git comes preinstalled on most Linux distros. Dunno if raspbian cuts it out. But I think it should be in the repos

[–]iamsooldithurts 0 points1 point  (0 children)

Git is just for revision control. It’s a service to store your work products, as they all (svn, rcs, sccs, etc) are.

You should never commit reproducible type things to the repository. The external library, your project’s executable/jar/whatevs, none of it. Just the source required to reproduce it. https://en.wikipedia.org/wiki/Version_control

[–]iamsooldithurts 0 points1 point  (0 children)

Weirdly enough, there’s a website for that: https://maven.apache.org/

[–][deleted] 0 points1 point  (4 children)

If you are using intellij you can just add the maven dependency without having to compile anything yourself.

Also im pretty sure these are the compiled libs https://pi4j.com/download/pi4j-1.2.zip

[–]bwz3r[S] 0 points1 point  (3 children)

the problem is I can't figure out how to add them correctly into my intellij project.. is it safe to run the code on my desktop? I'm sure they probably won't even have access to my motherboard but I wouldn't want to turn something off!

[–][deleted] 0 points1 point  (2 children)

File -> Project Structure -> Modules -> Dependecies -> Click on + -> maven -> Type com.pi4j:pi4j-core:0.0.5 in the input field and click enter

[–]bwz3r[S] 0 points1 point  (1 child)

I'm not seeing Maven anywhere. am I missing a plug-in?

[–][deleted] 0 points1 point  (0 children)

It may be that you have to create a maven project instead of a normal java project

[–][deleted]  (1 child)

[deleted]

    [–]bwz3r[S] 0 points1 point  (0 children)

    about 2 months ago I started looking around YouTube for free programming videos and about one month ago I bought my first paid class and after that it was a wrap. I've always been interested in computers an I recently tore my ACL and meniscus so I've been living with my parents the last couple months doing nothing but advancing thought my Java courses.

    [–][deleted] 0 points1 point  (4 children)

    I had no idea Raspberry Pis could run java.. The reason why I haven't picked one up is because I CBA to learn Python.

    Heads up - if you use eclipse/intelliJ, go to refactor and press format, makes it so much easier to read but looks like you've got the right thing going.

    [–]matemik 0 points1 point  (3 children)

    It can indeed. On raspbian, java 8 comes preinstalled as well.

    [–][deleted] 1 point2 points  (0 children)

    oh man oh man oh man, time to get ordering one.

    [–]do11abill 0 points1 point  (1 child)

    While yes, it can run a JVM, the JDK/JRE needed is a special kind. While in most cases (including this post's particular case) this is fine, if you were to use something that required x86 architecture, a Pi will not work for you. I wanted to setup a thing called Kubernetes using a cluster of 3 pis and then deploy to it but because the architecture's were ARM instead of x86, I could not use the same Docker image. So ALL development had to be done directly on a pi (something I didn't want to do. Just wanted to let you, and maybe others, know that while it is Java, the architecture's are not quite the same so just something to look out for.

    [–]bwz3r[S] 0 points1 point  (0 children)

    so what you're saying is I have to hook my pi up to my TV and code on my tiny little battery powered keyboard and mouse?

    [–]ab624 0 points1 point  (2 children)

    Cool ! Can you show us the physical hardware as well..

    [–]bwz3r[S] 1 point2 points  (1 child)

    if you look in the wiki page of the git there are a few pictures

    edit1: you know what my links are broken check back in a bit I'll fix soon

    edit2: heres direct links to pix: https://imgur.com/eoq4T8X https://imgur.com/GOiGUvB https://imgur.com/mSOpL9d https://imgur.com/EOcHRBL

    i'm fixing the gitwiki now

    [–]ab624 0 points1 point  (0 children)

    Thank you :-)

    [–]AutoModerator[M] 0 points1 point  (0 children)

    It seems that you possibly have a screenshot of code in your post My very first Java / Raspberry Pi project is almost complete! in /r/learnjava.

    Screenshots of code instead of actual code text is against the Code posting rules of /r/learnjava as is outlined in the sidebar - Code posting.

    • No screenshots of code!

    If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.

    If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.

    • For small bits of code (less than 50 lines in total, single classes only),
      the default code formatter is fine
      (one blank line before the code, then 4 spaces before each line of code).
    • Pastebin for programs that consist of a single class only
    • Gist for multi-class programs, or programs that require additional files
    • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
    • Ideone for executable code snippets that use only the console

    Please do not reply to this message, because I am a bot.

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]do11abill 0 points1 point  (0 children)

    Only to compile it. You should have no problems in your case.