Cov txheej txheem:

Txhim Kho Java Txhim Kho rau Raspberry Pi: 11 Kauj Ruam (nrog Duab)
Txhim Kho Java Txhim Kho rau Raspberry Pi: 11 Kauj Ruam (nrog Duab)

Video: Txhim Kho Java Txhim Kho rau Raspberry Pi: 11 Kauj Ruam (nrog Duab)

Video: Txhim Kho Java Txhim Kho rau Raspberry Pi: 11 Kauj Ruam (nrog Duab)
Video: Kho caj kho cev by Celesna Lor 2024, Hlis ntuj nqeg
Anonim

Cov Lus Qhia no piav qhia txog txoj hauv kev muaj txiaj ntsig zoo rau kev txhim kho Java cov haujlwm rau Raspberry Pi. Kuv tau siv txoj hauv kev los txhim kho Java lub peev xwm xws li los ntawm kev txhawb nqa cov cuab yeej qis mus rau ntau txoj xov thiab cov phiaj xwm sib txuas hauv network. Txoj hauv kev tsis tsuas yog ua tau zoo, nws yog pub dawb!

Hauv paus, txoj hauv kev yog kev txhim kho deb deb siv NetBeans. NetBeans khiav ntawm chaw ua haujlwm (lub khoos phis tawj lossis lub khoos phis tawj laptop, tsis yog Raspberry Pi) txuas ntawm Wifi mus rau Raspberry Pi. Thaum txhua yam tau teeb tsa kom raug, koj tuaj yeem sau Java program hauv NetBeans thiab tom qab ntawd nyem ib zaug ua ke thiab tsim cov haujlwm ntawm lub chaw ua haujlwm, rub tawm qhov program mus rau Pi, khiav qhov program ntawm Pi, thiab xa tawm mus rau NetBeans console. Khawv koob! Koj tseem tuaj yeem debug qhov haujlwm ua haujlwm, teeb tsa cov ntsiab lus tawg thiab tshuaj xyuas qhov txawv txav. Ntau khawv koob!

Tus so ntawm qhov kev qhia no piav qhia txog kev txhawb siab rau kev siv Java thiab rau kev txhim kho tej thaj chaw deb siv NetBeans. Yog tias koj mob siab txog kev txhawb siab, nyeem ntxiv. Yog tias koj tsis quav ntsej, mus rau kauj ruam 1.

Vim li cas siv Java ntawm Raspberry Pi?

Muaj ntau yam lus siv rau Raspberry Pi, tab sis kuv yuav txwv qhov kev sib tham mus rau "qib kev tshaj lij" cov lus programming uas tsom mus rau cov haujlwm ib leeg, txhawb nqa ntau txoj haujlwm, tso cai kho vajtse thiab nkag mus rau network, thiab lwm yam. Qhov ntawd txhais tau tias Java, Python, lossis C/C ++. Kev tshaj tawm tsis ntev los no ntawm Raspbian suav nrog kev txhim kho thiab kev txhawb nqa sijhawm rau txhua yam lus no.

Python tau siv "txhawb nqa" rau siv ntawm Pi, tsawg kawg hauv ib feem rau nws yooj yim-ntawm-kev kawm rau cov programmer tshiab. Kuv yog tus kws tshaj lij kev paub thiab kuv tsis nyiam Python vim qhov kev lees paub tus kheej tsis nyiam ntawm tus lej ntawm nws tus yam ntxwv, piv txwv li, hloov pauv tau. Muaj ib tus yam ntxwv ntawm Python uas kuv tsis nyiam yog lub hom phiaj - kev ua tau zoo. Cov peev txheej no qhia tau tias Java ib txwm nrawm dua Python 3, thiab qhov tseeb tuaj yeem ua haujlwm ntau pua zaus sai dua, nyob ntawm txoj haujlwm.

C hauv kuv lub tswv yim, yog "qib lus siv lub tshuab", piv txwv li, ib yam dab tsi uas nyob ze rau ntawm cov cuab yeej khoos phis tawj, lossis tsawg kawg yog kev ua haujlwm. Koj tuaj yeem ua txhua yam zoo nkauj heev, thiab koj tuaj yeem ua nws sai li sai tau; qhov tseeb, qhov peev txheej no qhia C tuaj yeem khiav mus txog 7X nrawm dua li Java. Kuv kuj tsis nyiam C txij li kuv (tus kheej) tsis nyiam qee yam ntawm nws cov yam ntxwv uas kuv pom arcane, qub, lossis ob qho tib si; piv txwv li, taw qhia meej. Lub hom phiaj, qhov tseeb tias koj tuaj yeem ua dab tsi txhais tau tias koj tsuas yog kab laum tsis meej (piv txwv li, tus lej ntsuas tus lej tsis zoo lossis ua yuam kev memcpy) deb ntawm kev rov sau dua nco thiab muaj peev xwm tsoo qhov haujlwm lossis txawm tias tag nrho cov kab ke. Java tiv thaiv kev phom sij, yog li Java muaj kev nyab xeeb dua. Kuv xav tias kev nyab xeeb tseem txhim kho cov tsim khoom tsim khoom. Kuv xav txog C ++ qhov khoom-tsom "qhwv" ncig C uas tsis muaj dab tsi los tshem tawm qhov phom sij ntawm C.

Cov kab hauv qab: Java nrawm dua li nab hab sej. Java muaj kev nyab xeeb dua C.

Puas muaj kev txwv thaum siv Java?

Txog tam sim no, Kuv tau ua txhua yam hauv Java uas kuv tuaj yeem ua hauv Python. Muaj ntau yam uas ib tus tuaj yeem ua hauv C uas ib tus tsis tuaj yeem ua hauv Java, tab sis ntxiv, txog tam sim no txhua yam kuv xav ua tau raug hais los ntawm Java cov kiv cua hauv Pi zej zog. Kuv mam muab qhov piv txwv hauv qib tom ntej. Qhov ntawd tau hais tias, Kuv tau yuav cov ntsuas hluav taws xob los ntawm cov muag khoom uas muab "tus tsav tsheb" rau lub ntsuas cua tsuas yog hauv Python (lossis C/C ++ rau Arduino), yog li kuv yuav tsum sau Java sib npaug; kev siv zog ntxiv tsis tas yuav muaj txiaj ntsig zoo, tab sis tuaj yeem ua rau pom kev ntau dua rau hauv lub tshuab ua haujlwm.

Vim li cas kev txhim kho tej thaj chaw deb raws NetBeans?

Kuv tau pom tias NetBeans-based kev txhim kho chaw deb heev ua rau muaj txiaj ntsig zoo thaum siv Java rau Raspberry Pi. Kuv ntseeg tias koj tuaj yeem siv txoj hauv kev los tsim cov phiaj xwm nrawm thiab nyab xeeb, vim yog tus yam ntxwv ntawm Java, thaum sau ntawv, tsim thiab debug lawv sai dua li lwm txoj hauv kev kuv tau pom, vim kev txhim kho tej thaj chaw deb siv "kev tshaj lij" qib "NetBeans Integrated Development Environment (IDE).

Nws yuav muaj txiaj ntsig los tham txog cov "lwm txoj hauv kev" luv luv. Txhua yam ua tau raws cov txheej txheem yooj yim uas Raspberry Pi tsis muaj cov keyboard, nas, lossis tso saib txuas nrog. Muaj ntau qhov laj thawj rau qhov xwm txheej no, tab sis kuv qhov laj thawj tseem ceeb yog tias kuv tsim kho lub xov tooj ntawm tes, thiab kuv tsis xav kom Pi txuas nrog ib qho khoom siv tshwj tsis yog cov neeg siv tshuab ย่อย, txawm tias thaum txhim kho.

VNC tus neeg rau zaub mov suav nrog hauv Raspbian muab cov neeg siv duab nraaj sib cuam tshuam (GUI) uas tso cai rau daim ntawv ntawm kev txhim kho tej thaj chaw deb, qhov twg tsuas yog GUI tej thaj chaw deb khiav ntawm chaw ua haujlwm thiab txhua yam ntxiv, sau ntawv, suav thiab tsim, ua haujlwm ntawm Pi. Nrog VNC nws yooj yim siv Java-muaj peev xwm txhim kho cov cuab yeej uas xa khoom hauv Raspbian, xws li BlueJ, Geany, thiab Greenfoot. Qee qhov no tuaj yeem suav tias yog IDE; txawm li cas los xij, kuv pom lawv nyob deb ntawm qib kev tshaj lij.

Nws yog qhov muaj peev xwm siv tau los teeb tsa qib kev tshaj lij Java IDE zoo li dab noj hnub lossis NetBeans ntawm Raspberry Pi thiab siv nws nyob deb ntawm VNC. Cov ntawv ceeb toom, thiab kev nkag siab zoo, qhia tias cov txiaj ntsig yuav poob siab, vim muaj lub cim xeeb loj thiab CPU lub zog xws li IDEs xav tau, nrog rau lub network latency qhia los ntawm GUI nyob deb.

Eclipse thiab NetBeans ua haujlwm tau zoo heev ntawm lub chaw ua haujlwm. Nrog Dab noj hnub, sau cov cai yog qhov kev lom zem, txawm li cas los xij, kev tsim cov program tsis yog; rub tawm qhov program yuav tsum tshwm sim sab nraum Eclipse; ua tiav txoj haujlwm ntawm Pi yog kev ywj pheej ntawm Eclipse. Qhov txiaj ntsig tag nrho yog ntau qib, yuav luag mob, txheej txheem uas tsis tuaj yeem txhawb nqa debugging deb. NetBeans tau teeb tsa ua ke, tsim, rub tawm, ua haujlwm deb, thiab debug deb, ua rau nws ua tau zoo dua.

Kauj Ruam 1: Teeb Raspberry Pi

Txhawm rau siv txoj hauv kev txhim kho nyob deb koj yuav tsum pib los ntawm kev teeb tsa lub hom phiaj Raspberry Pi. Muaj ntau cov peev txheej, suav nrog Cov Lus Qhia, muaj los pab teeb tsa Raspberry Pi. Saib qhov no rau qhov pib ntawm teeb tsa Pi (thiab ntau dua).

Cov lus qhia no xav tias koj

  • nruab qhov tseeb Raspbian; nco ntsoov tias koj sau Pi tus lej ID thiab tus password
  • teeb Wifi thiab txuas rau koj lub router (saib qhov no); nco ntsoov tias koj sau Pi's IP chaw nyob
  • pab SSH (saib qhov no) kom tso cai nkag mus rau Pi los ntawm chaw ua haujlwm

Thaum koj tau ua tiav kev teeb tsa, koj tuaj yeem txo hwj chim thiab txiav cov zaub, cov keyboard, thiab nas los ntawm Pi. Qhov no yog ib qho tseem ceeb ntawm kev txhim kho tej thaj chaw deb. Koj yuav tsum tso ib qho Wifi dongle txuas nrog (tsis xav tau, ntawm chav kawm, rau Pi qauv 3 lossis Pi Zero W), thiab tom qab ntawd koj tuaj yeem txhawb nqa Pi.

Txhawm rau sim, qhib tus neeg siv ssh ntawm koj lub chaw haujlwm, piv txwv li, Terminal ntawm MacOS lossis muab tso rau ntawm Windows. Tom qab ntawd nkag mus rau ssh (ruaj ntseg lub plhaub) hais kom ua nrog daim ntawv hauv qab no:

ssh the_pi_ip_address -l the_pi_user_id

Koj yuav tsum tau txais sai kom nkag mus rau koj li Pi tus lej ID tus lej nkag. Yog tias tsis muaj qhov tshwm sim tam sim, txheeb xyuas kom paub tseeb tias koj tau nkag mus rau qhov chaw nyob raug tus IP hauv ssh hais kom ua. Nkag mus rau koj tus password (nws yuav raug muab zais) thiab tom qab ntawd koj yuav tsum pom Pi lub plhaub tam sim uas pom qee yam zoo li no:

pi@raspberrypi: ~ $

Yog tias koj tsis pom qhov hais kom sai, txheeb xyuas tus lej ID thiab tus password uas koj siv.

Tam sim no koj yuav tsum nrhiav txoj hauv kev mus rau Java runtime thiab lees paub qhov ua piv txwv yog Java 8 (yuav tsum muaj tseeb rau qhov tseeb Raspbian). Txhawm rau nrhiav txoj hauv kev Java runtime, hauv ssh tus neeg siv nkag mus rau cov lus txib

sudo hloov tshiab-hloov pauv-ua si java

Koj yuav tsum pom cov lus teb nrog thawj ob kab uas zoo li cov hauv qab no:

java - pib hom

txuas qhov zoo tshaj plaws version yog/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java

Qhov "-8-" hauv kab thib ob lees paub tias lub sijhawm pib ua haujlwm yog Java 8. Sau txoj hauv kev ntawm kab thib ob raws li koj yuav xav tau nws los teeb tsa NetBeans rau kev txhim kho tej thaj chaw deb hauv cov kauj ruam tom ntej.

Yog tias lub sijhawm ua haujlwm tsis yog Java 8, hauv ssh tus thov kev nkag mus rau cov lus txib hauv qab no kom hloov mus rau Java 8 (piv txwv tias nws tau teeb tsa)

sudo hloov tshiab-hloov pauv --config java

Kauj Ruam 2: Nruab NetBeans ntawm Workstation

Tam sim no koj yuav tsum teeb tsa NetBeans ntawm koj lub chaw haujlwm. Taw tes koj lub browser chaw haujlwm rau NetBeans rub tawm nplooj ntawv. Koj yuav pom ntau qhov ua tau ua ke uas txhawb nqa ob tsab ntawm Java nrog rau lwm yam lus. Txhua yam koj xav tau rau Java kev txhim kho rau Raspberry Pi yog Java SE, tab sis koj tuaj yeem tau txais Java EE pob khoom lossis Txhua pob khoom. Thaum koj txiav txim siab pob khoom twg koj xav tau nyem lub pob download uas raug. Koj tuaj yeem pom cov lus qhia teeb tsa ntxiv rau koj lub chaw ua haujlwm OS ntawm no.

Thaum koj tau teeb tsa NetBeans, pib nws (nws tuaj yeem ua tau tom qab teeb tsa). Koj yuav tsum pom NetBeans lub qhov rai loj raws li qhia hauv daim duab. Daim duab tau yees duab ntawm Mac, thiab lub qhov rais loj yuav zoo li txawv me ntsis ntawm Windows.

Thaum koj tau ua tiav teeb tsa thiab pib NetBeans, mus rau kauj ruam tom ntej.

Kauj Ruam 3: Txhim Kho Raspberry Pi Raws Li Qhov Chaw Nyob Hauv NetBeans

Kho lub Raspberry Pi Raws li Lub Chaw Taws Teeb hauv NetBeans
Kho lub Raspberry Pi Raws li Lub Chaw Taws Teeb hauv NetBeans

Cov kev ua hauv qab no teeb tsa Raspberry Pi ua qhov chaw deb Java SE platform rau NetBeans. Qhov no ua rau NetBeans rub tawm thiab ua tiav Java cov haujlwm hauv Pi. Koj tuaj yeem pom cov lus piav qhia me ntsis ntawm no.

NCO TSEG: Hauv qhov no thiab cov theem hauv qab no, kuv qhia qhov tseem ceeb tshwj xeeb rau kuv ib puag ncig rau ntau yam ntawm kev teeb tsa thiab coding; koj yuav pom tseeb sib txawv.

Txhawm rau teeb tsa Pi ua lub platform nyob deb:

  1. Hauv NetBeans lub tshuab raj tseem ceeb, xaiv Cov Cuab Yeej -> Java Platforms. Koj yuav pom Java Platform Manager popup window (daim duab ib).
  2. Nyem Ntxiv Platform ntawm sab laug sab laug. Koj yuav pom qhov Add Java Platform [platform type] popup (daim duab ob).
  3. Xaiv Remote Java Standard Edition. Nyem Tom ntej no. Koj yuav pom Ntxiv Java Platform [teeb tsa lub platform deb] popup (daim duab peb pom cov popup tom qab kuv nkag mus rau qhov tsim nyog rau kuv ib puag ncig hauv cov teb).
  4. Hauv Lub Npe Lub Npe, sau lub npe rau Pi. Koj tuaj yeem siv txhua yam zoo nkauj, tab sis nws yuav tsum yog qhov tshwj xeeb.
  5. Hauv tus tswv tsev sau tus IP chaw nyob rau Pi pom hauv qib 1.
  6. Hauv Username teb sau tus neeg siv lub npe koj siv hauv qib 1.
  7. Tawm Siv Kev Siv Tus Kheej Tus Kheej uas tau xaiv thiab hauv tus lej Password sau tus lej koj tau tsim hauv qib 1.
  8. Hauv thaj chaw deb JRE Path koj yuav tsum nkag mus rau feem ntau ntawm txoj kev mus rau Java runtime ntawm Pi. Hauv qib 1, nws yog/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java. Txawm li cas los xij koj yuav tsum tso tawm /bin /java hauv tus nqi teb.
  9. NetBeans rub tawm cov haujlwm uas ua haujlwm tau mus rau cov npe ua haujlwm ntawm Pi, txheeb xyuas hauv Chaw Ua Haujlwm Dir. Lub neej ntawd yog/the_Pi_user_ID/NetBeansProjects/thiab nws ua tau zoo kawg nkaus. Koj tuaj yeem siv qee yam sib txawv yog tias koj xav tau, txawm hais tias nws yuav tsum muaj rau the_Pi_user_ID (daim duab peb).
  10. Nyem Finish nyob rau hauv qab txoj cai ntawm cov popup. Tom qab ua tiav, koj yuav tsum rov pom Java Platform Manager popup window. Tam sim no koj yuav tsum pom koj tus Pi nyob deb (nyob rau hauv lub npe koj siv hauv kev nqis tes ua 4 saum toj no) nyob rau hauv qeb Qhib Java SE (duab plaub).
  11. Nyem Test Platform ntawm sab laug sab laug txhawm rau sim kev sib txuas ntawm NetBeans thiab koj Pi. Koj yuav pom thawj zaug popup hais tias Txheeb Xyuas Chaw Taws Teeb. Yog tias ua tiav, koj yuav tau txais qhov tshwm sim thib ob qhia txog Kev Sib Txuas … ua tiav. Yog tias tsis yog, koj yuav tsum txheeb xyuas thiab kho cov ntaub ntawv koj tau nkag mus rau hauv Add Java Platform [teeb tsa lub platform deb] popup hauv kev nqis tes 5-9 saum toj no. Koj tuaj yeem ua li ntawd los ntawm Java Platform Manager popup; tsuas yog xaiv koj lub platform Pi thiab tom qab ntawd hloov kho cov teb ntawm sab xis ntawm cov popup.
  12. Tom qab ua tiav kev sib txuas, nyem Kaw hauv Java Platform Manager popup. Tam sim no koj yuav pom NetBeans lub qhov rais loj.

Tam sim no kev lom zem tiag tiag tuaj yeem pib!

Kauj Ruam 4: Tsim Java Project ntawm Workstation

Qhov no tsis yog lub hom phiaj los piav qhia txog yuav siv NetBeans, lossis Java, tab sis kuv yuav piav qhia qhov kev nqis tes ua tsawg tshaj plaws los sau ib qhov program hauv NetBeans ntawm chaw ua haujlwm thiab, thaum kawg, khiav qhov haujlwm nyob deb ntawm Raspberry Pi.

Hauv NetBeans koj yuav tsum xub tsim txoj haujlwm los tuav Java chav kawm (es) rau txoj haujlwm. Ntxiv mus, hauv Java, cov chav kawm nyob hauv pob khoom txhawb nqa lub koom haum thiab kev nyab xeeb. Txhawm rau tsim txoj haujlwm thiab xaiv tau tsim pob thiab chav kawm ntawv:

  1. Hauv NetBeans lub qhov rai tseem ceeb, nyem rau lub cim tshiab ua haujlwm (thib 2 ntawm sab laug). Koj yuav pom Txoj Haujlwm Tshiab [xaiv qhov project] popup (daim duab ib).
  2. Lub neej ntawd (Pawg: Java, Project: Java Application) yog qhov raug rau qhov piv txwv no, yog li yooj yim nyem Next. Koj yuav pom Daim Ntawv Thov Java Tshiab [lub npe thiab chaw nyob] popup (daim duab ob qhia qhov tseem ceeb rau kuv tus piv txwv). NCO TSEG: Kuv tau rov kho kuv cov neeg siv cov ntaub ntawv siv cov duab plaub plaub.
  3. Hauv qhov Project Name field, nkag mus rau Java lub npe siv tau uas koj xaiv. Lub npe yuav tsum pib nrog cov tsiaj ntawv loj, thiab kev pom zoo qhia txog rooj plaub ntxhuav thaum sib tham cov lus.
  4. Txoj Haujlwm Qhov Chaw Nyob tswj hwm qhov haujlwm nyob hauv koj cov ntaub ntawv. Lub neej ntawd txawv nws txawv nyob ntawm kev ua haujlwm, tab sis muaj kev nyab xeeb txais.
  5. Qhov Project Folder teb tso cai rau koj los tswj lub npe nplaub tshev rau txoj haujlwm. Kuv pom nws zoo tshaj plaws los siv lub neej ntawd, uas yog kev sib koom ua ke ntawm Qhov Chaw Nyob thiab Npe Npe.
  6. Thaum Tus Tsim Tus Kheej Cov Ntsiab Lus tau txheeb xyuas NetBeans cia li tsim cov pob thiab cov ntawv tseem ceeb hauv chav kawm (ib txoj haujlwm uas tuaj yeem khiav los ntawm kab hais kom ua) nrog tib lub npe raws li txoj haujlwm. Kuv xav tias feem ntau nws yuav tsum tsis raug tshuaj xyuas, tab sis hauv qhov no, kuv yuav tso nws tawm qhov uas tshem tawm cov lus qhia yam tsis tas yuav tsum tau ua (daim duab ob).
  7. Nyem Finish los tsim txoj haujlwm, pob thiab cov ntaub ntawv tseem ceeb hauv chav kawm. Tam sim no sab saud sab saud ntawm NetBeans lub qhov rai tseem ceeb qhia koj txoj haujlwm, uas muaj ib pob, uas nyob rau hauv lem muaj cov ntawv ib chav kawm nrog rau lub ntsiab () txheej txheem. Sab saum toj txoj cai pane muaj lub hauv paus qhov chaws rau chav kawm tseem ceeb (txoj haujlwm) tau tsim los ntawm NetBeans (daim duab peb).

Txij ntawm no mus, koj tuaj yeem sau qee cov cai hauv txoj hauv kev tseem ceeb thiab khiav nws ntawm chaw ua haujlwm. Qhov ntawd tej zaum yuav txaus siab rau lub sijhawm, tab sis tsis tsim nyog rau Cov Lus Qhia no, yog li npaj mus rau kauj ruam tom ntej.

Kauj Ruam 5: Txhim Kho NetBeans Project kom Ua Haujlwm Nyob Hauv Raspberry Pi

Txhawm rau teeb tsa NetBeans txoj haujlwm, thiab ib qhov program nws muaj, kom khiav deb ntawm Raspberry Pi, ua cov hauv qab no:

  1. Txoj cai lossis 2-ntiv tes nyem (nyob ntawm qhov chaw ua haujlwm OS) ntawm qhov haujlwm hauv Projects pane ntawm NetBeans lub qhov rais loj kom coj mus rau qhov project cov ntawv qhia zaub mov thiab nyem Properties. Koj yuav pom qhov Project Properties popup (daim duab qhia pom popup nrog qhov tsim nyog rau kuv qhov piv txwv).
  2. Hauv qab Pawg ntawm sab laug, xaiv Khiav.
  3. Nyem Tshiab rau sab xis ntawm Configuration teb. Hauv qhov tshwm sim Tsim Tshiab Configuration popup, sau lub npe rau kev teeb tsa thiab nyem OK. Lub npe tuaj yeem yog txhua yam; Kuv nyuam qhuav rov siv lub npe ntawm lub platform ("Kuv Pi"). Ib zaug ntxiv koj yuav pom qhov Project Properties popup.
  4. Nyem rau lub cim tso rau sab xis ntawm Runtime Platform teb. Los ntawm cov npe hauv cov popup, xaiv lub platform nyob deb uas koj tau tsim ua ntej (hauv kuv ib puag ncig, "Kuv Pi").
  5. Nyem OK txhawm rau teeb tsa lub chaw taws teeb rau txoj haujlwm. Koj yuav rov pom lub qhov rai tseem ceeb dua.

Tam sim no koj tau npaj los sau cov cai thiab khiav qhov haujlwm nyob deb.

Kauj Ruam 6: Sau Java Program ntawm Chaw Ua Haujlwm thiab Khiav Nws ntawm Raspberry Pi

Lub vaj huam sib luag sab xis hauv NetBeans lub qhov rai tseem ceeb qhia txog chav kawm tseem ceeb tsim los ntawm NetBeans. Ntaus cov lus sau yooj yim hauv txoj hauv kev tseem ceeb ntawm chav kawm ntawv (daim duab ib). Nws yog tam sim no ua tiav Java program uas ua qee yam, txawm hais tias qee yam yooj yim heev.

Txhawm rau khiav qhov haujlwm ntawm Pi, nyem rau lub cim Khiav (ntsuab ntsuab-taw qhia xub) hauv lub qhov rais loj. NetBeans suav sau cov cai, tsim cov ntaub ntawv thawv, rub cov ntawv ntim rau Raspberry Pi txheeb xyuas los ntawm cov chaw taws teeb, ua haujlwm txoj haujlwm ntawm Pi, ntes cov zis (System.out) ntawm qhov program, thiab ncha uas tawm mus rau NetBeans Cov ntawv tso tawm ntawm sab xis sab xis ntawm lub qhov rais loj (daim duab ob).

Tam sim no koj tau nthuav dav koj cov txuj ci tsim los tsim cov phiaj xwm ntawm Raspberry Pi! Tab sis tos…. Muaj ntau dua!

Kauj Ruam 7: Debug Java Program Nrog NetBeans

Ib qho ntawm cov yam ntxwv muaj zog tshaj plaws ntawm kev tsim khoom muaj zog Kev Txhim Kho Ib Leeg Ib puag ncig zoo li NetBeans yog lub peev xwm los debug qhov haujlwm thaum ua haujlwm. NetBeans tso cai rau koj ua kom muaj zog tag nrho ntawm cov cuab yeej debugging thaum ua haujlwm nyob deb. Qhov no suav nrog teeb tsa cov ntsiab lus ntawm "qhov tseem ceeb" lossis "teeb meem" qhov chaw hauv qhov haujlwm thiab tshuaj xyuas tus nqi ntawm qhov hloov pauv ntawm lub xeev ua tiav tam sim no.

Qhov kev zov me nyuam yooj yim hauv qib kawg yog yooj yim dhau los ua kom pom debug, yog li kuv tau ntxiv qee qhov chaws ntxiv rau qhov haujlwm. Cov cai ntxiv ntxiv ob qhov hloov pauv.

Txhawm rau siv cov cuab yeej debug, koj yuav tsum xub teeb tsa ib lossis ntau qhov kev tawg. Txhawm rau teeb tsa lub hauv paus, nyem rau kab kab uas koj xav ncua kev ua; lub cim duab plaub liab tshwm, thiab tag nrho kab tau txais keeb kwm liab (daim duab ib).

Txhawm rau debug qhov haujlwm ua haujlwm ntawm Pi, nyem lub Debug icon (tam sim ntawd mus rau sab xis ntawm Run icon) hauv NetBeans lub qhov rais loj. Raws li nrog kev ua tiav ib txwm muaj, NetBeans suav sau, tsim, rub tawm, ua tiav, ntes cov zis, thiab ncha uas tso tawm. Tab sis nrog kev debugging, NetBeans nres qhov kev ua tiav ntawm qhov chaw tawg thiab tso cai rau koj los tshuaj xyuas lub xeev kev ua tiav (daim duab ob, qhia qhov Variables pane ntawm sab xis).

Kev ua tiav nres ntawm qhov chaw nres tsheb ua ntej ua tiav cov lus qhia ntawm kab nrog tus nres Cov keeb kwm ntsuab ntsuab qhia txog nqe lus tom ntej kom ua tiav. Yog li hauv kuv qhov piv txwv, nrog tus lej tawg ntawm kab 9, qhov sib txawv a tseem tsis tau muaj, ntau tsawg muaj tus nqi.

Tam sim no yuj tus cursor hla qhov debug ntawv qhia zaub mov icon hauv lub qhov rai tseem ceeb (thawj ob-xub-nqis lub cim rau sab xis ntawm Debug icon) thiab nyem rau lub cim Kauj Ruam Tshaj (nws muaj daim ntawv xiav nyob rau tom qab thiab ntsuab xub rov qab hauv ntej). [NCO TSEG: yog tias koj ua rau koj lub NetBeans lub qhov rais loj txaus, cov ntawv qhia zaub mov debug nthuav dav thiab cov kev ua kom debug lub cim qhia pom nyob rau sab xis ntawm Debug icon.] NetBeans ua cov lus ntawm qhov chaw nres thiab nres ua ntej ua ntej cov lus tom ntej. Tam sim no koj yuav pom tias qhov sib txawv muaj tshwm sim thiab muaj txiaj ntsig zoo (daim duab peb).

Nyem rau Step Over icon ob zaug. Koj yuav pom tias tag nrho peb qhov kev hloov pauv muaj nuj nqis; nco ntsoov tias c tseem yog xoom (daim duab plaub).

Nyem rau Step Over icon ib zaug. Koj yuav pom qhov sib txawv c tam sim no muaj tus nqi tsim nyog, piv txwv li, cov lej sib txawv ntawm a thiab b (daim duab tsib).

Thaum kawg, hauv cov ntawv qhia zaub mov debug, nyem rau lub cim Khiav (lub voj voog ntsuab nrog tus xub dawb). Qhov ntawd ua rau kev ua tiav txuas ntxiv mus rau qhov cuam tshuam tom ntej, lossis mus rau qhov kawg ntawm txoj haujlwm, qhov twg los xij ua ntej. Tam sim no Cov Ntawv Tso Tawm tshwm thiab pom zoo ib yam li ib txwm ua tiav, hauv qhov no cov ntawv hauv kab lus luam tawm.

Kauj Ruam 8: Ua Haujlwm Txoj Haujlwm Ywj Pheej ntawm NetBeans

Lub sijhawm yuav los txog thaum koj xav ua koj txoj haujlwm ntawm Raspberry Pi, yam tsis muaj "kev pabcuam" lossis "cuam tshuam" los ntawm NetBeans. Nws yog qhov yooj yim heev. Ua ntej, qhib ssh tus thov rau koj Pi.

Nco ntsoov los ntawm theem 3 uas NetBeans tso koj lub phiaj xwm phiaj xwm hauv cov npe ua haujlwm ntawm Pi. Lub hauv paus pib yog/tsev/pi/NetBeansProjects rau cov neeg siv pi. Cov npe tshwj xeeb muaj tib lub npe zoo li koj qhov project. NetBeans tso lub thawv rau hauv cov npe me me hu ua dist. Rau kuv qhov piv txwv, tag nrho txoj hauv kev yog/home/pi/NetBeansProjects/MyRemoteProg/dist. Hauv ssh tus thov kev pab ntawm Pi, kom ua tiav txoj haujlwm koj tuaj yeem siv java hais kom ua nrog 'thawv' xaiv:

java -jar /home/pi/NetBeansProjects/MyRemoteProg/dist/MyRemoteProg.jar

Koj yuav pom cov txiaj ntsig ntawm kev ua tiav hauv ssh tus thov kev pab; hauv kuv qhov piv txwv, cov zis yuav yog

Nyob zoo los ntawm Raspberry Pi!

Qhov no ua haujlwm vim tias cov ntaub ntawv hauv lub thawv ntawv txheeb xyuas cov chav kawm tseem ceeb hauv lub thawv kom ua tiav.

Koj tseem tuaj yeem hloov pauv cov npe ua haujlwm (ntawm cd) mus rau qhov chaw ntawm cov ntaub ntawv thawv thiab tom qab ntawd muab cov lus txib luv los tsim cov txiaj ntsig zoo ib yam.

java -jar MyRemoteProg.jar

Kauj Ruam 9: Tsim thiab Rub Tawm, Tab sis Tsis Ua Raws Txoj Haujlwm Via NetBeans

Muaj xwm txheej uas koj xav kom NetBeans tsim thiab rub tawm koj qhov program, tab sis tsis ua nws. Ib qho xwm txheej zoo li no tshwm sim thaum koj qhov program xav tau cov keyboard nkag. Yog tias qhov no yog siv cov txheej txheem hauv qib dhau los, ib zaug koj tsim thiab rub tawm, qhov haujlwm tau ua rau ntawm Raspberry Pi thiab yog li cia siab tias cov keyboard nkag los ntawm Pi, tab sis qhov tseeb, tsis muaj cov keyboard txuas rau Pi, yog li qhov program cuam tshuam - tsis zoo.

Koj yuav tsum siv cov txheej txheem sib txawv me ntsis los ua txoj haujlwm. Hauv paus, koj tsim "dummy" cov ntaub ntawv tseem ceeb hauv chav kawm uas tsis muaj ib yam dab tsi, thiab txheeb xyuas nws raws li txoj haujlwm kom ua tiav tom qab rub tawm. Hauv qhov no, "dummy" tau ua tiav, thiab tom qab ntawd koj tuaj yeem ua haujlwm koj qhov "tiag" program ncaj qha rau ntawm Pi.

Txhawm rau siv cov txheej txheem no, ua ntej tsim chav kawm tseem ceeb tshiab:

  1. Nqa cov phiaj xwm phiaj xwm raws li hauv qib 5 thiab nyem Tshiab-> Java Main Class. Koj yuav pom New Java Main Class popup.
  2. Hauv Class Name field sau ib lub npe. Lub npe tuaj yeem yog txhua yam koj nyiam; Kuv siv "Dummy". Cov pob ntawv tso cai rau koj txheeb xyuas chav kawm 'pob; koj xaiv pob uas siv qhov nco cia rau sab xis ntawm daim teb. Cov chav kawm tuaj yeem nyob hauv ib pob zoo ib yam li koj qhov program "tiag" lossis hauv pob sib txawv; Kuv muab cov chav kawm tshiab rau hauv tib lub pob. Nyem tag. Tam sim no koj yuav pom NetBeans lub qhov rai tseem ceeb nrog cov ntawv tshiab nyob rau sab saum toj vaj huam sib luag (daim duab ib). Kuv ntxiv cov lus sau yooj yim hais txog kev khiav ntawm Pi, tab sis tsis muaj dab tsi xav tau tiag tiag.

Txhawm rau khiav "Dummy" tom qab rub tawm koj yuav tsum ua nws "chav kawm tseem ceeb kom ua tiav los ntawm lub neej ntawd" rau txoj haujlwm:

  1. Qhib qhov Project Properties raws li hauv kauj ruam 5. Xaiv Pawg Run. Nyem Xauj mus rau sab xis ntawm Main Class field. Koj yuav pom Browse Main Classes popup (daim duab ob).
  2. Xaiv chav kawm "Dummy". Nyem Xaiv Cov Chav Kawm Loj. Koj yuav rov pom qhov Project Properties dua.
  3. Nyem OK. Koj yuav rov qab mus rau lub qhov rai tseem ceeb.

Tam sim no thaum koj nyem rau lub cim Khiav, NetBeans ua raws/tsim tag nrho txoj haujlwm, rub lub thawv uas muaj txhua cov ntaub ntawv hauv chav kawm mus rau Pi, thiab ua tiav "Dummy" chav kawm (daim duab peb).

Txhawm rau ua tiav koj txoj haujlwm tiag tiag ntawm Pi, koj yuav tsum tam sim no siv java hais kom ua nrog qhov 'classpath' kev xaiv, uas xav kom koj qhia meej meej txog chav kawm tseem ceeb kom ua. Los ntawm ib tus neeg siv ssh mus rau cov npe luv rau koj txoj haujlwm. Qhov hais kom ua yog ntawm daim ntawv:

java -cp project_name.jar package_name.class_name

Qhov project_name pom tseeb hais txog txoj haujlwm; uas hloov pauv tsuas yog thaum cuam tshuam nrog txoj haujlwm tshiab. Package_name ntawm chav kawm hais txog pob, thiab class_name hais txog chav kawm tseem ceeb kom ua. Raws li tau hais ua ntej, txoj haujlwm tuaj yeem muaj ntau pob. Zoo sib xws, pob tuaj yeem muaj ntau chav kawm, thiab txhua qhov tuaj yeem yog chav kawm tseem ceeb, lossis cov haujlwm, uas tuaj yeem ua tiav los ntawm kab hais kom ua. Yog li, cov txheej txheem 'classpath' yog qhov muaj txiaj ntsig zoo rau kev txhim kho cov haujlwm zoo nrog ntau chav kawm, qee qhov yog cov chav kawm tseem ceeb tsuas yog pab txhawb kev ntsuas chav.

Cov lus txib hauv qab no ua tiav kuv qhov kev pab cuam piv txwv:

java -cp MyRemoteProg.jar myremoteprog. MyRemoteProg

Kauj Ruam 10: Leverage NetBeans Library Management

Ib qho ntawm qhov nyuaj tshaj plaws tab sis qhov tseem ceeb tshaj plaws ntawm cov khoos phis tawj ntse yog cuam tshuam nrog cov tsev qiv ntawv, piv txwv li, tus lej lwm tus tau sau lawm. NetBeans ua txoj haujlwm zoo ntawm kev tshem tawm feem ntau qhov mob ntawm kev tswj hwm lub tsev qiv ntawv.

Kuv yuav siv ua piv txwv Pi4J, uas muab cov khoos kas Java nkag mus rau Raspberry Pi GPIO, I2C npav, thiab lwm yam kho vajtse I/O. Pi4J yog tab sis ib qho piv txwv ntawm kev txhawb nqa ua ntau yam lom zem ntawm Pi nrog Java.

Koj yuav tsum xub rub lub tsev qiv ntawv mus rau koj lub chaw haujlwm. Saib nplooj ntawv Pi4J rub tawm. Txij li thaum koj tsis tau txhim kho Pi4J ntawm Pi, rub tus zip rau koj lub chaw ua haujlwm. Koj tuaj yeem lossis yuav tsis tas yuav nthuav tawm qhov tseeb thaum zip tau rub tawm.

Tam sim no koj yuav tsum tsim "lub tsev qiv ntawv thoob ntiaj teb" hauv NetBeans:

  1. Hauv NetBeans cov zaub mov tseem ceeb, nyem Cov Cuab Yeej -> Tsev Qiv Ntawv. Koj yuav pom Ant Ant Manager Manager popup (daim duab ib).
  2. Nyem Tshiab Lub Tsev Qiv Ntawv hauv qab sab laug. Koj yuav pom New Library popup (daim duab ob).
  3. Ntaus lub npe muaj txiaj ntsig koj xav siv thiab nyem OK. Koj yuav pom ib zaug ntxiv Ant Ant Manager Manager popup. Tam sim no nws qhia lub tsev qiv ntawv tshiab uas koj tau tsim (daim duab peb).
  4. Nyem Ntxiv JAR/Folder ntawm sab xis. Koj yuav pom Browse JAR/Folder popup (daim duab plaub).
  5. Nkag mus rau thiab tom qab ntawd xaiv pi4j-core.jar. Tom qab ntawv nyem Ntxiv JAR/Folder. Koj yuav rov qab mus rau Ant Ant Manager Manager popup.
  6. Hauv Ant Ant Manager Manager popup nyem OK. Koj yuav rov qab mus rau NetBeans lub qhov rai tseem ceeb.

Koj tau ntxiv lub tsev qiv ntawv kom nws tuaj yeem siv rau hauv txhua qhov haujlwm. Tam sim no koj yuav tsum ntxiv cov tsev qiv ntawv rau koj qhov haujlwm:

  1. Nqa qhov Project Properties popup (saib cov kauj ruam 5) thiab xaiv Cov Tsev Qiv Ntawv (duab tsib).
  2. Nyem Ntxiv Tsev qiv ntawv ntawm sab xis ntawm qhov tshwm sim. Koj yuav pom qhov Add Library popup (daim duab rau).
  3. Nkag mus rau lub tsev qiv ntawv thiab xaiv nws. Tom qab ntawv nyem Ntxiv Lub Tsev Qiv Ntawv. Koj yuav rov pom qhov Project Properties popup. Lub tsev qiv ntawv tam sim no tshwm nyob rau hauv cov npe Cov Sijhawm Qub Qub hauv cov popup.
  4. Hauv qhov Project Properties popup nyem OK. Koj yuav rov qab mus rau lub qhov rai tseem ceeb.

Koj tau ntxiv lub tsev qiv ntawv rau koj qhov haujlwm kom koj txoj haujlwm tuaj yeem siv nws. Koj tuaj yeem ua tib ntu ntawm kev nqis tes ua rau ib lub tsev qiv ntawv uas koj xav tau rau txoj haujlwm.

Muaj peb zaug koj xav tau lub tsev qiv ntawv - suav sau, tsim, thiab ua tiav. Hmoov zoo, nrog NetBeans, ntxiv lub tsev qiv ntawv raws li qhia saum toj no ua haujlwm tag nrho. Txhawm rau lees paub qhov no, kuv tau tsim lwm chav kawm tseem ceeb uas ua qhov tsawg kawg nkaus uas yuav tsum tau siv I2C lub peev xwm hauv Pi4J (daim duab xya). Qhov tseeb tias tsis muaj qhov yuam kev qhia txhais tau tias chav kawm TestPi4J suav sau. Nyem Khiav kom ua tiav thiab rub tawm; NetBeans rub tawm lub tsev qiv ntawv ntxiv rau lub thawv ntawv, yog li qhov program yuav ua. Txhawm rau txheeb xyuas qhov kawg, koj tuaj yeem siv cov txheej txheem hauv qib 9 thiab hauv ssh tus neeg siv nkag mus rau cov lus txib hauv qab no (los ntawm cov npe nyob deb):

java -cp MyRemoteProg.jar myremoteprog. TestPi4J

Nws yog qhia kom nkag siab yuav ua li cas NetBeans saib xyuas cov tsev qiv ntawv. Thaum nyob hauv phau ntawv teev npe sib txawv rau koj txoj haujlwm, sau cov ntsiab lus ntawm phau ntawv teev npe (siv cov lus txib ls) thiab koj yuav pom lib lib subdirectory. Sau cov ntsiab lus ntawm cov npe ntawd thiab koj yuav pom cov ntaub ntawv thawv txheeb hauv lub tsev qiv ntawv thoob ntiaj teb, uas hauv kuv qhov piv txwv yog pi4j-core.jar. Txhua lub tsev qiv ntawv uas koj ntxiv rau txoj haujlwm yuav tshwm nyob rau hauv phau ntawv teev npe lib, thiab yog li muaj rau txhua qhov haujlwm hauv cov phiaj xwm phiaj xwm.

Kauj ruam 11: Mus Zoo Siab

Kuv tau piav qhia txoj hauv kev kom ua tiav Java txhim kho tau zoo rau Raspberry Pi. Raspberry Pi yog lub thev naus laus zis nrov nrov rau kev nthuav dav ntawm cov phiaj xwm. Java yog cov txuj ci qib qib lus uas muaj kev ua tau zoo dua Python thiab muaj kev nyab xeeb zoo dua C/C ++. NetBeans yog qib IDE kev tshaj lij uas ua rau cov neeg tsim khoom tsim tau zoo dua.

Kuv xav tias qhov kev sib xyaw ua kom yuam kev. Tam sim no, mus muaj kev lom zem siv ua ke rau koj cov haujlwm.

Pom zoo: