A cikin duniyar yau, saita masu canjin yanayi akan kwamfutarka wani muhimmin sashi ne na tsarin haษaka software. Daya daga cikin irin wannan m shine gidan_ a kan tsarin aiki na Mac. Manufar wannan labarin shine don samar da cikakken jagora kan yadda ake saita the_home a cikin yanayin Mac ta amfani da lambar Java. Ba wai kawai za mu tattauna maganin wannan matsala ba, har ma mu bincika mataki-mataki-mataki bayanin lambar, ษakunan karatu da ayyukan da suka dace, da sauran cikakkun bayanai don tabbatar da cikakken fahimtar tsarin.
Maganin Matsala
Mataki na farko a saitin gidan_ m akan tsarin Mac shine ฦirฦirar shirin Java wanda ke sarrafa shi System kaddarorin. Waษannan kaddarorin suna adana bayanai game da saitunan da aka fi so da mai amfani. Don saita gidan, za mu yi amfani da System.setProperty() Hanya.
public class SetHome { public static void main(String[] args) { System.setProperty("the_home", "your_desired_path"); System.out.println("The home is set to: " + System.getProperty("the_home")); } }
Bayanin mataki-mataki na Code
A cikin snippet na lambar da ke sama, za mu fara da ฦirฦirar ajin Java mai suna SaitaHome. Wannan aji ne zai ษauki alhakin saita gidan_ m a cikin Mac tsarin. Na gaba, mun ayyana ma'anar main hanya a cikin aji, wanda zai zama wurin shigarwa na shirin mu.
A cikin main hanyar da muke amfani da ita System.setProperty() aiki don saita ฦimar canjin_gida zuwa hanyar al'ada da muka zaษa (a wannan yanayin, "hanyar_desired_your_desired_"). Wannan hanya tana karษar sigogi guda biyu, na farko shine sunan canjin, na biyu kuma shine ฦimar da kake son sanya mata.
Bayan saita darajar gidan, zamu dawo da ฦimar ta amfani da System.getProperty() hanyar kuma fitar da shi zuwa na'ura mai kwakwalwa ta hanyar System.out.println() sanarwa. Wannan yana tabbatar da cewa an saita canjin_home cikin nasara.
Tsarin Tsarin Java
The Tsarin tsarin Java wani muhimmin sashe ne na yaren shirye-shiryen Java kuma yana daga cikin jawa.lang kunshin. Yana ba da hanyoyin amfani daban-daban da kaddarorin don sarrafa muhalli, hulษa tare da kaddarorin tsarin, da aiwatar da ayyuka kamar tarin shara. Misalai na sauran hanyoyin da aka saba amfani da su ta hanyar ajin Tsarin sun haษa da System.currentTimeMillis() da kuma System.arraycopy().
Yin aiki tare da Canjin Muhalli a Java
Harshen shirye-shiryen Java yana ba da hanya mai dacewa don aiki tare da masu canjin yanayi ta amfani da System.getenv() hanya. Wannan hanyar tana dawo da ฦimar nau'in java.util.Map wanda ya ฦunshi maษalli-darajar nau'i-nau'i na duk masu canjin yanayi da aka ayyana akan tsarin. Don saita canjin yanayi, zaku iya amfani da ProcessBuilder class da ta muhalli() hanya. Tsarin saita canjin yanayi a Java ba shi da sauฦi kamar saita kayan tsarin, amma har yanzu yana yiwuwa.
A ฦarshe, yin magudi gidan_ m a kan tsarin Mac ta amfani da shirin Java ba kawai mai sauฦi ba ne amma kuma yana da amfani. Ta hanyar yin amfani da ฦarfin ajin Tsarin Java, yana da sauฦi don saitawa da samun kaddarorin tsarin kamar the_home. Kuma yayin aiki tare da masu canjin yanayi na iya buฦatar wata hanya ta ษan bambanta, Java yana ba da isassun kayan aiki a cikin nau'in ajin ProcessBuilder don cimma sakamakon da ake so. Tare da waษannan fasahohin da ke hannunku, saita gidan_gida a cikin tsarin Mac ya zama aiki mai kusanci.