0

I have a problem trying to run a applet in browsers. I get a NullPointerException and I can't figure what it is going wrong.

Here is the stack trace:

Java Plug-in 10.60.2.19
Using JRE version 1.7.0_60-b19 Java HotSpot(TM) Client VM
User home directory = C:\Users\Alexandru
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
java.lang.NullPointerException
    at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
    at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source)
    at sun.awt.SunToolkit.getSystemEventQueueImpl(Unknown Source)
    at java.awt.Toolkit.getEventQueue(Unknown Source)
    at java.awt.EventQueue.invokeLater(Unknown Source)
    at sun.awt.windows.WToolkit.windowsSettingChange(Unknown Source)
    at sun.awt.windows.WToolkit.eventLoop(Native Method)
    at sun.awt.windows.WToolkit.run(Unknown Source)

I get this after I get a ClassNotFound for Quiz.class.

Here is my code:

<jsp:plugin type="applet" code="Quiz.class" codebase="../target/classes" width="500" height="280">
    <jsp:fallback> 
    <p> Unable to load applet </p> 
    </jsp:fallback>
</jsp:plugin>

I am trying to run the app on OpenShift cloud service. My server is running using JBoss and it should create a quiz and display it in the applet. I have the quiz already created and I could display it in the browser via jsp, but now I am trying to display it in the applet due to security issues.

Here is my code for the applet (this applet is only for testing, I should manage to display the quiz in it after I solve this problem):

package models;

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

public class Quiz extends Applet{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void paint(Graphics g)
    {
          g.drawString("My applet",400,200);
    }
}

My project is Maven based, I think it is important. I tried to add the compiled class from my applet to a jar and add it to webapp folder at runtime using Maven plugin using this example Maven - Copy Some Dependency JARs into warSourceDirectory but it did not help. I also tried to compile the class directly to webapp folder using this plugin:

<pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>

and this profile:

<profile>
            <id>copy</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.goldin</groupId>
                        <artifactId>copy-maven-plugin</artifactId>
                        <version>0.2.5</version>
                        <executions>
                            <execution>
                                <id>create-archive</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <targetPath>${project.build.outputDirectory}/work/webapp/WEB-INF/classes/</targetPath>
                                            <directory>${project.basedir}/src/main/webapp</directory>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

but it did not work either. Any other suggestions?

Community
  • 1
  • 1

1 Answers1

0

You may need to put the Quiz.class file in your webroot directory (by your jsp file) so that the jsp code can find it, otherwise i don't think that ../target/classes gets exposed to browsers on the web, as that seems like it would be a security issue?

  • Thank you very mych for your idea, but i do not think i can do that. I already tried to place them in the same folder, but in my project i have this structure: under src i have main with 3 other subfolders: java, resources and webapp. I can only place java files in java folder and jsp files in webapp folder. As far as i can see in my git folder, java files are compiled into target/classes folder. i do not know where the problem is...Though, thank you very much for this idea – user3738906 Jun 13 '14 at 22:42