reload java applet - java

i have a java applet in one html page, later, i modified the java code and regenerate the jar file. all i did is copy the jar file to my web server and brought up the browser to see the updated the appplet, but it still showed the old version. i tried refresh the browser, delete the cookies, still the same. i tried to open that html file by double clicking the file, it open it in browser with the right applet...i deployed the applet with jnlp. anyone knows what might go wrong? Thanks.

Go to the Java control panel and clear the Java caches*. The Java plugin does not use your browser for downloading Jar files.
*: Temporary internet files - configuration - delete files

Try this to clear the cache quickly without having to go through the tedious process of opening the Control Panel:
Open up the Java Console:
Windows:
http://www.java.com/en/download/help/javaconsole.xml
Use method 2.
Linux:
http://www.java.com/en/download/help/enable_console_linux.xml
And I can't insert a third hyperlink for Macintosh because I don't have enough reputation points yet......
Press 'x' to clear the cache!
I hope this works!

Jonathan's answer should do the trick, but in future I recommend you to load the applet from a new URL each time you update. For example http://www.domain.com/applet.jar?version=x

Related

How do I export a PApplet to make it runnable in a browser?

I have an Eclipse Java project, in which I have an src/demo package that contains a Processing demo, inside a single class that extends PApplet. The demo runs fine in Eclipse.
I wish to demo this package, preferably in a web browser. Being able to demo outside the Eclipse project would still be appreciated.
I've tried exporting the package to a JAR and embedding it in an HTML file. Firefox seems to be the only modern mainstream browser that supports NPAPI plugins like Java (Chrome 46 just shows a grey box, Safari 9 shows a blank page).
Firefox kept throwing "Class/Library not found" errors, until I manually copied all the libraries to the same directory as a JAR and including them in archive attribute of the applet element in the HTML.
Now Firefox shows a black outline but a blank app, which might because I haven't copied assets from the data folder in Eclipse. I have no idea how to include them with the JAR however.
I tried following this guide and simply adding a main() to the PApplet but that gave me a "Class not found error" when I exported it as a runnable JAR and tried running it.
System information: Mac OS X 10.11.0, Java 1.8.60
What is the systematic way to go about all this?
I think the best way to answer your question is to clear up some of the confusions you have about the issues you're experiencing.
First of all, applets are pretty much dead. They won't work at all in chrome, like you mentioned. Getting them to work in other browsers is a pain in the neck, for you and for your end users. You have to either pay for a certificate or get your users to change their Java security settings.
Furthermore, as of Processing 3, PApplet no longer extends Applet. So you can't simply extend PApplet and treat it as an applet anymore. (You forgot to tell us which version of Processing you're using.)
Honestly, the best approach is to forget about applets.
If you forget about applets, then you could deploy as a standard executable by going to file -> export, or as a runnable jar using something like JarMatey (full disclosure: I wrote JarMatey). It's important to note that it's not enough to simply add a main() function to your class.
But in my honest opinion, your best bet for deploying your Processing sketch is to use Processing.js to deploy as html5/JavaScript. This should be pretty easy, as long as you aren't using any Java libraries.

Overwrite a jar while in use - Java

I have jar client that has an auto updater built in, when you open it if there is a new version it will download it. I made it so it downloads the new version to the same directory that the user is running the current one from so that it's easy for the end user.
The problem with this is that it can't overwrite itself because it's in use obviously. As of right now it downloads a new version and I have the version in the name so it downloads a new one with like v1.1 or v1.2 in the jar name.
This works but just seems to messy in my opinion, does anyone know of a way to make it so I can just always have the same file name? IE does anyone know of a way to overwrite a file that's in use, or a work around that will close the current and replace then reopen the new one?
Here is my downloader class - http://pastebin.com/KJdDndhh
I think the best solution to this problem is to not have 1 Jar file both manage itself as the application and the updater. Have a separate Jar for updating and your current one act as the application alone.
This seems to be similar to how many applications with auto updating works.
League of Legends has a separate updater that runs before the main application launches
Antivirus usually loads their signature files into memory and close their connection to them allowing them to overwrite those files.
When a JRE executes a JAR file, it loads the classes it needs and then releases the JAR file. So you will be able to overwrite the JAR file even from the code within the JAR file.
I have implemented the same update mechanism and it works fine for me on Windows 7, Ubuntu and Mac OS.
But if it's not able to overwrite for you, then from your code you are probably using up some resource which it has to keep the lock on (I am not really sure what, it's just my guess).

Latest changes are not reflected in servlet (tomcat)

I am working on my project of quiet sometime now I am using tomcat and eclipse both working correctly till now..
I deployed the war on 22-1-2012 ( with some print messages) it was working correctly then next day I made some changes removed some messages and redeployed the file...In my webapps folder it is showing the latest time for 'last modified' of my war file.. what wrong i am doing tell me..
P.S any changes to JSP pages of same project are reflected but servlet class is unchanged
This is what log file shows
_SEVERE: A web application appears to have started a TimerThread named [MySQL Statement Cancellation Timer] via the java.util.Timer API but has failed to stop it. To prevent a memory leak, the timer (and hence the associated thread) has been forcibly cancelled. _
Well this is the summary of my problem i hope i can explain you now the problem
i again performed the following steps
Deleted my webapp directory from webapps
Tried to access servlet (it shows 'Resource not available')
Make some changes in print statement to debug
Redeployed WAR from eclipse
Again when access that servlet it is not the latest version it is showing same old messages.
Now tell me if there is solution....
Thanks in advance
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
The JSP files are not updating because they were precompiled, and even though they may pull information from files that have changed, each JSP file that may be affected needs to have a minor change made to it, like add a space and then remove a space, and then save it.
Then build your WAR, and then the updates should show. I went through this same problem tonight and none of the other answers helped. The key is, to check the file dates in the Tomcat directory of where you deployed the WAR. I noticed that even though I was deploying an entirely new cleaned WAR, and deleting all folders, there were still older cached files in there, probably because Eclipse keeps them to save compile time, thinking they don't have any changes.
Hope this helps
Go to Servers View in Eclipse:
Double click on your server. In my case, it’s Tomcat.
A Tomcat Web Module should pop up. Click on Modules tab at the very bottom (see Pic1)
Select your project. Click “Remove” button.
Pic 1:
Now you should see a star next to the Tomcat Tab. That means you need to save your changes. So do a Control+S.
Pic 2:
Right-click on your project in Project Explorer. Go to Maven -> Update Project…
Pic 3:
Now this is the important part, make sure you have “Force Update of Snapshots/Releases” checked. Having that part checked is critical. Then click Ok.
Pic 4:
Now look at your Server View. It should look like this, with a “Restart” warning telling you that it’s out of sync.
Pic 5:
Right-click on it and choose Restart
Pic 6:
Let the server restart. Now if you go back to the Server View, you should see that it’s synchronized. That’s what you want. Like this:
Pic 7:
Now you should be able to right-click on your project and choose “Run As” -> Run on Server and you should see your changes.
Pic 8:
If things still didn’t update, go back and look at your Server View and make sure it doesn’t say the restart thing like in Pic 5 above. If it does, please restart your server again like in Pic 6. Then click refresh on the browser.
Go to browser settings and clear the cache.
Check the log files for Tomcat, I bet there is a startup problem with your web app and it's not getting deployed.
The reality is that Tomcat cannot be running code it doesn't have a copy of. Especially if you have restarted it. It sounds like there is a separate "copy" of your web app that is actually in use. Either made inadvertently by you (hey lets face it, we've all done this) OR made by Tomcat in a location you weren't aware of.
Pick a unique file that exists within your web app. Maybe an icon name, or a configuration file name. Search the entire hard drive for it to locate exploded copies of the WAR file. This will help find it in a temp directory or working folder. Make sure to clean those up.
Also, make sure you are running the Tomcat that you think you are. Most developers with multiple Tomcat installations has also made the mistake of deploying to a different location. Look at the process list to see the arguments given to the JVM at launch time. Be sure to also check environment variable for things like CATALINA_HOME.
EDIT: Your update that JSP pages change, but classes do not make me think you have multiple JAR files on the class path that have the same file in it (one older version loaded first) OR you have changed a class name in the code base, but not updated references to it.
any changes to JSP pages of same project are reflected but servlet class is unchanged
It is not clear what you are saying.
If you are saying that the updated JSPs are in the expanded webapp directory, but the generated / compiled JSP classes have not changed (in the work directory), then try deleting the classes from the work directory. You may need to restart the web container too.
If you are saying that the non-JSP servlet classes have been updated (in the webapp) but you are not running them, then try restarting the web container.
If you are saying that the non-JSP servlet classes have not been updated in the webapp directory, then something went wrong in the webapp deployment. Shutdown the web container, delete the webapp directory (and the compiled JSPs for good measure) and restart the webapp.
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
So the problem is nothing to do with deployment. The problem is that you are not building the WAR file correctly in the first place.
I can't help with this because I don't use Eclipse to build my WAR files. (I use Maven so that the build process is scripted and reproducible ... and doesn't depend on me clicking the right buttons in the right order every time.)
is your tomcat server.xml pointing to the right Workspace?
to make sure, you go to tomcat installed directory -- find server.xml in the confi folder
for every war file, tomcat creates a similar named folder. Delete the folder, try to redeploy war again, hope it will reflect.
In web.xml file add one letter at the end and delete it and then by pressing enter save the file. After that run the program and it works with updated data.
go to catalina home\conf\context.xml
change <Context> to <Context reloadable="true">
Make sure you restart tomcat.
Boom.
You might have to still press F5 or Ctrl+F5 two or three times though.
TL;DR: Make sure your eclipse project is set to build automatically: Project > Build Automatically
I apologize for answering without having complete knowledge of what the WAR files are, but I assume the WAR files are the compiled .class files in the "build" folder.
I noticed that when I saved my Servlet "HelloWorld.java" in my case, that the compiled "HelloWorld.class" did not update at all. I could force the project to build by right clicking the java project and selecting "Build Project". After Building the project, the "HelloWorld.class" file was successfully updated, but the updated code still did not show on the server.
To get the results to show on the server, I had to click on my server (mine was called "Tomcat v9.0 Server at localhost [Started, Synchronized]") and then I clicked "Publish to Server". If you do not see your Servers, do: Window > Show View > Servers
I didn't even have to restart the server, after a few seconds (and refreshing google chrome), the website updated itself!
Of course manually building and publishing (and possibly restarting) the server is kind of too much for my lazy fingers, so I found how to fix it. You can just go to Project > Build Automatically. and then the website will update anytime you save a modified java file.
This solution worked for me because I was only missing the automatic building. but you could also have a problem where the server doesn't automatically publish.
I personally didn't have this problem so I'm just speculating, but there are some settings for publishing. In your "Servers" view, double click on your server name (in my case, double click on "Tomcat v9.0 Server at localhost [Started, Synchronized]"). A tab should open up showing your server settings. Expand the section titled "Publishing", and set your publishing settings as you desire. Right now mine is set to "Automatically publish when resources change".
Unfortunately I have no clue how to make the server automatically restart upon the saving of a modified .java file.

Java security policy file question

Okay guys, I am trying to get the interpreter to use my .policy file for some JAAS stuff I am doing. When I try to enter the extra entry (ie. policy.url.3=file:/C:/Test/raypolicy
) in my Windows:java.home\lib\security\java.security
file, it refuses to save the new entry. I get a Save not successuful prompt telling me to make sure that the program is not open in somewhere else. Of course, it is not open somewhere else.
I know that it is a wrong setting somewhere on my computer as I am able to save to my java security file on my computer at work. I am running a Windows 7 on my personal computer and a windows xp at work. I have also already checked the file settings for the security file and I am set up as the administrator so I have authority to change the file, etc. Any and all thoughts are welcome.
Make sure you run the editor you use to edit the file (e.g. notepad) as Administrator -- otherwise the file permissions set on that directory will not allow you to modify the file.
Right click on notepad, select "Run as administrator" then load the file in notepad, edit it and save it and that should work.
One more option that worked for me was,
Copied the original file java.security to my desktop.
Changed the desktop version using notepad++ or any editor
Saved it.
And copied back this updated version to original file replacing the entire file.
Opened the file to confirm the changes
Deleted the desktop version.

Why does Java tell me my applet contains both signed and unsigned code?

My signed Java applet has been running fine until Java update 19. Now some but not all of our users on Java Update 19 report a java security message stating that our applet contains both signed and unsigned code.
The process for creating our applet is as follows:
Clean and Build the applet project in Netbeans IDE.
Open the Applet jar file in WinRAR and add the required mysql JDBC driver .class files to the jar file.
Sign the applet jar file.
Can someone please tell me how to determine what code is signed and what code is not signed in our applet? Is there a better way to include the mysql JDBC driver jar file in our applet other than copying the jar file contents into our applet jar file?
Thanks
EDIT: Due to a bug in Java 7 Update 45 you should not add Trusted-Library to your manifest file. Just add the new attribute Caller-Allowable-Codebase. See this question for more info: Java applet manifest - Allow all Caller-Allowable-Codebase
Java 7 Update 21 was released on April 16 2013 and caused our applet to start showing this warning dialog.
Per the release notes:
As of JDK 7u21, JavaScript code that calls code within a privileged applet is treated as mixed code and warning dialogs are raised if the signed JAR files are not tagged with the Trusted-Library attribute.
To fix this edit your manifest.mf file and add a line like this:
Trusted-Library: true
You should be very careful before doing this though. If your signed applet can be called from javascript then a malicious user can potentially do harmful things on your users' computers.
One quick way to secure your applet is to prevent it from being run on other websites. Do this by putting code in the init() method that looks at getCodeBase().getHost() and throws an exception if it does not match your site.
Java 7 Update 25 introduces another way to limit the sites where your applet can be run. You can set the Codebase attribute in your manifest file like this:
Codebase: test.example.com www.example.com
Java 7 Update 45 (releated October 16 2013) introduces more changes to the LiveConnect system (javascript-to-applet bridge) that may cause another prompt. This article talks about the 7u45 changes: https://blogs.oracle.com/java-platform-group/entry/liveconnect_changes_in_7u45
Basically you'll also want to add the following to your manifest file to avoid the prompts:
Caller-Allowable-Codebase: test.example.com www.example.com
If you are selling a product that includes an applet and you don't know what domains it can be deployed on you can populate * here.
Some things to try:
Go to the java plugin control panel ($JAVA_HOME/bin/ControlPanel).
Go to the Advanced tab.
Expand Debug
Check Enable tracing, Enable logging, and Show applet lifecycle exceptions
Expand Java console
Check Show console
Click OK (or Close, depending on your OS)
When your applet loads the Java console will open. Click on it and immediately press '5'. It will log the jars and classes being fetched to run your applet. Somewhere in this there should be a message indicating what jars or classes are consider "unsigned". If you miss it the first time, just reload the window to try it again.
Mixing trusted and untrusted code together is a vulnerability that has been fixed in the 6u19 (the current CPU/SSR release at the time of writing). See the docs. Blocking the mix or using a debugger should show where the problem is.

Categories