— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet539/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   535   536   537   538   539   540   541   542   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

JAR
101101 
101101 
10101000010 
1010 10 0 
01010 1 
1010101 
10101010 
1001010101 
Making an executable JAR
1
Make sure all of your class fi les are in 
the classes directory
We’re going to refi ne this in a few pages, but 
for now, keep all your class fi les sitting in the 
directory named ‘classes’. 
2
Create a manifest.txt fi le that states 
which class has the main() method
Make a text fi le named manifest.txt that has a 
one line:
Main-Class: MyApp
Press the return key after typing the Main-
Class line, or your manifest may not work 
correctly. Put the manifest fi le into the “classes” 
directory.
101101 
101101 
10101000010 
1010 10 0 
01010 1 
1010101 
10101010 
1001010101 
101101 
101101 
10101000010 
1010 10 0 
01010 1 
1010101 
10101010 
1001010101 
Main-Class: MyiApp
3
Run the jar tool to create a JAR fi le 
that contains everything in the classes 
directory, plus the manifest.
%cd MiniProject/classes 
%jar -cvmf manifest.txt app1.jar *.class
OR
%jar -cvmf manifest.txt app1.jar MyApp.class
classes
MyProject
101101 
101101 
classes
101101 
101101 
101101 
101101 
MyProject
Main-Class: MiniApp
manifest.txt
app1.jar
101101 
101101 
101101 
101101 
101101 
101101 
Main-Class: MiniApp
don’t put the .class 
on the end
no source 
code (.java) 
in the JAR
MyApp.class
classes
manifest.txt


586
 
chapter 17
Running (executing) the JAR
Java (the JVM) is capable of loading a class from a JAR, and calling 
the main() method of that class. In fact, the entire application can 
stay in the JAR. Once the ball is rolling (i.e., the main() method 
starts running), the JVM doesn’t care where your classes come 
from, as long as it can fi nd them. And one of the places the JVM 
looks is within any JAR fi les in the classpath. If it can see a JAR, the 
JVM will look in that JAR when it needs to fi nd and load a class.
%cd MyProject/classes
%java -jar app1.jar
app1.jar
101101 
101101 
101101 
101101 
101101 
101101 
Main-Class: MiniApp
classes
The JVM has to ‘see’ the JAR, so 
it must be in your classpath. The 
easiest way to make the JAR visible 
is to make your working directory 
the place where the JAR is.
The -jar flag tells the 
JVM you’re giving it a 
JAR instead of a class.
The JVM looks inside this JAR for 
a manifest with an entry for Main-
Class. If it doesn’t find one, you get 
a runtime exception.
Depending on how your operating system is confi gured, you 
might even be able to simply double-click the JAR fi le to launch 
it. This works on most fl avors of Windows, and Mac OS X. You 
can usually make this happen by selecting the JAR and telling 
the OS to “Open with...” (or whatever the equivalent is on your 
operating system).
Q: 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   535   536   537   538   539   540   541   542   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish