Java 7 Debug on Windows 8 not working

余生颓废 提交于 2019-12-04 07:26:03

I'm having the same problem and can a little light on the issue. I don't have a solution yet, which is why I came here, but this may help find the answer.

The problem is in the actual run-time being launched by the JRE. If you look at the executable in the Java control panel, it will be javaw.exe. So you're adding the debug flags to that. If you use Process Explorer to look at the actual process that's running your applet, it's java.exe. I don't know if javaw.exe is just spawning java.exe then dying or what, but the flags are never getting passed onto java.exe.

If you go to the Java tab in the control panel, you used to be able to add another run-time there. Well, you still can, but after clicking OK then Apply on the next dialog tab, then clicking back into the Java tab, your added run-time will be gone. None of the settings that I've modified have made the browser plugin get the run-time parameters passed on, which makes it impossible to debug the applet in the browser context.

Did it ... almost !

Since I'm stuck I did it the hard way : replaced java exe by one of my own which forced java into debug mode

(please be gentle this is not high quality dev :) )

  • backup your original java.exe and replace it with this fake java.
  • don't forget to update exeFile to point to your java dir
  • don't forget to update stdoutRedirect and stderrRedirect too
  • use compilation options -static-libgcc -static-libstdc++ for mingW

fakeJava.exe

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<time.h>
#include<strings.h>
int main(int givenArgc,char *givenArgv[])
{ 
    std::cout<<"step 0.a\n";
    char exeFile[] = "c:\\java\\jdk1.7.0_21\\bin\\java.exe";
    int prependArgc = 4;
    char* prependArgv[] = {
        "-Djava.compiler=NONE",
        "-Xnoagent",
        "-Xdebug",
        "-Xrunjdwp:transport=dt_socket,address=2502,server=y,suspend=y"
    };


    std::cout<<"step 0.b\n";
    time_t rawtime;
    struct tm * timeinfo;
    char date [80];

    time (&rawtime);
    timeinfo = localtime (&rawtime);

    strftime (date,80,"%Y%m%d%H%M%S",timeinfo);

    std::cout<<"step 0.c\n";
    char stderrRedirect[100];
    char stdoutRedirect[100];
    sprintf(stderrRedirect,"2>d:\\tmp\\%s-stderr.txt",date);
    sprintf(stdoutRedirect,">d:\\tmp\\%s-stdout.txt",date);

    std::cout<<"step 0.d\n";
    int appendArgc = 2;
    char* appendArgv[] = {
        stderrRedirect,
        stdoutRedirect
    };

    std::cout<<"step 0.e\n";
    int argc = prependArgc+givenArgc-1+appendArgc;
    char** argv = (char**)malloc(argc*sizeof(char*)); 

    std::cout<<"step 1.a\n";
    char** src = prependArgv;
    int nbItems = prependArgc;
    int j = 0;
    for(int i=0;i<nbItems;i++){
        argv[j++]=src[i];
    }

    std::cout<<"step 1.b\n";
    src = givenArgv;
    nbItems = givenArgc;
    for(int i=1;i<nbItems;i++){
        argv[j++]=src[i];
    }

    std::cout<<"step 1.c\n";
    src = appendArgv;
    nbItems = appendArgc;
    for(int i=0;i<nbItems;i++){
        argv[j++]=src[i];
    }

    std::cout<<"step 3\n";
    char str[4096];
    strcpy(str,exeFile);
    std::cout<<"step 4\n";
    for(int i =0;i<argc;i++){
        strcat (str," ");
        strcat (str,argv[i]);
    }
    std::cout<<"step 5\n";
    std::cout<<"will run : ";
    std::cout<<str;

    std::cout<<"\nstep 6\n";
    system(str);
    free(argv);
    return 0;
}

I set the environment variable JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8989" as it suggested in the bug and it did the trick for me (at least in the Chrome)

There is a lot of bugs filled in sun bugs database related to that, and it seems it only resolved in java-8 (b97) Here is the link to the sun-bug which describe exactly the same problem and here is the place you can download java-8 (b99 is the current build)

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