Czyzby
Czyzby

Reputation: 3139

Creating libGDX applet

I know there's a guide on how to create a libGDX applet, but I feel it's highly outdated and somewhat confusing. Here's what I've already done:

  1. Created applet class in my desktop project:

    public class DesktopApplet extends LwjglApplet {
    private final static LwjglApplicationConfiguration DEFAULT_CONFIG =
        new LwjglApplicationConfiguration() {
        {
            width = 512;
            height = 512;
        }
    };
    
    public DesktopApplet() {
        super(new Core(),DEFAULT_CONFIG);
    }
    
    private static final long serialVersionUID = -1916205038641068252L;
    }
    
  2. Exported desktop project as a regular jar. Added the project's jar (along with gdx and all lwjgl jars in "applet/basic" folder).

  3. Created a html file, based on basic lwjgl applet and the tutorial:

    <applet code="org.lwjgl.util.applet.AppletLoader" archive="lwjgl_util_applet.jar" codebase="." width="512" height="512">
    
    <!-- Name of Applet, will be used as name of directory it is saved in, and will uniquely identify it in cache -->
    <param name="al_title" value="mygametitle">
    
    <!-- Main Applet Class -->
    <param name="al_main" value="my.packages.desktop.DesktopApplet">
    
    <!-- List of Jars to add to classpath -->
    <param name="al_jars" value="mygamejar.jar, gdx.jar, gdx-backend-lwjgl.jar, lwjgl_applet.jar, lwjgl.jar, jinput.jar, lwjgl_util.jar">
    
    <!-- signed windows natives jar in a jar --> 
    <param name="al_windows" value="gdx-natives.jar, gdx-backend-lwjgl-natives.jar, windows_natives.jar">
    
    <!-- signed linux natives jar in a jar --> 
    <param name="al_linux" value="gdx-natives.jar, gdx-backend-lwjgl-natives.jar, linux_natives.jar">
    
    <!-- signed mac osx natives jar in a jar --> 
    <param name="al_mac" value="gdx-natives.jar, gdx-backend-lwjgl-natives.jar, macosx_natives.jar">
    
    <!-- signed solaris natives jar in a jar --> 
    <param name="al_solaris" value="gdx-natives.jar, gdx-backend-lwjgl-natives.jar, solaris_natives.jar">
    
  4. Created a keystore file. Deleted default lwjgl signing (META-INF folders), added timestamps to the signing command, created a bash script for jar signing and - finally - signed all jars. While signing produces no errors, jarsigner -verify returns one warning "This jar contains entries whose certificate chain is not validated." and I'm not sure how to get rid of it. Here's my signing command: jarsigner -keystore .keystore -digestalg SHA1 -tsa http://timestamp.comodoca.com/rfc3161 -storepass mypass $jar gdxkey.

  5. Changed Java security level to medium. It allowed me to - finally - run the applet without security errors (thanks kabb!).

  6. The applet... doesn't work. It stays that an error occurred when "Switching applet". I'm not sure if I exported the right projects - should I include a jar with desktop project or just the core and manually add all assets and libraries?

Upvotes: 1

Views: 510

Answers (1)

kabb
kabb

Reputation: 2502

The issue is that the applet is self signed. As of JDK7u51, self signed and unsigned applications are blocked if your java security settings are set to high or above. You can read more about this here.

To be able to test your applet, you can simply go to the java control panel, go to the security tab, and set the security level to medium.

However, if you wish for other people to be able to run your applet without having to go through the hassle of changing their security settings, you'll have to get a certificate by a Certificate Authority, and sign your applet using that. Unfortunately, this costs money, and there is no workaround to it that I know of.

If you want to run your game in a browser, you could consider using GWT instead. LibGDX has some tutorials on it's wiki on how to setup a project with GWT. However, it could be a hassle, especially if you're using libraries not supported by GWT.

Upvotes: 1

Related Questions