How I can clear JRE cache dynamicly in java applet - applet

Here is code:
<applet code="ATest.class" archive="ATest.class?v=200406181300">
</applet>
I want to clear existing cache and load the new one when it loads 1st time.How can i do in java applet?
I tested it in Firefox 0.9 and it loaded and ran the class. The idea here
is that when you change the class, you change the [v]ersion in the ARCHIVE
attribute. That should force the browser to get a new copy of the class
file, since the "archive" is now at a different URI, and since the
"archive" is the .class file, it might work (unless the user agent
disregards ARCHIVEs that are classes, which is entirely possible)

I don't think the applet can so this.
But I don't think it needs to either. If the changing the v parameter to a different value isn't sufficient to get the browser to request a new copy of the class, then put it into a JAR file and arrange that the JAR file's name changes each time you want to deploy a fresh version.
I should note that forcing the browser to download a fresh copy of a class if it hasn't changed is a bad idea. It won't achieve anything useful. On the contrary, it will waste server and network resources, and it will make the page load slower.

First, read your question: Why would one update an Applet, "when it loads 1st time"? If you mean the second time, when the plugin tries to load it from its own cache, than just use a new codebase, maybe a new one for every visit/or.

Related

I am having a class not found exception for an applet I'm trying to put in a web page. Think it might be directory related

I have the java stuff in its own folder and have the main class some folders down from the main html.
The folder right below the html code is called "java", the folder inside of "java" that next needs to be used is called "churcheventcalendar". There is one in "churcheventcalendar" called "churchevents". There is one in "churchevents" called "main". Inside of "main", there is a class file called "EventsApplet".
Also, my jar file is inside of "churcheventscalendar". I have heard that the applet tag is deprecated in html 5 so I tried looking up what to do online. It recommended that I use an embed tag. I tried what they had, altering it to make it fit.
I did hear somewhere else, while trying to find the problem that perhaps I shouldn't have the .class in the "code" attribute, but removing it didn't solve the problem, so I put it back.
There are some other issues that might be causing it. I originally had the java file in another folder, but I compiled it in the new folder where I copied it to, so that shouldn't be it. I even remade the jar file there. Still nothing.
I still think it's a directory issue or something that, as a novice, I don't see.
Here's what I have for the embed code:
[code]
<embed id="testapplet" style="border: 1px solid black;"
type="application/x-java-applet;version=1.6"
width="256" height="256"
archive="./java/churcheventscalendar/churcheventcalendar.jar"
code="./java/churcheventcalendar/churchevents/main/EventsApplet.class" />
[/code]
It is showing an error message type thing in red where the applet should be. When I click it, it shows a dialog that says:
"ClassNotFoundException" and it says
"..java.churcheventcalendar.churchevents.main.EventsApplet.class"
When I click "Details", it says:
[code]
Java Plug-in 11.25.2.18
Using JRE version 1.8.0_25-b18 Java HotSpot(TM) Client VM
User home directory = C:\Users\Patriot Mongoose
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
[/code]
I should add that the html files are in "C:/Users/Patriot Mongoose/Documents/sprbc" directory as the main root directory where all the web stuff is. The java folder and subsequent lower folders are in that directory. Also, when I created the jar file in JGrasp, as the thing was an applet, there was no main class, so to speak, to select from when creating it. Normally there is, but that's because I've pretty much always made offline Java GUIs before and hence there was a class with a main method.
The html file where the applet is being called at is in the "sprbc" folder and is called "home.html".
So now you know where the files are at and might be able to see if it's a directory error.
Do you see what I could be doing wrong? Is it what I'm putting under the code attriubte or is it what I'm putting under the archive attribute or is it both and a directory error? Could it even be because I have AdBlockPlus running? Could it be my value under the version attribute? (That one said 1.6, like where I copied the example from, but the thing under details said it was JRE 1.8.something. I did change that to 1.8 to see if anything happened, but it's still busted. On the other hand, I thought I'd still ask.)
Thanks in advance for the help.
Ok, got help on Java Programming Forums. However, now security is blocking my applet. It's only a local applet. I have turned off AdBlock Plus (didn't help, so I turned that back on.)
I have gone to the Java Control Panel and it is already set to "High" like it should be. I have added the local files to the blocking exceptions. Still not working.
How do you get it to accept an uncertified applet?

How does GWT ClientBundle caching work?

I am trying to better understand the use of GWT ClientBundle and caching.
If I have a large text file, for example, that I'd like to make available to my client, I can use
public interface MyResources extends ClientBundle {
public static final MyResources INSTANCE = GWT.create(MyResources.class);
#Source("myText.txt")
public TextResource myText();
}
//-- then later to use the text
String text = MyResources.INSTANCE.myText().getText();
Does this mean that the file "myText.txt" would be downloaded from the server the first time the client runs the app, and then the file would be stored in the browser's cache so that in future uses of the app, the file does not need to be downloaded?
If so, what happens if I change "myText.txt", does the app know to get the new version?
Finally, if the file is indeed stored in the cache, how then is this different from local storage in HTML5?
Thanks.
As Daniel Kurka already mentioned, the resources can be inlined in the js file (a *.cache.* file) where the rest of the compiled GWT code lives.
Inlining does not occur for all resources in a client bundle. E.g. large images are never inlined, it can also be prevented with #ImageOptions.preventInlining(), and it doesn't occur for ExternalTextResources.
What's common for both cases is, that the results will be in *.cache.* files, with unique names that change automatically whenever the contents of a source file change (you'll have to recompile the GWT app though!)
This allows the server to deliver these files with appropriate caching HTTP headers (you'll have to set this up yourself!) For the client this means, that it will not only be able to cache the contents (which it does anyway, even if those headers aren't set), but it can even skip asking the server, if a newer version exists.
The big advantage of ClientBundles is, that the file names will change automatically. The biggest disadvantage is, that you must recompile your GWT app, when a resource changes. If you don't want that, then it's better to use some other approach to load the files: You can still make the browser cache any file you like (by setting the HTTP headers), but then you'll have to be careful to manually give them a new name, when the content changes.
You should use an External Text Resource if you want it to be loaded on demand and not as a part of compiled JavaScript.
https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle#TextResource
If your users need the entire file, use one text resource. If users need parts of it, split this file into separate smaller files: only the requested file will be loaded when needed.
The external text resources can be cached like all other static files.
Files that are inside a clientbundle get inlined into your compiled javascript. They will not be downloaded separately. If you want to download a resource at a given time you can easily use request builder for that.
If you don`t want to download the file immediately but you still want to inline it, you can use code splitting and put the bundle into another part of your app.

Single image with GWT 2.4 requires an ImageResource?

I was just adding a single image to a GWT 2.4 application I was working on. I just put it under the images folder in the war and I had it working properly until I would compile it. Then it would get deleted from the folder. If I remember correctly, from working with older versions of GWT, you could just put an image in this folder to use it.
It just took a few minutes to convert the code to use an ImageResource, but do you have to use an ImageResource for just one image or is there another way to do this?
The class ImageBundle is deprecated, try to use ClientBundle instead.
Instead of putting the file in the war folder, which is typically generated, try putting it in a folder called public/ in the same directory as your client package. The compiler will move it then into your module directory.
And finally, ClientBundle (and ImageBundle, but don't use it) will automatically try to sprite your images where possible, and in some cases include the image in your main html download so that the user only needs to download and cache one large file instead of several files - even for individual images it can be worth it for repeat users of the page, to ensure that no caching issues ever occur.

GWT Caching Concept

Can someone explain to me in simple term the concept of caching in GWT. I have read this in many places but may be due to my limited knowledge, i'm not being able to understand it.
Such as nocache.js, cache.js
or other things such as making the client cache files forever or how to make files cached by the client and then if file get changed on the server only then the client download these files again
Generally, there are 3 type of files -
Cache Forever
Cache for some time
Never Cache
Some files can never be cached, and will always fall in the "never cache" bucket. But the biggest performance wins comes from systematically converting files in the second bucket to files that can be cached forever. GWT makes it easy to do this in various ways.
The <md5>.cache.js files are safe to cache forever. If they ever change, GWT will rename the file, and so the browser will be forced to download it again.
The .nocache.js file should never be cached. This file is modified even if you change a single line of code and recompile. The nocache.js contains the links of the <md5>.cache.js, and therefore it is important that the browser always has the latest version of this file.
The third bucket contains images, css and any other static resources that are part of your application. CSS files are always changing, so you cannot tell the browser 'cache forever'. But if you use ClientBundle / CssResource, GWT will manage the file for you. Every time you change the CSS, GWT will rename the file, and therefore the browser will be forced to download it again. This lets you set strong cache headers to get the best performance.
In summary -
For anything that matches .cache., set a far-in-the-future expires header, effectively telling the browser to cache it forever.
For anything that matches .nocache., set cache headers that force the browser to re-validate the resource with the server.
For everything else, you should set a short expires header depending on how often you change resources.
Try to use ClientBundle / CssResource; this automatically renames your resources to *.cache bucket
This blog post has a good overview of the GWT bootstrapping process (and many other parts of the GWT system, incidentally), which has a lot to do with what gets cached and why.
Basically, the generated nocache.js file is a relatively small bit of JS whose sole purpose is to decide which generated permutation should be downloded.
Each individual permutation consists of the implementation of your app specific to the browser, language, etc., of the user. This is a lot more code than the simple bootstrapping code, and thus needs to be cached for your app to respond quickly. These are the cache.html files that get generated by the GWT compiler.
When you recompile and deploy your app, your users will download the nocache.js file as normal, but this will tell their browsers to download a new cache.html file with the app's new features. This will now be cached as well for the next time they load your app.

Non class files with Java Web Start

How do you distribute other files needed by your application that aren't in a jar file? For example, the application at http://www.javabeginner.com/java-swing/java-swing-shuffle-game . The download contains Shuffle.jar, Shuffle.bat, Score.dat, and an images folder with 3 images in it. I can see possibly putting the images directly in Shuffle.jar, but you wouldn't want to put Score.dat in the jar file because it changes. Is there somewhere you could identify this type of file in the jnlp?
The non-java files should be stored as resources. For files that change, you store the original or template file also as a resource in your jar. When the program starts, you have it check the local system to see if that file exists. If not, it creates the local file by copying the template file from the JAR resource. If the file already exists, then it is used as is.
To save files to the local system, even when running in the sandbox (unsigned), you can use the PersistenceService (javadoc / example). If your java application is signed, then you can use the regular File apis to write the file to the local machine, such as in a ".yourgame" subfolder under the user's home folder.
You can put all those files (except the scores file) in your jar file and load the contents using resource loading.
I've just deleted and restarted my reply twice now, changing my answer each time; this is confusing and needs a bit more clarification.
Are you SURE that application is supposed to be a Web Start app? On the site you linked to, it doesn't appear to be. Are you trying to take an application that was not designed as a Web Start application and change it into one that can be Web Start?
If it's not a Web Start app as your tag implies, then this question is open ended. You can distribute it 100 different ways.
If you are indeed trying to convert it into a Web Start app, you can start by packaging the images into the jar and that will alleviate your first headache if you just read them from there instead of from a File(). If it's going to be Web Start, then you need to decide how you want to keep scores. You have to decide what the scoring system is like before you can decide on how to go about it; will all the scores be kept on the web site hosting the Web Start app? Will that part still be local? If you want to get access to the local file system, you need to sign the jar, then you can extract the score.dat to the file system and do whatever you want with it if the end user accepts.
You need to figure out what you want to do before you can do it, or at least clear it up for us if you already know more than we know you know.