0

Im not very familiour with Java nor Java applets but I have to fix this issue.

Ever since JRE 7 Update 21 the applet is throwing eceptions in all browsers.

enter image description here

I need to debug the app, because the error gives no clues whatsoever (the application was running for years now, its after latest JRE update that the clients cant use it anymore).

So the applet is used as a JAR file in .NET application. It is called as javascript with some code:

<html>
<head>
    <script type="text/javascript">
        var i = 0;
        var path = "\\\\\\\\reaktorm\\\\Outgoing\\\\test";
        var ext = ".tif";
        var fullPath = "";

        function nextImage() {
            if (i==2) {
                alert("There is no next image in collection!");
            } else {
                i++;
                displayImage();
            }
        }

        function previousImage() {
            if (i<1) {
                alert("There is no previous image in collection!");
            } else {
                i--;
                displayImage();
            }
        }

        function displayImage() {
            //fullPath= path + (i<10?"0"+i:i) + ext;
            fullPath= path + ext;
            alert(fullPath);
            document.webViewer.display(fullPath);
        }
    </script>
</head>
<body>
    <div style="width:100%; height:100%;">
        <applet name="webviewer" archive="..\webviewer.jar" code="my.webviewer.WebViewerApplet.class" width="100%" height="100%">
            <param name="java_arguments" value="-Xmx512m">
            <param name="image_source" value="C:\test\test.tif">
        </applet>
    </div>
    <form id="testForm" name="testForm" style="display:block">
        <input type="button" onClick="previousImage();" value="previous" />
        <input type="button" onClick="nextImage();" value="next" />
    </form>
</body>
</html>

So if I put this in html file and open it in a browser, i get the upper RuntimeException.

Now I want to debug in order to find the reason for this exception. I have eclipse, the source code and an JAR export.

I have tried remote debug by launching:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar webviewer.jar

Then i tried to connect to that using "Remote Java Application" under Debug options in eclipse by connection to locahost:5005, but i get connection refused.

Please can some one point me to the solution - how can i debug this in eclipse?

no9
  • 6,424
  • 25
  • 76
  • 115
  • Maybe you got the same problem: http://stackoverflow.com/questions/17786669/java-1-7-0-u25-applet-debugging-with-eclipse/17941467#17941467 – Oli Jul 30 '13 at 08:11

2 Answers2

1

In Eclipse, navigate to your Applet class, and then click Run in Eclipse menu, then Debug As and Java Applet. Eclipse will launch your applet in debug mode.

Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68
  • 1
    That is obvious, but the applet requires some imput, that is done via javascript in my .NET app. The HTML only calls JAR file that is compiled java applet, so im not sure how this would work? Applet alone works ... but i need a working scenario to show the applet in web browsers (this is when the exception takes place). – no9 Apr 25 '13 at 09:11
  • 1
    Try [this answer](http://stackoverflow.com/a/6049278/572834). You have to setup Java plugin for remote debugging, and then you'll be able to connect to it with Eclipse debugger. Alternatively, you can extend your plugin functionality, so that you could call the functions that are called by JavaScript on HTML page. `ExceptionInInitializerError` means that an [exception occurred during evaluation of static initializers](http://stackoverflow.com/a/3375834/572834) for a class. Thus it could be enough just to instantiate your main applet class with `image_source` parameter from HTML. – Alexey Ivanov Apr 25 '13 at 14:09
  • Most probably, you get `SecurityException` because your applet is not allowed to access `C:\test\test.tif`. Applets may not be allowed accessing user's computer file system. And this `SecurityException` is the reason why you get `ExceptionInInitializerError`. – Alexey Ivanov Apr 25 '13 at 14:13
  • Alexey, what troubles me is the fact that his applet works in all previous versions, except v7 update 21... – no9 May 21 '13 at 06:34
  • @no9 Updates sometimes break application… because application may depend on the bugs present in the runtime. If the bug is fixed, the application fails. First of all, you have to find the reason why it fails now, to find what exception is thrown – that would be the key to resolve the failure. – Alexey Ivanov May 21 '13 at 07:37
0

The java console will give you a full stack trace on any exceptions your applet is throwing. You can enable it by following the instructions on the linked Oracle doc.

drew moore
  • 31,565
  • 17
  • 75
  • 112