how to create a skeleton of a java console application

4
N o t e b o o k : C C P W i k i m a t e r i a l s C r e a t e d : 0 5 . 0 6 . 2 0 1 2 1 6 : 3 5 U p d a t e d : 0 3 . 0 7 . 2 0 1 2 1 9 : 1 8 L o c a t i o n : W i e n , A u s t r i a T a g s : C C P P D , С и с т е м а у п р а в л е н и я с т р а н о й , Я в а H o w t o c r e a t e s k e l e t o n o f a J a v a c o n s o l e a p p l i c a t i o n H o w t o c r e a t e s k e l e t o n o f a J a v a c o n s o l e a p p l i c a t i o n P r e r e q u i s i t e s F o l l o w i n g c o n d i t i o n s m u s t b e s a t i s f i e d b e f o r e y o u c a n i m p l e m e n t t h e s t e p s i n t h i s t u t o r i a l : 1 ) J a v a 1 . 6 o r b e t t e r i s i n s t a l l e d 2 ) M a v e n 2 o r b e t t e r i s i n s t a l l e d S t e p 1 I n v o k e f o l l o w i n g c o m m a n d o n t h e c o m m a n d l i n e m v n a r c h e t y p e : g e n e r a t e \ - D a r c h e t y p e G r o u p I d = o r g . a p a c h e . m a v e n . a r c h e t y p e s \ - D g r o u p I d = r u . a l t r u i x \ - D a r t i f a c t I d = p o p u l a t i o n g e n e r a t o r S t e p 2 C r e a t e e c l i p s e p r o j e c t f i l e s b y r u n n i n g f o l l o w i n g c o m m a n d i n t h e c o m m a n d l i n e : m v n e c l i p s e : e c l i p s e S t e p 3 - a d d c h e c k s t y l e f i l e s C o p y f o l l o w i n g f i l e s i n t o t h e d i r e c t o r y w i t h t h e p o m . x m l f i l e o f t h e n e w p r o j e c t . 1 ) a l t r u i x - c h e c k s t y l e . j a v a . h e a d e r 2 ) a l t r u i x - c h e c k s t y l e . s h . h e a d e r 3 ) a l t r u i x - c h e c k s t y l e . p r o p e r t i e s . h e a d e r 4 ) a l t r u i x - c h e c k s t y l e . x m l . h e a d e r 5 ) a l t r u i x - c h e c k s t y l e . x m l S t e p 4 - a d d r e p o r t i n g c o n f i g u r a t i o n t o p o m . x m l P a s t e f o l l o w i n g t e x t i n t o t h e p o m . x m l f i l e . < r e p o r t i n g > < p l u g i n s > < p l u g i n > < g r o u p I d > o r g . c o d e h a u s . m o j o < / g r o u p I d > < a r t i f a c t I d > j a v a n c s s - m a v e n - p l u g i n < / a r t i f a c t I d >

Upload: dmitri-pisarenko

Post on 04-Jul-2015

71 views

Category:

Business


1 download

TRANSCRIPT

Page 1: How to create a skeleton of a Java console application

NNNNooootttteeeebbbbooooooookkkk:::: CCP Wiki materials

CCCCrrrreeeeaaaatttteeeedddd:::: 05.06.2012 16:35 UUUUppppddddaaaatttteeeedddd:::: 03.07.2012 19:18

LLLLooooccccaaaattttiiiioooonnnn:::: Wien, Austria

TTTTaaaaggggssss:::: CCP PD, Система управления страной, Ява

How to create skeleton of a Java console application

How to create skeleton of a Java console application

Prerequisites

Following conditions must be satisfied before you can implement the steps

in this tutorial:

1) Java 1.6 or better is installed

2) Maven 2 or better is installed

Step 1

Invoke following command on the command line

mvn archetype:generate \

-DarchetypeGroupId=org.apache.maven.archetypes \

-DgroupId=ru.altruix \

-DartifactId=populationgenerator

Step 2

Create eclipse project files by running following command in the command

line:

mvn eclipse:eclipse

Step 3 - add checkstyle files

Copy following files into the directory with the pom.xml file of the new

project.

1) altruix-checkstyle.java.header

2) altruix-checkstyle.sh.header

3) altruix-checkstyle.properties.header

4) altruix-checkstyle.xml.header

5) altruix-checkstyle.xml

Step 4 - add reporting configuration to pom.xml

Paste following text into the pom.xml file.

<reporting>

<plugins>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>javancss-maven-plugin</artifactId>

Page 2: How to create a skeleton of a Java console application

<version>2.0</version>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-pmd-plugin</artifactId>

<configuration>

<targetJdk>1.7</targetJdk>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-checkstyle-plugin</artifactId>

<version>2.6</version>

<configuration>

<configLocation>altruix-

checkstyle.xml</configLocation>

<includeTestSourceDirectory>true</includeTestSourceDirectory>

</configuration>

</plugin>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>cobertura-maven-plugin</artifactId>

<configuration>

<formats>

<format>html</format>

<format>xml</format>

</formats>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-project-info-reports-

plugin</artifactId>

<version>2.0.1</version>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-site-plugin</artifactId>

<version>2.2</version>

<configuration>

<inputEncoding>UTF-8</inputEncoding>

<outputEncoding>UTF-8</outputEncoding>

<locales>en,ru</locales>

</configuration>

</plugin>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>findbugs-maven-plugin</artifactId>

<version>2.0.1</version>

</plugin>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>jdepend-maven-plugin</artifactId>

</plugin>

</plugins>

</reporting>

Page 3: How to create a skeleton of a Java console application

Step 5 - check that reporting works

Create reports using "mvn site" command.

Thereafter, open the file target/site/index.html.

It should look like this:

When you click on "Project reports", you should see following:

Following reports must be present:

1) Checkstyle

2) Cobertura Test Coverage

3) CPD report

4) FindBugs report

5) JavaNCSS report

6) JDepend

7) PMD Report

Step 6

Create a text file called ".gitignore" in the same directory as the

pom.xml file.

This text file should contain only one line:

Page 4: How to create a skeleton of a Java console application

target

Step 7 - add compiler configuration

Paste following code at the correct place in the pom.xml file:

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.6</source>

<target>1.6</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

</build>

Step 8 - add altruix-commons and logging dependencies

Paste following code at the correct place in the pom.xml file:

<dependencies>

...

<dependency>

<groupId>ru.altruix</groupId>

<artifactId>commons</artifactId>

<version>1.7</version>

</dependency>

<dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-core</artifactId>

<version>0.9.26</version>

</dependency>

<dependency>

<groupId>ch.qos.logback</groupId>

<artifactId>logback-classic</artifactId>

<version>0.9.26</version>

</dependency>

...

</dependencies>

Step 9 - change version of JUnit

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.8.2</version>

<scope>test</scope>

</dependency>