Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 012012

How to find a class in a Jar file


To find a class file in a given Java Jar file, e.g. to find the class "KeyToken" in the file "selenium-server-standalone.jar",

# jar -tf selenium-server-standalone.jar | grep KeyToken
Feb 292012

How to get the hostname of a local machine using Java


The following codes illtsraeted how to get the hostname of the local machine using Java.


public class Test {

    public static void main(String[] args) {

        try {
            InetAddress addr = InetAddress.getLocalHost();

            // Get hostname
            String hostName = addr.getHostName();


        } catch (Exception e) {}