spawn still not working

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

spawn still not working

James Rome
I posted this without getting an answer, so I am trying again with more
information.

In Windows 7 (64-bits) and NetBeans 6.9RC1 using MinGW tools, I am
spawning a Java application (in a jar file) to listen on a socket for
things coming from C. The section of code is:

#define JAVA_LOCATION "C:/Program Files (x86)/Java/jre6/bin/java"
#define TP_LOCATION "C:/Users/jar/Tekdraw2/tekPlot/dist/tekPlot.jar"
...
        port = getFirstFreePort();   // Find a free port
        if (port == 0) { // Failure
            fprintf(stderr, "Failed to find an open port in C");
            exit(-1);
        }
        sprintf(portstr, "%d", port);

/* spawn Java to launch tekPlot.jar with portstr as its argument */
        // start Java
        if (spawnlp(_P_NOWAIT, "java",
                JAVA_LOCATION,
                "-jar", TP_LOCATION,
                portstr, NULL) < 0) {
            perror("spawn failed");
            exit(EXIT_FAILURE);
        }
/* Continue here to connect to the socket in the Java program */
        // Initialize Winsock.
        WSADATA wsaData;
        int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);

        if (iResult != NO_ERROR)
            printf("Client: Error at WSAStartup().\n");
        else
            printf("Client: WSAStartup() is OK.\n");
....

This works perfectly using Cygwin. But using MinGW, Java cannot find its
main program:
Client: WSAStartup() is OK.
Client: WSAStartup() is OK.
Client: socket() is OK.
Exception in thread "main" java.lang.NoClassDefFoundError: Files
Caused by: java.lang.ClassNotFoundException: Files
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Files.  Program will exit.

The jar file is correct, and runs perfectly from the command line (or when launched by Cygwin). Java is launched, but it seems that the arguments are getting munged somewhere.

What is MinGW doing differently than Cygwin? Is this a bug in MinGW? How do I get this to work?

Thanks,
Jim



------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: spawn still not working

Greg Chicares
On 2010-06-02 14:51Z, James Rome wrote:
> I posted this without getting an answer

Tor replied:
  http://article.gmane.org/gmane.comp.gnu.mingw.user/33108

------------------------------------------------------------------------------

_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users