0

I've a maven Web-app in Eclipse and a page in JSP. I'm trying to launch an applet JAVA in this page, so I wrote :

<APPLET code="a/b/c/AppletStream.class" width="500" height="200"></APPLET>

wich is supposed to call the class :

package a.b.c;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

public class AppletStream extends Applet {

    private static final long serialVersionUID = 1L;
    Font font;

    public void init() {
        font = new Font("TimesRoman",Font.PLAIN,20);
    }

    public void paint(Graphics g) {
        g.setFont(font);
        g.setColor(Color.red);
        g.drawString("Hello !",0,font.getSize());
    }

}

But I've no idea where I have to put the 'AppletStream.java' file in the Maven file system...

Do you have an idea ?

Apaachee
  • 900
  • 2
  • 10
  • 32
  • 1) Why code an applet? If it is due due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). – Andrew Thompson May 27 '13 at 13:50
  • 1) Nice question and maybe you'll have a better solution. I'd like to print in a web page a stream of text. I got a servlet wich produce string in continue and i'd like to print them. 2) I copy/paste an applet example i found on the web. Thanks for url – Apaachee May 27 '13 at 14:32

1 Answers1

0

The class file must be available at the URL declared in your Applet tag, here a/b/c/AppletStream.class. The way to deploy it depends entirely on your website.

Remember the applet is client-side (interpreted by the browser), so the applet in itself, and the website site deploying it, are 2 totally different things.

If your website is a java application, in the same maven project as the applet, you need to customize your pom.xml to package the AppletStream.class into <WAR_ROOT>/a/b/c, to make it available at the desired URL.

If it is a different maven project, you can simply copy the .class file into src/main/webapp/a/b/c.

If your website consists of html/php pages on an apache server, you need to copy your applet class file into <apache_website_folder>/a/b/c.

It all depends on the website, and how it deploys its resources.

kgautron
  • 7,915
  • 9
  • 39
  • 60
  • Hi Kaykay ! Yes, the website is a JSP application, in the same maven project as the applet. But 2 questions, Is my applet auto-compiled in a class file ? And where is stored this class file ? – Apaachee May 27 '13 at 13:20
  • If your applet source file is in src/main/java/somepackage then maven compiles it into target//WEB-INF/classes/somepackage. You need to configure maven to copy the class file into /a/b/c instead. I don't know how to do that. Probalby with maven-compiler-plugin, or maven-war-plugin. Another solution is to manually copy the class file into src/main/webapp/a/b/c, but this means your build won't be fully automated... – kgautron May 27 '13 at 13:41