Creating Jar from Applet

I made an applet and I want to stick it in a jar but I guess there is no way to execute the jar because the applet does not have a main method. Is there another way to make another class with a main method that just executes the applet?
Also, I want to use proguard to obfuscator my applet. Can I use it without being able to make a jar file out of my applet?

Thanks

You can recode your implementation so that a component/canvas is placed into the applet, and can also be placed in a frame. That is what I’ve been doing, and it works perfectly fine.

Is there another way to make another class with a main method that just executes the applet?

Yes. Create a (j)frame, instantiate the applet, add it to the frame, init it. However, there may be some issues if you rely on the document base etc.

Alternatively you can use webstart to launch some applet.

Can I use it without being able to make a jar file out of my applet?

Eh… ???

Well, you can use proguard or any other obfuscator. The entry points aren’t affected in any way (if the obfuscator works as intended).

Ok, I think I got everything figured out. I am having a problem with this one method used to play my audio files:


public void loadAu(String filepath)
    {
        try
        {
        	InputStream in = getClass().getResourceAsStream(filepath);
        	AudioInputStream stream = AudioSystem.getAudioInputStream(in);
        	AudioFormat format = stream.getFormat();
        	if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED)
        	{
        			format = new AudioFormat(
                    AudioFormat.Encoding.PCM_SIGNED,
                    format.getSampleRate(),
                    format.getSampleSizeInBits()*2,
                    format.getChannels(),
                    format.getFrameSize()*2,
                    format.getFrameRate(),
                    true);
        			stream = AudioSystem.getAudioInputStream(format, stream);
        	}
    
        	DataLine.Info info = new DataLine.Info(
            Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
        	clip = (Clip) AudioSystem.getLine(info);
        	clip.open(stream);
        	clip.addLineListener(this);
        	stream.close();
    
        }
        catch (MalformedURLException e){e.printStackTrace();}
        catch (IOException e){e.printStackTrace();}
        catch (LineUnavailableException e){e.printStackTrace();}
        catch (UnsupportedAudioFileException e){e.printStackTrace();}
    }

It throws an IOException when It is in a jar and when I call it with the parameter “Audio/file.au” Audio being the subdirectory and Audio.au being the audio file. It works when I use it in Bluej or in Eclipse. This is the exact error:


java.io.IOException: mark/reset not supported
	at java.util.zip.InflaterInputStream.reset(Unknown Source)
	at java.io.FilterInputStream.reset(Unknown Source)
	at java.io.FilterInputStream.reset(Unknown Source)
	at com.sun.media.sound.WaveFileReader.getFMT(Unknown Source)
	at com.sun.media.sound.WaveFileReader.getAudioInputStream(Unknown Source)
	at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)

mark/reset are not suported by original InputStreams, therefore you must buffer the Stream throughout some Buffered instance from java IO or NIO. I’d use a BufferedInputStream for the resource.

InputStream in = getClass().getResourceAsStream(filepath);
        	AudioInputStream stream = AudioSystem.getAudioInputStream(new BufferedInputStream(in));
        	AudioFormat format = stream.getFormat();

;D

The simplest way and also a way that will enable you to easily convert any applet to Application is to write a JavaAppletViewer in java:

this thread may interest you:

http://www.java-gaming.org/forums/index.php?topic=17028.0

I do not have source code right now but I will post it or send me an email i will sent this code back to you