Friday, September 12, 2014

how to .xz files

  • J: use xz to uncompress archive -- notice: J is uppercase

tar xvfJ filename.tar.xz  

xz --decompress filename.gz

Thursday, September 11, 2014

how to install tomcat

PLATFORM
windows 7 family edition 64-bit
jdk 1.7.0
tomcat 7.0.26 (64-bit edition)


go to apache tomcat website and download tomcat 7.0

http://tomcat.apache.org/

download 64-bit Windows zip file as we try to install tomcat 7.0.26 on windows 7 64-bit system

unzip apache-tomcat-7.0.26-windows-x64.zip

this is how the folder looks like after unzipping

C:\Downloads\apache-tomcat-7.0.26-windows-x64\apache-tomcat-7.0.26\bin

If you click startup.bat file to start tomcat IT WILL NOT RUN

C:\Downloads\apache-tomcat-7.0.26-windows-x64\apache-tomcat-7.0.26\bin\startup.bat

To get tomcat running,first run command prompt

Then with cd command go to directory

cd C:\Downloads\apache-tomcat-7.0.26-windows-x64\apache-tomcat-7.0.26\bin

Run startup.bat in the command prompt

C:\Downloads\apache-tomcat-7.0.26-windows-x64\apache-tomcat-7.0.26\bin>startup.bat

Then type on firefox

http://localhost:8080


Server Status" and "Manager App" interfaces require manager-gui role and "Host Manager" requires admin-gui role.

add these lines and restart tomcat if it works.

C:\Downloads\apache-tomcat\conf \tomcat-users.xml


<role rolename="manager-gui,admin-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui,admin-gui"/>


configure tomcat port.
C:\Downloads\apache-tomcat\conf\server.xml

 <Connector port="5555" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

This file sets java_home manually and runs tomcat on the folder mentioned.
contents of "tomcat start.cmd" file.

@echo off
SET JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_31
SET CATALINA_HOME=C:\Downloads\apache-tomcat
C:\Downloads\apache-tomcat\bin\startup.bat

run "tomcat start.cmd" on folder
C:\Downloads\ciroot

test tomcat whether it runs
tomcat runs on http://localhost:8080/

how to spring-framework-3.1.0. and eclipse indigo


  • PLATFORM

*windows 7 family edition 64-bit

*download Java Platform, Standard Edition
Java SE 7u3
jdk-7u3-windows-i586.exe
www.oracle.com

*download Java EE 6 Development Kit Bundles without JDK
Java EE 6 SDK Update 4
java_ee_sdk-6u4-windows-ml.exe
www.oracle.com

*download tomcat 7.0.26 (32-bit edition)
apache-tomcat-7.0.26-windows-x86.zip
http://tomcat.apache.org

*download Eclipse IDE for Java EE Developers
eclipse indigo package 32 bit
eclipse-jee-indigo-SR2-win32.zip
http://www.eclipse.org

*download Spring Framework 3.1.0.RELEASE
spring-framework-3.1.0.RELEASE-with-docs.zip
http://www.springsource.org/download


Because of the problems linked to whether 64-bit or 32-bit software should be used,even though I use 64-bit I prefer 32-bit software so that I don't risk having compatibility issues

@there are two types of containers in spring: applicationcontext and beanfactory.
applicationcontext is used in this example

@ create a new project eg "tester"
Eclipse-New-Java Project

@righ click on file "tester"
java build path-libraries-add external jars

@add all files in "spring-framework-3.1.0.RELEASE\dist"
@add file "spring-framework-3.1.0.RELEASE\projects\spring-build\lib\ivy\commons-logging.jar"

@create a new package
com.edu4java.spring.tutorial3

@create new java class Hello.java

@create Main.java class that uses Hello.java

@create context.xml  by using this pdf file "spring-framework-3.1.0.RELEASE\docs\spring-framework-reference\pdf\spring-framework-reference.pdf"

References:
http://www.youtube.com/watch?v=ZwMwfGNrRtE&feature=related

how to spring aop with eclipse indigo

PLATFORM

*windows 7 family edition 64-bit
ps:Because of the problems linked to whether 64-bit or 32-bit software should be used,even though I use 64-bit I prefer 32-bit software so that I don't risk having compatibility issues


*download Java Platform, Standard Edition
Java SE 7u3
jdk-7u3-windows-i586.exe
www.oracle.com

*download Java EE 6 Development Kit Bundles without JDK
Java EE 6 SDK Update 4
java_ee_sdk-6u4-windows-ml.exe
www.oracle.com

*download Eclipse IDE for Java EE Developers
eclipse indigo package 32 bit
eclipse-jee-indigo-SR2-win32.zip
http://www.eclipse.org

*download Spring Framework 3.1.0.RELEASE
spring-framework-3.1.0.RELEASE-with-docs.zip
http://www.springsource.org/download

*download aspectj-1.6.12.jar
http://www.eclipse.org/aspectj/downloads.php

What is AspectJ?
AspectJ(tm) is a simple and practical extension to the Java(tm) programming language that adds to Java aspect-oriented programming (AOP) capabilities. AOP allows developers to reap the benefits of modularity for concerns that cut across the natural units of modularity. In object-oriented programs like Java, the natural unit of modularity is the class. In AspectJ, aspects modularize concerns that affect more than one class.


*download aopalliance.zip

The AOP Alliance project is a joint open-source project between several software engineering people who are interested in AOP and Java
AOP Alliance: http://aopalliance.sourceforge.net/


*download cglib-2.2.2.jar
cglib is a powerful, high performance and quality Code Generation Library, It is used to extend JAVA classes and implements interfaces at runtime.
CGILIB: http://cglib.sourceforge.net/


*download asm-3.3.1.jar (asm-4.0-bin.zip caused compatability problems and had to remove)

ASM is an all purpose Java bytecode manipulation and analysis framework. It can be used to modify existing classes or dynamically generate classes, directly in binary form
http://asm.ow2.org/

how to 32 bit vs 64 bit

  •  how to 32 bit vs 64 bit



x86_64 ==> 64-bit kernel
i686   ==> 32-bit kernel

on linux commands to find

cat /proc/cpuinfo

grep flags /proc/cpuinfo

tm(transparent mode) or rm(real mode) or lm(long mode)

rm ==> 16-bit processor
tm ==> 32-bit processor
lm ==> 64-bit processor

you can have a 64-bit CPU with a 32-bit kernel installed


getconf LONG_BIT
    32, if OS is 32 bit
    64, if OS is 64 bit

 grep "CONFIG_64" /lib/modules/*/build/.config




#include <stdio.h>

int main(void)
{
    printf("%d\n", __WORDSIZE);
    return 0;
}



$ ls -l /lib*/ld-linux*.so.2
/lib/ld-linux.so.2
/lib64/ld-linux-x86-64.so.2


lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit

http://stackoverflow.com/questions/246007/how-to-determine-whether-a-given-linux-is-32-bit-or-64-bit  

how to java enterprise application

there are 3 ways of implementing enterprise applications with java. This list can be updated or corrected.

1-licensed j2ee servers -weblogic,websphere,oracle application server

2-open source j2ee containers - jboss,glassfish,tomcat,openejb,activemq

3-spring framework + opensource servlet/jsp engine -tomcat,jetty,resin

Tuesday, April 29, 2014

Java 8 features : default methods

Functional interface can not have more than one abstract method but it can have more than one default methods.


public interface DefaultInterface1 {
   
    public void printMessage1();
   
    default void printMessage2(){
        System.out.println("default method test1");
    }
    default void printMessage3(){
        System.out.println("default method test2");
    }
   
}

you can either use annotations
@FunctionalInterface
public interface DefaultInterface1 {
   
    public void printMessage1();
   
    default void printMessage2(){
        System.out.println("default method test1");
    }
    default void printMessage3(){
        System.out.println("default method test2");
    }
   
}

public class DefaultInterface1Test implements DefaultInterface1 {

    public static void main(String[] args) {
       
        DefaultInterface1Test di1=new DefaultInterface1Test();
       
       
        di1.printMessage1();
//        default method test1
        di1.printMessage2();
//        default method test2
        di1.printMessage3();
    }

    @Override
    public void printMessage1() {
        System.out.println("not default method");
       
    }

}

Java 8 features : lambda expressions

Anonymous classes enable you to make your code more concise.
They enable you to declare and instantiate a class at the same time.
They are like local classes except that they do not have a name

public interface FunctionalInterface1 {

//    Functional Interface by defining Single Abstract Method in interface.
    public void printMessage();
}

public class FunctionalInterface1Test {

    public static void main(String[] args) {
       
//        anonymous inner class example
        FunctionalInterface1 ft1=new FunctionalInterface1(){
           
            public void printMessage(){
                System.out.println("anonymous inner class example");
            }
        };

        ft1.printMessage();
       
//        lambda expression example
        FunctionalInterface1 ft2=()->{
            System.out.println("lambda test1");
            System.out.println("lambda test2");
        };
        ft2.printMessage();
    }

}




Functional interface can not have more than one abstract method but it can have more than one default methods.
You can use annotations for functional interfaces

@FunctionalInterface
public interface FunctionalInterface2 {

//    Functional Interface by defining Single Abstract Method in interface.
    public void printMessage();
//    public void printMessage1();
}

if you uncomment  printMessage1 it gives error below
Invalid '@FunctionalInterface' annotation; FunctionalInterface2 is not a functional interface

public class FunctionalInterface2Test {

    public static void main(String[] args) {
       
       
        FunctionalInterface2 fi1=new FunctionalInterface2() {
           
            @Override
            public void printMessage() {
                System.out.println("anonymous inner class test1");
               
            }
        };

        fi1.printMessage();
       
        FunctionalInterface2 fi2=()->{
            System.out.println("lambda expression test1");
        };
       
        fi2.printMessage();
    }

}


Using functional interfaces with anonymous inner classes are a common pattern in Java
In addition to the EventListener classes, interfaces like Runnable and Comparator are used in a similar manner
Therefore, functional interfaces are leveraged for use with lambda expressions.
As Runnable is having Single Abstract Method, we can consider this as a Functional Interface and we can use Lambda expression

public class RunnableTest {

    public static void main(String[] args) {
       
         System.out.println("=== RunnableTest ===");
       
        // Anonymous Runnable
        Runnable r1 = new Runnable(){

            @Override
            public void run() {
                System.out.println("anonymous works");
               
            }

    };

    // Lambda Runnable
    Runnable r2=()-> System.out.println("lambda works");
   
    // Run em!
    r1.run();
    r2.run();
   
    }
}    


Wednesday, April 23, 2014

super() example

It’s legal to invoke "new" from within a constructor and  to call
super() on a class with no explicit superclass.

public class Test1 {

static int count = 0;

Test1() {
while(count < 10)
new Test1(++count);
}

Test1(int x)
{
super();
}

public static void main(String[] args) {
new Test1();
new Test1(count);
System.out.println(count++);
}

}


outcome is 10 here.


Sunday, April 20, 2014

how to mirror repository on artifactory

If you automatically generate settings.xml file on artifactory server.Mirror part looks like below

<mirrors>
    <mirror>
      <mirrorOf>*</mirrorOf>
      <name>repo</name>
      <url>http://localhost:5555/artifactory/repo</url>
      <id>repo</id>
    </mirror>
  </mirrors>


Artifactory repositories use "**/*" syntax. You should replace mirror settings like below

  <mirrors>
    <mirror>
      <mirirrorOf>**/*</mirrorOf>
      <name>repo</name>
      <url>http://localhost:5555/artifactory/repo</url>
      <id>repo</id>
    </mirror>
  </mirrors>

Sunday, March 16, 2014

my diary of resolutions

  • I run offline artifactory server which acts like maven repository.From time to time I get this error.

Eclipse Kepler Problems view tab


Description    Resource    Path    Location    Type
ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.tomcat:el-api:jar:6.0.32: ArtifactResolutionException: Failure to transfer org.apache.tomcat:el-api:pom:6.0.32 from http://localhost:5555/artifactory/libs-release was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.tomcat:el-api:pom:6.0.32 from/to central (http://localhost:5555/artifactory/libs-release): Connection refused: no further information to http://localhost:5555/artifactory/libs-release/org/apache/tomcat/el-api/6.0.32/el-api-6.0.32.pom    pom.xml    /simple-parent    line 1    Maven Dependency Problem

Normally you see many errors in problems view.This is just one of them.To resolve this

right click on the project.Maven-Update Project



My guess is that if you run eclipse first when artifactory server is shut down you get this problem.


  • c3p0 problem 
This is what I get eclipse console view.

2014-03-16 22:42:10 DEBUG C3P0PooledConnectionPool:468 - Preparing to destroy PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@17c0756
2014-03-16 22:42:10 DEBUG NewPooledConnection:566 - com.mchange.v2.c3p0.impl.NewPooledConnection@17c0756 closed by a client.
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:566)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:989)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1174)


in applicationContext.cml

<bean id="MyDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

resolution

<bean id="MyDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" >

I don't exactly know why.When I browse class path I couldn't find destroy method.



  • maven project error which is on eclipse luna

[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Window > Preferences > Java > Installed JREs >Execution Environments > JavaSE-1.8
Project > Right Click > Maven > Update Project


  • ArtifactTransferException: Failure to transfer

If you get this error message starting with this you can trace the failing jar or dependency file on local folder below.This path is a generic one for hibernate

C:\Users\user1\.m2\repository\org\hibernate\hibernate-core

Remove folder or back up just in case you need.Update project via eclipse with m2eclipse

  • This happens when you configure project while artifactory is not running


C:\Users\yeniceri\.m2\repository\org\apache\maven\plugins\maven-war-plugin

Delete 2.4
Update project to sync with artifactory

  • Index downloads are disabled, search result may be incomplete.

#1
Windows > Preferences > Maven
check the box
"Download repository index updates on startup"
"Download Artifact Sources"

#2
Window > Show View > Other > Maven > Maven Repositories
central repository in 'Global Repositories'
Tick 'Full Index Enabled' and then 'Rebuild Index'

http://stackoverflow.com/questions/24252256/how-to-enable-index-downloads-in-eclipse-for-maven-search


  • -Dmaven.multiModuleProjectDirectory system property is not set.Check $M2_HOME environment variable and mvn script match.

apache-maven-3.3.1
java: 1.8.0_31
eclipse luna

Window-> Preference -> Java -> Installed JREs -> Edit
Default VM arguments
-Dmaven.multiModuleProjectDirectory=$M2_HOME

http://stackoverflow.com/questions/29330577/maven-3-3-1-eclipse-dmaven-multimoduleprojectdirectory-system-propery-is-not-s

Sunday, February 16, 2014

how to run artifactory offline

If you are planning to run artifactory on offline mode just click check box.



Organization-wide Offline
    This is common in organizations using a separate secured network (such as military or financial institutes) and are disconnected from the rest of the world.
    In this case, remote repositories serve as caches only and do not proxy remote artifacts.