Monday, June 18, 2012

how to find byte code class file JDK compiled java version

you can find out the byte code class version.

On Linux, Mac OS X or Windows with Cygwin installed, the file(1) command knows the class version. Extract a class from a jar and use file to identify it:

$ jar xf log4j-1.2.15.jar
$ file ./org/apache/log4j/Appender.class
./org/apache/log4j/Appender.class: compiled Java class data, version 45.3

A different class version, for example:

root@mypc:/merchant-sample/classes/com/paypal/core$ file SSLUtil.class 
SSLUtil.class: compiled Java class data, version 50.0 (Java 1.6)


The class version major number corresponds to the following Java JDK versions:

46 = Java 1.2
47 = Java 1.3
48 = Java 1.4
49 = Java 5
50 = Java 6
51 = Java 7

Alternatively, you can make a simple test class that can identify class version.
import java.io.*;
 
public class Test {
    public static void main(String[] args) throws IOException {
        checkClassVersion("Class path you want to know");
    }                      
 
    private static void checkClassVersion(String filename)
        throws IOException
    {
        DataInputStream in = new DataInputStream
         (new FileInputStream(filename));
 
        int magic = in.readInt();
        if(magic != 0xcafebabe) {
          System.out.println(filename + " is not a valid class!");;
        }
        int minor = in.readUnsignedShort();
        int major = in.readUnsignedShort();
        System.out.println(filename + ": " + major + " . " + minor);
        in.close();
    }
}


Thursday, June 14, 2012

Configure Proxy server bypass or pass

When you work in enterprise environment, you will most likely need to use proxy server either you like or not.

I have suffered for long time because proxy setting and I had to have customized proxy bypass script due to development.

I would like to share my snippet. I hope it helps.

Ubuntu apt-get Proxy configuration. For more detail




Maven test proxy setting



Eclipse proxy set up for JRE/JDK



Eclipse Network Proxy configuration for installing new sofware or update plugins



Eclipse Tomcat proxy set up
add below text
 -Dhttp.proxyHost="106.101.91.4" -Dhttp.proxyPort="8080" -Dhttps.proxyHost="106.101.91.4" -Dhttps.proxyPort="8080"



Internet Explorer Proxy configuration



Eclipse Java application Proxy configuration



Ubuntu Proxy for chrome browser



Firefox Proxy configuration



Proxy Automate Script(PAC) sample

/*************************
Configuration Example path

For IE on Windows
file://d:\proxy.pac

For FF on Windows
file:///d://proxy.pac

For FF on Ubuntu
file:///home/proxy.pac
*************************/
var PROXY1 = "PROXY 123.123.123.1:8080";
var PROXYY2 = "PROXY 123.123.123.2:8080";

var DIRECT = "DIRECT";
var regexpr_facebook = /^[.a-zA-Z0-9-]*.facebook.com/;
var myip = myIpAddress();

//url = http://www.yahoo.com/dkdkd/allld.jpg
//host = www.yahoo.com
function FindProxyForURL(url, host){

 //For Home AP access ( If Source IP starts with 192.168.x.x) bypass Proxy
 if (isInNet(myip, "192.168.0.0", "255.255.0.0")) {
  return DIRECT;
 //your local computer bypass Proxy
 }else if (isInNet(host, "127.0.0.1", "255.255.255.0") || host=="localhost") {
  return DIRECT;
 //C class subnet mask by pass Proxy(it means all IPs starts with 111.111.111 will bypass
 }else if (isInNet(host, "111.111.111.xxx", "255.255.255.0") ) {
  return DIRECT;
 //When you need to access from host file definition IPs
 }else if (host=="devsite"|| host=="mytest") {
  return DIRECT;
 //if you need proxy for specific ip ranges ( Domain will be resolved by DNS ang get IP)
 }else if (isInNet(myip, "106.101.7.93", "255.255.255.0") ) {
  return PROXY1;
 //if you need proxy for specific domain address
 }else if (regexpr_facebook.test(host)){
  return PROXYY2;
 }else{
  return PROXY1;
 }
}