[Jsokoban-gamedevel] Re: Java Web Start
Brought to you by:
texx
From: Matthias J. <m....@gm...> - 2002-04-22 17:31:08
|
hi 1. webstart: what do you think if we implement all features for you implement in the ws version that work also in the standard version.. and for the other thinks we create a own branch in the cvs. at which version you want to start with the ws version??? is 0.2beta2 possible you think? 2. next release 0.2beta2 it is possible to you to check in all your changes until the 30. April ?? then we shoult test the application. 1 week is enought i think. and report all bug in the bug system at soureforge and after that we have 2 weeks to fix the bugs we found. 3. i have added you to the project so now can use the cvs and commit your canges ... nice day matthias Gustavo Federico Bett wrote: >Matthias: > >I'm working with jws, and we have a problem... > >An application that uses jws should have all their files packed in jar >files (which is not our case). There are two kinds of environment for >a application. A untrusted environment (like the applet sandbox), that >restrict access to files, and to the network; and a trusted >environment, that does not have that limitations, but requires all the >files signed (and better if is from a trusted signer). > >I'm trying to make the application work in a untrusted environment, >the problem is how to load a file. >Below i quote a text that explains a possible solution (is from the >site of BlueJ http://www.bluej.org) >Tell me what do you think. > >Greetings > Federico > >PS: Did you receive my previous e-mail? (the one with a couple of bugs >in the current CVS tree) if you don't received it i send it again. > >>Here is a common problem: You want to access a file on disk (maybe an image, maybe a text file, or anything else for that matter), and you need to specify the name. You write some code similar to this: >> >>Image image = new ImageIcon("myImage.gif").getImage(); >> >>or >> >>FileInputStream stream = new FileInputStream("myFile.txt"); >> >>Then you discover that it doesn't work. (Or, as some people wrote to us, it "works when I run it from xxx, but not from BlueJ".) >> >>So why is that? >> >>Most people put their image or text file into the project directory, and then want it to be found. The problem is that this depends on the system's "current directory". This is not a BlueJ-specific problem, but a general Java problem. Only, you may discover it for the first time when you use BlueJ. >> >>The current directory is the directory you used when you start Java. When you use BlueJ, the current directory is the directory where you started BlueJ. If you started BlueJ from a DOS window, it is that current directory of that DOS window. If you started BlueJ, say, with a shortcut from the desktop, then it is the desktop. >> >>This means that the above code fragments will probably not find the files when you run them in BlueJ. On the other hand, if you run Java from the DOS window, as below, it may work: >> >C:\>> cd myProject >C:\myProject\>> java MyClass > >>So is BlueJ wrong? No, because you should never assume that you know what the current directory is when your code runs. Consider the following way to start your Java class through the DOS window, which is an equally valid way to start your application: >> >C:\>> java myProject\MyClass > >>This command will also start your class, but your code trying to load the file will fail, because now the current directory is different. >> >>In other words: Writing code that relies on the current directory is usually a bad idea, and it is prone to break at any moment. >> >>That leaves the question: what should I do instead? The answer is: Use the "getResource" method from java.lang.ClassLoader. This method will find a file anywhere in the current classpath. And the BlueJ project directory is always in the classpath, so it will always find a file there, no matter what the current directory is. >> >>Here is a code example using this method to load an image: >> >>public Image getImage(String fileName) { >> URL imageURL = getClass().getClassLoader().getResource(fileName); >> if(imageURL == null) >> return null; >> return new ImageIcon(imageURL).getImage(); >>} >> >>Here is a code example reading a text file using getResource: >> >>public InputStream openFile(String fileName) >> throws IOException >>{ >> URL url = getClass().getClassLoader().getResource(fileName); >> if(url == null) >> throw new IOException("File not found: " + fileName); >> return url.openStream(); >>} >> >>The "getClass()" method is defined in class Object, so it is available in every object. Class URL is in the package java.net. Using this code, your program should work independently of how it was started. >> > > >-------------------------------------------------------------------- > > Gustavo F. Bett > > PGP Fingerprint: C4BD CD59 8F03 47FD 9A5A 1ECD 5DB4 34AB C6B5 C315 > > -- ----------------------------------------------- Matthias Jell E-Mail: m....@gm... Homepage: http://www.geocities.com/texx_1at ----------------------------------------------- -- ----------------------------------------------- Matthias Jell E-Mail: m....@gm... Homepage: http://www.geocities.com/texx_1at ----------------------------------------------- |