Running project out of Selena and networking
I have a strange issue here:
When I run the main class of my project out of IDEA 6.0.5, everything works fine.
When I run the same project with the same configuration out of 7118, a call to
InetAddress.getLocalHost();
always leads to an java.net.UnknownHostException
In another class, a call to
new ServerSocket(65535);
works fine when launched out of 6.0.5, but when launching the class containg the statement out of 7118, I get:
java.net.SocketException: Unrecognized Windows Sockets error: 10106: create
请先登录再写评论。
Are you sure you are running the project with the exactly same JDKs?
Yes, I am - in both cases it's 1.6.0_01.
Can anyone reproduce this behaviour, or am I the only one having this problem?
Hello Tobias,
I do not know much about java.net, but at least the following dummy main
class:
public class LocalHoster {
public static void main(String[] argv) throws IOException {
InetAddress inetAddress = InetAddress.getLocalHost();
System.out.println(inetAddress.getCanonicalHostName());
System.out.println(inetAddress.getHostName());
ServerSocket serverSocket = new ServerSocket(65535);
System.out.println(serverSocket.getInetAddress().getCanonicalHostName());
}
}
runs Ok on my machine. Used project JDK 1.6.0 and alternate JRE 1.6.0_01.
Build 7118.
Maybe, your code have some specific to cause the exception?
Alexander.
Now it gets really weird:
Running this simple test class works, running my application using similar code does not.
After playing around a little bit and searching for the difference, I found out the following:
The code above also breaks as soon as you enter anything in the line "Environment variables:" in the "Run configuration" page.
Simply typing "a" there leads to an java.net.UnknownHostException :o
In my "real" run configuration of my main class, I set an environment variable called "NB_HOME" pointing to a certain directory.
This also explains why the problem didn't occur in IDEA6: there is no "Environment variables" field in 6.0.5
Looks like a bug to me...
Hello Tobias,
Do you work on WinXP? When you specify environment variables, try to add
"SystemRoot" one like: "your custom variables ... ;SystemRoot=C:\Windows".
With this my sample runs with any variables and with no problems.
This is probably related to the usage of java.lang.Runtime.exec() method.
When it is called with environment variables parameter, the environment of
parent process is just ignored. This way, your java process runs with the
only NB_HOME, without knowledge about SystemRoot. As I've learned from here:
http://forum.java.sun.com/thread.jspa?threadID=329241&messageID=1916356 other
Java IDEs also have or had such problems. Probably IDEA could have an option
to append user's variables to ones the IDEA starts with.
Alexander.
Hi Alexander,
thanks for your help, adding ";SystemRoot=C:\Windows" did the trick.
IDEA should either automatically add this when something is entered in the Environment variables field or at least provide an option for this.
Otherwise, JetBrains will have to field a lot of support requests, most people won't find the solution on their own I guess...
Hello Tobias,
Posted a request: http://www.jetbrains.net/jira/browse/IDEADEV-20158.
Alexander.