Tải bản đầy đủ - 0 (trang)
Appendix A.  Installation Using install4j

Appendix A.  Installation Using install4j

Tải bản đầy đủ - 0trang

install4jVersusJWS

Beforestarting,it'sworthwhiletocompareinstall4jandJava

WebStart(JWS),thesubjectofAppendixB.install4jcreatesa

standaloneinstallerforanapplication,whichcanbedeliveredto

theuseronaCDordownloadedviaawebpagelink.Agreat

advantageisthefamiliarityoftheinstallationconcept:doubleclickontheEXEfile,pressafewYesbuttons,andthe

applicationappearsasamenuitemandadesktopicon.The

factthattheexecutableiscodedinJavabecomesirrelevant.

JWSisanetworksolution,whichoffersbetterprotectionfrom

potentiallyrenegadedownloads,andsupportsapplication

updates.JWSistypicallyutilizedviatheJWSclientthatcomes

aspartoftheJ2SEinstallation.Therelianceonanetwork

modelseemsrestrictive,especiallywhenapplicationsarelarge.

Thepossibilityofbeingqueriedaboutsecuritylevelsand

updatesisoff-puttingtonovicecomputerusers.



TheJava3DComponents

TogetBugRunnerandCheckers3Dtocompileandrun,you'llneedto

includerelevantbitsfromJava3D.OnWindows,theOpenGL

versionofJava3DconsistsoffourJARfilesandthreeDLLs.The

JARfilesarej3dcore.jar,j3daudio.jar,vecmath.jar,and

j3dutils.jarin\lib\ext\.TheDLLsareJ3D.dll,

j3daudio.dll,andJ3DUtils.dllin\bin\.is

thedirectoryholdingtheJRE,typicallysomethinglike

C:\ProgramFiles\Java\j2re1.4.2_02\.IftheJava3D

developmentkitisinstalled,thefileswillbefoundbelowthe

J2SEhomedirectory,whichisusuallysomethinglike

C:\j2sdk1.4.2_02orC:\ProgramFiles\Java\jdk1.5.0.

TheOSlevellibrarieswillvaryiftheDirectXversionofJava3D

isusedoriftheplatformisLinuxortheMacOS.Theeasiest

wayoffindingoutJava3D'scompositiononyourmachineisto

lookthroughtheJava3Dreadmefile,whichisaddedtothe

J2SEhomedirectoryatinstallationtime.



Java3DComponentsforBugRunner

TheBugRunnerapplicationusesonlytheJ3DTimer,sowhichofthe

JARandDLLfilesarerequired?TheJ3DTimerclassispartofthe

com.sun.j3d.utils.timerpackage,whichisstoredinj3dutils.jar

(confirmthisbylookinginsidetheJARwithatoolsuchas

WinZip),asshowninFigureA-1.



TheJ3DTimerclass(anditsinnerclass)accountforabout1KBoutofthe

1.2-MBJAR.



AlookatthedecompiledJ3DTimerclass,usingsoftwaresuchas

theDJJavadecompiler

(http://members.fortunecity.com/neshkov/dj.html),showsthat

asmallamountofJavacodecallsJ3DUtils.dlltodoallthework

(seeFigureA-2).

Forexample,theJavamethodgetValue()callstheJ3DUtils.dll

functiongetNativeTimer().

Analternativetodecompilingthe.classfileistodownloadthe

originalsource,whichisavailablefromtheJava3Dwebsite.

J3DUtils.dllcanbeexaminedwithHTEditor,afile

editor/viewer/analyzerforWindowsexecutables,availablefrom

http://hte.sourceforge.net/(showninFigureA-3).



FigureA-1.AWinZipviewofj3dutils.jar



FigureA-2.TheDJJavadecompilerviewof

J3DTimer



FigureA-3.TheHTeditorviewofJ3DUtils.dll



getNativeTimer()usestheWindowskernel32.dllfunctions

QueryPerformanceCounter()andQueryPerformanceFrequency().



Insummary,thecallstoJ3DTimerrequirej3dutils.jarand

J3DUtils.dll.



j3dutils.jaronaDiet

Itmaybeworthwhiletoseparatethetimercodefrom

j3dutils.jarandputitintoitsownJAR,therebysavingabout1.2

MBofspace.Thetechniqueinvolvesun-JARingj3dutils.jar

usingWinZiporsimilarcompressionsoftware.Theresultistwo

folders:com/andmeta-inf/.com/holdsthevariousclassesin

j3dutils,whichcanbedeleted,asidefromthetwotimerclasses

incom/sun/j3d/utils/timer/.meta-inf/holdsamanifestfile,

Manifest.mf,whichshouldbepulledoutofthedirectoryand

usedinthere-JARingprocess:



jarcvmfManifest.mfj3dutils.jarcom



Thesizeoftheslimmeddownj3dutils.jaris2KB,whichisquitea

difference.



Therealdrawbackwiththistechniquemaybealegalonesince

aSun-createdJARisbeingdismembered.Java3Disopen

sourcewithsomeprovisos,whichmaymakeitokaytorelease

modifications;licenseinformationcanbefoundat

https://java3d.dev.java.net/.Intherestofthisappendix,I'll

usethefullversionofj3dutils.jartoplayitsafe.



TheBugRunnerApplication

TheBugRunnercodeisunchangedfromChapter11,asidefrom

theadditionofonenewmethodintheBugRunnerclass,whichis

explainedinthenextsection.



PreparingtheJARs

I'massumingthatthetargetmachinefortheinstallation

doesn'thaveJava3Dinstalled,sothetestmachinewhereI

developtheinstallationshouldn'thaveiteither.Instead,

j3dutils.jarandJ3DUtils.dllareplacedintheBugRunner/

directory(asshowninFigureA-4).



FigureA-4.TheBugRunner/directory



SinceJava3Disn'tinstalledinastandardlocationcheckedby

javacandjava,thecallstothecompilerandJVMmustinclude

additionalclasspathinformation.ThecompileBR.batbatchfilein

BugRunner/containsthisline:

javac-classpath"%CLASSPATH%;j3dutils.jar"*.java



TheBugRunner.batbatchfilecontainsasimilarline:

java-cp"%CLASSPATH%;j3dutils.jar"BugRunner



There'snoneedtomentionJ3DUtils.dll,whichwillbefoundby

theJARaslongasit'sinthesamedirectory.

Oncetheprogramhasbeentested,theclassesandallother

applicationresourcesmustbepackagedupasJARspriorto

beingpassedtoinstall4j.TheBugRunnerapplicationconsistsof

variousclassesandthetwosubdirectories,Images/and

Sounds/.Theseshouldbethrowntogetherintoasingle

BugRunner.jarfile,alongwithanyDLLs.ThemakeJar.batbatch

filecontainsthefollowingline:



jarcvmfmainClass.txtBugRunner.jar*.class*.dllImagesS



ThemanifestdetailsinmainClass.txtareasfollows:

Main-Class:BugRunner

Class-Path:j3dutils.jar



Themanifestspecifiestheclasslocationoftheapplication's



main()methodandaddsj3dutils.jartotheclasspathusedwhen



BugRunner.jarisexecuted.Forthisexample,theapplication

assumesthisJARinthesamedirectoryasBugRunner.jar.



Sinceyou'recontrollingtheinstallationprocess,thisisn'tthatbigofa

requirementandnotalimitation.



TheDLLisstoredintheJARbecausetheinstallationiseasierif

install4jonlyhastodealwithJARs.However,afterthe

installationEXEfilehasbeendownloadedtotheuser'smachine,

theDLLmustberemovedfromBugRunner.jarandwrittento

thenewBugRunner/directory.ThiscopyingfromtheJARtothe

localdirectoryiscarriedoutbytheBugRunnerclass,whichisthe

newmethodImentionedearlier.main()inBugRunnercallsan

installDLL()method:

publicstaticvoidmain(Stringargs[])

{

//DLLsusedbyJava3DJ3DTimerextension

installDLL("J3DUtils.dll");



longperiod=(long)1000.0/DEFAULT_FPS;

newBugRunner(period*1000000L);//ms-->nanosecs

}



privatestaticvoidinstallDLL

(StringdllFnm)

/*InstallationoftheDLLtothelocaldirectory

fromtheJARfilecontainingBugRunner.*/

{

Filef=newFile(dllFnm);

if(f.exists())

System.out.println(dllFnm+"alreadyinstalled");



else{

System.out.println("Installing"+dllFnm);

//accesstheDLLinsidethisJAR

InputStreamin=ClassLoader.getSystemResourceAsStream

(dllFnm);

if(in==null){

System.out.println(dllFnm+"notfound");

System.exit(1);

}

try{//writetheDLLtoafile

FileOutputStreamout=newFileOutputStream(dllFnm);



//allocateabufferforreadingentrydata.

byte[]buffer=newbyte[1024];

intbytesRead;

while((bytesRead=in.read(buffer))!=-1)

out.write(buffer,0,bytesRead);



in.close();

out.flush();

out.close();

}

catch(IOExceptione)

{System.out.println("Problemsinstalling"+dllFnm);

}

}//endofinstallDLL()



installDLL()willbecalledeverytimethatBugRunnerisexecuted,



soinstallDLL()firstcheckswhethertheDLLispresentinthe

localdirectory.Ifnot,it'sinstalledbybeingwrittenouttoafile.

ThestreamfromtheDLLfileinsidetheJARiscreatedwith:



InputStreamin=ClassLoader.getSystemResourceAsStream(dllF



ThisworkssincetheDLLisinthesameJARasBugRunner,sothe

classloaderforBugRunnercanfindit.FigureA-5illustratesthe

technique.



FigureA-5.InstallingaDLLlocally



TheresultisthattheBugRunnerapplicationinstalledontheuser's

machinewillconsistoftwoJARs,BugRunner.jarand

j3dutils.jar.AfterthefirstexecutionofBugRunner,thesetwoJARs

willbejoinedbyJ3DUtils.dll.



Testing

ThebesttestingapproachistomovethetwoJARstoadifferent

machine,specificallyonethatdoesn'thaveJava3Dinstalled

(butJ2SEorJREmustbepresent).Double-clickon

BugRunner.jar,andthegameshouldbegin.TheJ3DUtils.dllwill

magicallyappearinthesamedirectory.Alternatively,the

applicationcanbetestedwiththiscommand:

java-jarBugRunner.jar



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Appendix A.  Installation Using install4j

Tải bản đầy đủ ngay(0 tr)

×