I'm trying to use this tool
https://swingexplorer.dev.java.net/
to find some information out about an applet's swing structure. Unfortunately, I didn't develop the applet. I've pulled the jars for the applet from the cache, but there are several hundred .class files in the jars, and I don't know which one has the main method.
Is there a way to pinpoint the applet's entry point? The browser must be able to figure it out to run the applet, so that information has to be somewhere in the jar (or maybe the .idx files that were in the same directory with the jars).
Ideas appreciated.
The lifecycle of an Applet (or JApplet) is more complicated than start and run until the program is finished so there is no single main method. It will be managed by the browser (lifecycle tutorial.)
The applet class is specified by the deployment mechanism (e.g. applet/object/embed tags.) See the deployment tutorial for determining how this type is specified.
The entry class will either be in the applet tag, or JNLP for new plugin JRE 6u10+ applets. You should be able to see which one it is from the jar alone by grepping for referecnes to the Applet or JApplet classes or, say, the init()V method.
I was trying to use the wrong tool for the task.
Related
It is as simple as an application that can update itself.
More specific, maybe a launcher that loads a jar file from the web and replaces it with the current jar.
The approach that I want is:
A launcher which is coded in Java.
That launcher overall uses classloader e.t.c.
I want to keep the data from the previous jar. Maybe the data from the previous jar are written on a .txt file and pass them to the new one? (If possible)
I have no clue about classloader or any direction to follow.
So my question is "How can i use classloader to create an auto-update Java application?".
P.S. I want java web start to be the last choice. Some lines of code would help me very much.
Edit: I understand completely what are you saying in theory. What i am looking for is specific links or code which i can take as reference.
The question isn't a duplicate because i can't find links or code but theory.
You can use the URLClassLoader to load a jar file from an URL. Mind, URLs may also be local files, and I'd recommend that you download the jar file locally before loading it in, instead of loading it directly from the web. The reason for this is that you want the application to remain usable, even if the user cannot reach your server.
However, I'd also recommend against taking this approach. What if you want to update the launcher? It's better to download a seperate updater application from the main application, launch the seperate updater application, have that kill the main application and update it.
I've exported my java program to a runnable jar file, and it works great except for a few methods. When I use apple's methods such as..
System.setProperty("apple.laf.useScreenMenuBar", "true");
..and..
Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor");
..they work in eclipse, but don't run in the runnable jar. How do I fix this?
It's difficult to know why from the snippets, but, according to Java Runtime System Properties you could pass them as part of the Java command,
java -Dapple.laf.useScreenMenuBar="true" com.example.yourApp
Or set them as part of the System.setProperty, but you should do so before any part of the AWT/Swing libraries have had a chance to be initialised.
When setting a property within your application (using
System.setProperty), make sure that it is one of the first statements
made inside of your main method. Doing so sets the property before AWT
is loaded, ensuring that it takes effect.
Or you could package your app as an app bundle, then you could supply the setting as part of the Info.plist as demonstrated here
I currently have a in-development Java Game.
It runs from a .jar, with all the image files inside. The .jar creates and accesses files in the working directory.
I was wondering if there was a simple way to put this on a webpage as a Java Applet. I currently have Applet code in the Game, but all it does is calls the normal main method to create JFrames and run the game.
I need a simple way to run this on clients from a webpage, prefferably an applet? Is there one?
Please note, I didn't actually make this as an Applet at first. It's currently a .jar, with a .bat to run it. My "Applet" class is this simple...
package explorer.applet;
import java.applet.Applet;
import explorer.boot.Startup;
#SuppressWarnings("serial")
public class ExplorerApplet extends Applet{
public void init()
{
Startup.wp = true;
Startup.main(null);
}
}
I was wondering if there was a simple way to put this on a webpage..
Sure. Launch a JFrame direct from a link using Java Web Start.
..as a Java Applet.
Why? Applets are harder to deploy and maintain, and provide a less satisfactory experience to the end user.
Note that the fundamental problem is the same either way. 'How to access an application resource?'
Such resource access would be by URL. There are these 2 primary alternatives:
Add the resource to the Jar and use Class.getResource("/path/to/the.resource")
Put the resource 'loose' on the home server, and form the URL relative to the code base or document base of the applet, or the code base of the JNLP (the file used to configure a JWS launch).
The .jar creates and accesses files in the working directory.
About 4MB, and they store the game information. (It's a 2D world game.)
They also have to be client side, and in the folder that the "jar" runs from.
That is too large for any of the sand-boxed techniques I had in mind, but since it is 'static'1 resources - they can be added to a Jar which is on the run-time class-path and thereby will be 'downloaded and made available to the app.'.
Access the resources as described above.
By 'static' I simply mean 'do not need to be edited or changed by the user or app.', as opposed to something like 'high scores' which must logically be written by the app. on game exit. It is still possible to update the maps, all you need to do is provide the updated Jar and Java will do the rest.
I have a client who has a java based game which he wants to make available online (at the moment it is desktop version which he had to install). He asked me whether I can embed it into a webpage. After trying for several days still no joy. Can you please point me to the right direction. It have fives jar files(executable jar file) and a folder called lib which has five more jar files. Now I don't know whether it is possible to embed the game using applet/object tag. Can you please point me what to look at when dealing with these jar files.
..at the moment it is desktop version which he had to install..
Launch it from a link using Java Web Start. It might be necessary to digitally sign the Jars (what does the app. do?).
Note that a 'desktop application' would typically be coded using a JFrame, whereas the equivalent top-level container for embedding is a JApplet. A frame cannot simply be embedded in a web page.
As the rest of the problems mentioned, you'll need to be a lot more specific about what you tried and the results of those attempts, or find some psychic helpers.
I have been using IntelliJ for a while now and I'm enjoying its suite of features but I'm having a hard time getting the run configurations to work for a java applet. I have a pre-existing Java tool that uses Swing and I'm using the JApplet class to load those GUI objects as an applet. The problem is I have a couple configuration files that I need loaded. I load these from the working directory and from my knowledge, this working directory would normally be the directory in which the applet resides. I think the major problem is IDEA sets the startup variable:
-Didea.launcher.bin.path=IDEA_BIN_DIR
I would like to be able to change this but I am seemingly unable to. I have tried overriding this flag by editing the applets run configuration VM parameters, but IDEA will continue putting the above one in even if I specify something different.
So in short, I'm having a hard time loading a local configuration file because I can't set the working directory for the run configuration in IDEA. Does anyone know how to get around this or know of a better way of running Java applets that use configuration files, in IDEA?
An applet normally runs in a sandbox in a browser, and such an applet can't access the local computer's file system, for security reasons.
Thus it is generally a bad idea to load configuration files from the file system, and "working directory" is not a useful term for an applet.
If these files change seldom (i.e. in principle only by the developer), you can put them to the applet's class files (i.e. in the jar file, or during development in the directory where the classes will be generated), and use class.getResource() or .getResourceAsStream() to load them.
If the configuration files should be definable by the webmaster, put them on the webserver - either at some fixed location relative to getCodeBase() or .getDocumentBase(), or specify them as parameters to your applet tag in the HTML tag.
If these are user specific configuration files (which the applet should be able to write), you either need to store them on the server and retrieve/store after a login (i.e. you need some logic at the server side), or you would store them at the client side.
The current way to do this would be using the JNLP API (in javax.jnlp.*) - there are some interfaces allowing Persistence, or loading/storing data (with the user having a FileChooser). Alternatively, you could sign your applet and request an AllPermission from the user - then you can access the file system.
Sorry, nothing of these answers your original question (I don't use IDEA), but maybe these help you to find another way.