JApplet NoClassDefFoundError

隐身守侯 提交于 2019-12-02 18:45:03

问题


I'm writing an Japplet on Eclipse, and from a moment to another, it stopped to work on the html page.

Here are the errors:

  Exception in thread "thread applet-main.MapGenerator.class-1" java.lang.NoClassDefFoundError: com/google/gson/Gson
at main.Floor.parse(Floor.java:39)
at main.MapGenerator.loadParameters(MapGenerator.java:64)
at main.MapGenerator.start(MapGenerator.java:28)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1698)
at java.lang.Thread.run(Thread.java:662)

  Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 5 more

And here it is also the server request:

  "GET /static/java/MapGenerator.jar HTTP/1.1" 200 68177
  "GET /static/java/com/google/gson/Gson.class HTTP/1.1" 404 1697

The point is that it tries to find the Gson library inside the server instead of its package... I don't know how to solve the problem.

If you need something, ask freely.

EDIT

I have imported the Gson's library inside my project in eclipse. Actually I don't know why the applet tries to load it from the server... On Eclipse it runs withouth any problem.

EDIT

I have copied physically the libraries inside the eclipse project... and it still try to get them from the server... I don't know what else do...


回答1:


1st thing you did not add gson library in your classpath and second your request(GET /static/java/com/google/gson/Gson.class HTTP/1.1) is wrong.

If you have gson jar under /static/java like MapGenerator.jar, you could make request for gson jar same as you did for MapGenerator.jar. But you can not make request to get class from that jar.




回答2:


Apparently nobody told me that I cannot insert a Jar inside another Jar, and hope that all works well.

So I put my JAR libraries in the same folder of the applet, and I load the applet this way:

    <applet name="mapGenerator"
            id="mapGenerator"  
            code="main.MapGenerator.class"
            archive="{{STATIC_URL}}java/MapGenerator.jar, 
                            {{STATIC_URL}}java/gson-2.2.2.jar,
                            {{STATIC_URL}}java/plugin.jar"
                     >
                    <param name=id value="{{building.id}}">
                    <param name=piani value='{{floors}}'>  
            MAYSCRIPT
    </applet>


来源:https://stackoverflow.com/questions/13524293/japplet-noclassdeffounderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!