Main menu:

Site search

Feeds

Categories

October 2014
S M T W T F S
« Sep    
 1234
567891011
12131415161718
19202122232425
262728293031  

Archive

java.net.UnknownHostException

Francesca.lib started giving java.net.UnknownHostException errors for many different java based applications, like tomcat, cocoon, and fedora. At the same time, fedora was refusing to start, but we couldn’t figure out why. It seemed like the java apps on francesca couldn’t access DNS, not even to resolve “localhost”. To test this, I wrote a little java application:

package edu.virginia.dris;

import java.net.*;
import java.io.*;

public class SocketTest {

/**
* @param args
*/
public static void main(String[] args) {

if(args.length<1){
System.out.println("Usage: java -jar HostTester.jar hostname port");
System.exit(0);
}

int port = Integer().parseInt(args[1]);

// TODO Auto-generated method stub
try{
Socket c1 = new Socket(args[0], port);
BufferedReader is = new BufferedReader (new InputStreamReader (c1.getInputStream()));
DataOutputStream os = new DataOutputStream (c1.getOutputStream());
System.out.println("No errors encountered");

}
catch (UnknownHostException e){
System.out.println("Unknown Host" + e);
e.printStackTrace();
}
catch (IOException ex) {
System.out.println("error io "+ ex);
ex.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}

}

Sure enough, the application worked fine on my desktop and on other servers, but when it ran on francesca it generated java.net.UnknownHostException errors.

Adding this line to the app made it run correctly on francesca:


System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");

ksclarke from #code4lib gave me the system-wide answer: put these lines in /etc/system:


_JAVA_OPTIONS='-Dsun.net.spi.nameservice.provider.1=dns,sun'
export _JAVA_OPTIONS

And now when I start fedora, it starts! The other problems seem to be fixed, too.


[fedora@francesca fedora-2.0]$ ./server/bin/fedora-start mckoi
Starting the Fedora server...
Picked up _JAVA_OPTIONS: -Dsun.net.spi.nameservice.provider.1=dns,sun
Using server profile: mckoi
Deploying API-M and API-A...
Picked up _JAVA_OPTIONS: -Dsun.net.spi.nameservice.provider.1=dns,sun
nohup: appending output to `nohup.out'
Waiting for server to start...
Waiting for server to start...
Waiting for server to start...
Waiting for server to start...
Waiting for server to start...
Waiting for server to start...
Processing file /usr/local/fedora/fedora-2.0/server/config/deployAPI-A.wsdd
Done processing
Picked up _JAVA_OPTIONS: -Dsun.net.spi.nameservice.provider.1=dns,sun
Processing file /usr/local/fedora/fedora-2.0/server/config/deploy.wsdd
Done processing
Initializing Fedora Server instance...
Picked up _JAVA_OPTIONS: -Dsun.net.spi.nameservice.provider.1=dns,sun
OK

Comments

Comment from Peter Murray
Time: April 26, 2006, 8:24 pm

Good catch! I’d suggest registering for the new Fedora wiki and posting your find there for other to make use of as well…

Write a comment