1

I'm trying to open an http socket in an annotation processor on Windows, and am getting the following stacktrace:

java.net.SocketException: Unrecognized Windows Sockets error: 10106: create
    at java.net.Socket.createImpl(Socket.java:397)
    at java.net.Socket.connect(Socket.java:527)
    at java.net.Socket.connect(Socket.java:478)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
...

I have looked into the error a little and it seems it may be because the annotation processor (run though javac) has no access to environment variables such as SystemRoot. I tested this by calling System.getenv("SystemRoot") from my annotation processor and it returned null. In normal code it returned C:\Windows as expected.

Is there any way to pass environment variables into javac? Or even set them programmatically although I suspect that's evil.

1 Answers1

0

The Java toolset is now contained in the runtime of Java. If you want to set Java variables using -D, all you have to do is call the tools from your own application. You can then pass -Dmy.variable="hello world" to java instead of javac.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • Behind my PC at work now, will insert link once my Google connection is up at home. Looking for answer, resurecting the dead... – Maarten Bodewes Apr 02 '14 at 09:01