How To

How to Fix an UnknownHostException for Java Applications on Ubuntu

Member
By seedling
User-Submitted Article
(1 Ratings)

If you are programming your own Java applications and attempting to connect to another computer across the internet, you may be getting an UnknownHostException. Here's how to fix it for Ubuntu.

Difficulty: Moderately Easy
Instructions

Things You'll Need:

  • A computer running Ubuntu with an internet connection
  1. Step 1

    First, try to run your Java application. If you get an error like this: java.net.UnknownHostException, then your machine is not performing DNS properly in the context of your Java application. Sure, you may be able to read web pages in Firefox, but your Java applications may not have DNS capabilities available to them. Your machine may need some DNS packages installed.

  2. Step 2

    The package you need to install is called lib32nss-mdns. This library, according to its information page, allows "name resolution by common Unix/Linux programs in the ad-hoc mDNS domain".

  3. Step 3

    Open a terminal window.

  4. Step 4

    Type: sudo apt-get install lib32nss-mdns.

    Even if you are running 64-bit Linux, the above library should work.

  5. Step 5

    Re-run your Java application. Hopefully, this did the trick for you. If you no longer get the UnknownHostException, then problem solved.

Comments  

mkrueger said

Flag This Comment

on 7/25/2009 This link fixed my similar problem with Java on Debian 5.0:
http://uclue.com/?xq=2127#form

The key was this system property:
-Djava.net.preferIPv4Stack=true

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US

eHow Computers
eHow_eHow Technology and Electronics