spawnle not working

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

spawnle not working

James Rome
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:
...
        port = getFirstFreePort();
        if (port == 0) { // Failure
            fprintf(stderr, "Failed to find an open port in C");
            exit(-1);
        }
        sprintf(portstr, "%d", port);
        // start Java
        if (spawnlp(_P_NOWAIT, "java",
                JAVA_LOCATION,
                "-jar", TP_LOCATION,
                portstr, NULL) < 0) {
            perror("spawnle failed");
            exit(EXIT_FAILURE);
        }

        // 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.

What is MinGW doing differently than Cygwin?

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: spawnle not working

Tor Lillqvist
> Exception in thread "main" java.lang.NoClassDefFoundError: Files

I suggest you begin debugging this by temporarily running instead of
java.exe some minimal test program that just prints out its argv. Then
you can see what command-line parameters it actually gets, and if
there is anything strange in them. Is for instance spaces in pathnames
involved? You might need some quoting then. And remember, the quoting
is not as on Unix systems like Cygwin.

> What is MinGW doing differently than Cygwin?

Everything.

They really have not much at all in common as run-time environmnts.
MinGW is a toolchain (compiler, linker etc) that produces Win32
binaries. MinGW is not really involved much when MinGW-built programs
are running. Cygwin on the other hand is a complete Unix environment
that Cygwin programs run in, as if running on a Unix OS. Cygwin code
obviously uses a different C library than MinGW.-built code, which
uses the Microsoft C library.

The only thing in common between MinGW and Cygwin is that they both
use gcc as their compiler. But then, the same is true for, let's say,
MinGW and MacOSX.

--tml

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

_______________________________________________
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