developing environment

22
IT G ROUP Developing Environment Olivier de Pertat

Upload: caia

Post on 09-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Developing Environment. Olivier de Pertat. Developing In Java. Text Editors Java Compilers Building Tools Setting Your Environment Logging Capabilities Unit Testing. Java Compilers. Latest Java Version : 1.5 Latest J2EE Version : 1.4 (1.5 is comming) Many Providers : - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Developing Environment

IT GROUP

Developing Environment

Olivier de Pertat

Page 2: Developing Environment

Developing In Java

Text Editors

Java Compilers

Building Tools

Setting Your Environment

Logging Capabilities

Unit Testing

Page 3: Developing Environment

Java Compilers

Latest Java Version : 1.5

Latest J2EE Version : 1.4 (1.5 is comming)

Many Providers : SUN : Solaris, Win32, Linux x86

IBM : AIX, Linux x86, Win32, Solaris, HP-UX, OS/390, z/Linux…

BEA : Linux iA64, Win32

HP : HP-UX

Non Compliant JVM :Microsoft J++ & Many old JVM

Warning : For JAKARTA products on Linux Operating Systems it might be useful to use IBM JDK’s.

Old Microsoft JVM are not completely Java Compliant.

Page 4: Developing Environment

Building Tool : ANT

Command Line not suited to projects.

ANT :Managed by XML File (build.xml).

Tag based Architecture.

Fully written in Java.

Runs on every OS that supports Java.

Extensible Application by development.

Not limitations like : Makefile, nmake, jam…

Developed by Jakarta from Apache Group.

An Industry Standard : Used in IDE for Java Compilation : JBuilder, Jext, Emacs, JDE, NetBeans, JEdit, Eclipse, Visual Age For Java, WSAD

AS : WebLogic (deployment handled by ANT)

Page 5: Developing Environment

ANT (1)

Tag Structure :Main tag : Project

One “project” tag by build file.

Specifies the default task to perform.

Specifies the working directory.

Default file : Build.xml

<project name="j2ee-lesson" default="sys-about" basedir=".">

<target name="sys-about"> <echo>Hello World ! </echo>  </target>  </project>

Command line :ant <target>

Page 6: Developing Environment

ANT (2)

Variable declaration :

<project name="j2ee-lesson" default="sys-about" basedir=".">

<!-- System variables   --> <property environment="myenv" />

<property name=" PATH“ value="${myenv.PATH}" /><property name="SQL_FILE" value="test.tmp.sql" />

Java Compilation :

<target name="j2ee-mk-class" depends=""><buildnumber /><echo>Compiling Java Source</echo>

  <javac srcdir="${src}" debug="yes“ destdir="${build}“ classpath="${PROJECT_CLASSPATH}"/>

</target>

Page 7: Developing Environment

ANT (3)

Java Execution : <target name="run-MyHello" depends="j2ee-mk-class"> <java classname="mytest.MyHello" fork="yes">  <jvmarg value="${RUN_OPTION_1}" /> <classpath> <pathelement path="${PROJECT_RUN_CLASSPATH}"/> </classpath> </java> </target>

File Manipulation :Create Directory : <mkdir dir="${build}" />Delete files & directories : <delete dir="${build}" />Copy, Move files & directoriesCompression : gzip, zip, jar, bzip2, tarSecurity : chmodOthers : checksum, basename, concat, touch

Page 8: Developing Environment

ANT (4)

System Tasks Execution :<exec executable="j2ee.bat">

<env key="CLASSPATH" value="${J2EE_CLASSPATH}" /><arg line="-verbose" />

</exec>

Network Services :Mailing : mail

FTP : File transfer

RCS & CVS Management : cvs…

Page 9: Developing Environment

ANT (5)

SQL Commands (JDBC Way) :<target name="sys-OracleSQL" depends="">

<sql driver="${ORACLE_DRIVER}" url="${ORACLE_URL}" userid="${ORACLE_USER}"

password="${ORACLE_PASSWORD}" classpath="${ORACLE_CLASSPATH}" src="${SQL_SCRIPT}"

print="true" /> </target>

SQL Commands (SQL*Plus Way) : <property name="DB_EXEC_ARGS" value="${ORACLE_USER}/$

{ORACLE_PASSWORD}@${ORACLE_NAME} @${SQL_SCRIPT}" />  

<echo file="${SQL_SCRIPT}" append="true">exit;</echo>   <echo>${DB_EXEC_ARGS}</echo> <exec dir="." executable="${ORACLE_SQLCMD}">  <arg line="${DB_EXEC_ARGS}" />   </exec> 

Page 10: Developing Environment

Logging Capabilities

Traces are needed :DevelopmentDebuggingProduction & problem trackingSystem.out : is limited and not persistent (#define)

Logging APIs:Jakarta’s Log4J: Production reference

Most used in projectsPowerful

JDK 1.4 logging APIs (JSR-47):Standard Java API since 1.4 VMsSun’s reference

Jakarta Common Logging (JCL):Wrapper API for : Log4J, JDK 1.4, Avalon LogKit, Pre 1.4 JDKs, Common functionalities present but not specifics

Page 11: Developing Environment

Log4J

LOG4J :Developed JAKARTA (Apache Group)

Logging system dynamically & statically configurable

high-performance Java API

Defined levels :FATAL : logger.fatal(“string”)ERROR : logger.error(“string”)WARNING : logger.warn(“string”)INFO : logger.info(“string”);DEBUG : logger.debug(“string”)

Page 12: Developing Environment

LOG4J (2)

Import needed : org.apache.log4j.*;

Sample In Java : static Logger logger =

Logger.getLogger(mytest.MyLoggedHello.class.getName());

public MyLoggedHello() { logger.fatal("FATAL : Constructor called !"); logger.error("ERROR : Constructor called !"); logger.warn( "WARN : Constructor called !"); logger.info( "INFO : Constructor called !"); logger.debug("DEBUG : Constructor called !"); }

Page 13: Developing Environment

LOG4J (3)

File configuration : Log4J.properties (Console)log4j.rootCategory=DEBUG, A1log4j.appender.A1=org.apache.log4j.ConsoleAppenderlog4j.appender.A1.layout=org.apache.log4j.PatternLayout

File configuration : Log4J.properties (File)log4j.rootCategory=INFO,Rlog4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=wstools-debug.loglog4j.appender.R.MaxFileSize=100KBlog4j.appender.R.MaxBackupIndex=1log4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

JVM Arguments :java -Dlog4j.configuration=file:/Log4J.properties MyProgam

Page 14: Developing Environment

JDK Logging

Sun’s Flogging FrameworkLogger / LogManager Architecture

Package: java.util.logging.

Levels are:Level.SEVERE

Level.WARNING

Level.INFO

Level.CONFIG

Level.FINE

Level.FINER

Level.FINEST

Page 15: Developing Environment

JDK Logging (2)

Handlers:StreamHandlers

Console Handlers

File Handler

SocketHandler

MemoryHandler

Formatters:SimpleFormatter: simple chars output

XMLFormatter: XML File format output

JVM Parameter:java -Djava.util.logging.config.file=monLogging.properties

Page 16: Developing Environment

Unit Testing : JUnit

Unit Testing :Non-regression tests

Improve quality

Speed-up code writing

JUnit :Developed JAKARTA

Command-Line or Graphical.

Simple Java API.

Package : junit.framework

Page 17: Developing Environment

JUnit (2)

JUnit Java Sample :

public class CheckMyHello extends TestCase { ….. public void testAssertPosInfinityEqualsInfinity() { assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, 0.0); } public static Test suite() { TestSuite suite= new TestSuite(); suite.addTest(new TestSuite("testItSays")); suite.addTest(new TestSuite(CheckMyHello.class)); suite.addTest(new TestSuite(CheckAssertTest.class)); return suite; } }

Page 18: Developing Environment

JUnit (3)

Running JUnit (Command Line) :

public static void main(String [] args) {

junit.textui.TestRunner.run(suite());

}

Running JUnit (Graphical) :

java junit.swingui.TestRunner mytest.CheckMyHello

Page 19: Developing Environment

JUnit (4)

Using Standard Output :

public void testItSays() { String lineSeparator = System.getProperty("line.separator");

ByteArrayOutputStream out4debug = new ByteArrayOutputStream();

PrintStream out_new = new PrintStream(out4debug); PrintStream out_bkp = System.out; MyHello objectTested = null; String outputExcepted = "Hello Object Built !" +

lineSeparator; System.setOut(out_new); objectTested = new MyHello(); System.setOut(out_bkp);

assertTrue((out4debug.toString()).equals(outputExcepted)); }

Page 20: Developing Environment

ODP’s JavaBox (1)

Tool Box packaged for Java programming: Everything is included! Nothing more is needed.

Java Standard Edition 1.4.2 (J2SE)Java Entreprise Edition 1.4:

SUN Application Server: Tools, libs…

2 Database Engine: PointBase ServerHSQL DB

Java Text Editor: JExt (Color highlight)ANT: asantSome useful utilities:

Custom Windows ShellUNIX Basic utilities: tail, zip, md5sum..

Why?Simple.No complex to understand IDE to learn. Easy to install at work, at home… No special authorizations are needed to install it. Even in a cyber coffee as a guest user it works! Can be used for large projects.

Page 21: Developing Environment

ODP’s JavaBox (2)

Installation:Unzip the archive to anywhere you want.

Run the SHELL named “JavaShell.cmd”. It automatically detects whether or not installation has been processed.

Installation process is run once.

Installation is fast but can be slow down by Antivirus software

Page 22: Developing Environment

ODP’s JavaBox (3)

A virtual J: drive is mapped to your installation Directory.

Every source file should be placed in J:\src

To write your first program you should:Launch a JavaShell

Launch JExt (thro ugh the shortcut placed in J:\bin)

Write your program

Save it to J:\src directory

Compile it by typing in the JavaShell:

Run it by typing in the JavaShell

Enjoy!

J:\>asant make

J:\>java MyFirstProgram