LOG4J

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Apache log4j
Developed by Apache Software Foundation
Latest release 1.2.15 / August 29, 2007
Written in Java
OS Cross-platform
Genre Logging Tool
License Apache License 2.0
Website http://logging.apache.org/log4j

Log4j is a Java-based logging utility. It was originally written by Ceki Gülcü and is now a project of the Apache Software Foundation. It is used primarily as a debugging tool. log4j is one of several Java Logging Frameworks

Ceki Gülcü has since started the SLF4J and Logback projects, with the intention of offering a compatible successor to log4j.

Log4j 1.2 offers six standard logging levels; from highest (coarsest) to lowest (finest):

  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE

Also, custom logging levels can be added.

There are two ways to configure log4j. One is with a properties file and the other is with an XML file. Within either you can define 3 main components: Loggers, Appenders and Layouts. Configuring logging via a file has the advantage of turning logging on or off without modifying the application that uses log4j. The application can be allowed to run with logging off until there’s a problem, for example, and then logging can be turned back on simply by modifying the configuration file.

Loggers are logical log file names. They are the names that are known to the Java application. Each logger is independently configurable as to what level of logging (FATAL, ERROR, etc) it currently logs. In early versions of log4j, these were called category and priority, but now they’re called logger and level, respectively.

The actual outputs are done by Appenders. There are numerous Appenders available, with descriptive names, such as FileAppender, ConsoleAppender, SocketAppender, SyslogAppender, NTEventLogAppender and even SMTPAppender. Multiple Appenders can be attached to any Logger, so it’s possible to log the same information to a file locally and to a socket listener on another computer, for example.

Appenders use Layouts to format log entries. A popular way to format one-line-at-a-time log files is PatternLayout, which uses a pattern string, much like the C / C++ function printf. There are also HTMLLayout and XMLLayout formatters for use when HTML or XML formats are more convenient.

Contents

[hide]

//<![CDATA[
if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); }
//]]>

[edit] Example configuration

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC
"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd">
<log4j:configuration>
    <!-- an appender is an output destination, such as e.g. the console or a file;
    names of appenders are arbitrarily chosen -->
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
        </layout>
    </appender>

    <!-- loggers of category 'org.springframework' will only log messages of level info or higher;
    if you retrieve Loggers by using the class name (e.g. Logger.getLogger(AClass.class))
    and if AClass is part of the springframework.org package, it will belong to this category -->
    <category name="org.springframework">
        <priority value="info"/>
    </category>

    <category name="org.acegisecurity">
        <priority value="info"/>
    </category>

    <root><!-- the root category -->
        <!-- all log messages of level debug or more serious will be logged, unless defined otherwise -->
        <!-- all log messages will be logged to the appender 'stdout', unless defined otherwise -->
        <priority value="debug" />
        <appender-ref ref="stdout" />
    </root>
</log4j:configuration>

[edit] Log Viewer

Apache has another project named Chainsaw which was intended to use log4j generated log files. Chainsaw is a java-based GUI viewer with a lot of functionality. Chainsaw also uses similar configuration file as log4j. Other log viewing tools can be used with log4j too.

[edit] External links

[edit] Ports

Cấu hình SVN

CẤU HÌNH SUBVERSION

Giới thiệu:

Subversion(viết tắt là SVN) là một hệ thống quản lí version (version control system(VCS)) được giới thiệu vào năm 2000 bởi công ty CollabNet. Đây là hệ thống hỗ trợ làm việc theo nhóm rất hiệu quả. Khi một nhóm làm việc cùng trên một project, việc nhiều người cùng chỉnh sửa nội dung của một file là điều không thể tránh khỏi. SVN cung cấp các chức năng để có thể thực hiện việc này một cách đơn giản và an toàn.

Về mặt khái quát, SVN giống như một hệ thống file server mà các client có thể download và upload file một cách bình thường. Điểm đặt biệt của SVN là nó lưu lại tất cả những gì thay đổi trên hệ thống file: file nào đã bị thay đổi lúc nào, thay đổi như thế nào, và ai đã thay đổi nó. SVN cũng cho phép recover lại những version cũ một cách chính xác. Các chức năng này giúp cho việc làm việc nhóm trở nên trơn tru và an toàn hơn rất nhiều.

Link download cho phiên bản chạy trên WINDOWS:

Subversion Client:

Dưới đây là một số các chương trình khách (CLIENT) hay giao diện người dùng có khả năng truy cập các máy chủ chạy Subversion.

  1. AnkhSVN là một phần mềm phụ, bổ sung khả năng truy cập Subversion cho môi trường lập trình Visual Studio .NET.

  2. eSvn, chương trình khách dựa trên thư viện Qt.

  3. Insurrection, giao diện Web cho Subversion.

  4. JSVN, chương trình khách viết bằng Java.

  5. kdesvn, chương trình khách cho KDE.

  6. psvn.el, giao diện Subversion cho Emacs.

  7. PushOk SVN SCC PlugIn là một phần mềm phụ, bổ sung khả năng truy cập Subversion cho môi trường lập trình Visual Studio .NET.

  8. RapidSVN, chương trình khác đa hệ điều hành dựa trên thư viện wxWidgets.

  9. SCPlugin, phần mềm phụ cho Macintosh Finder.

  10. SmartSVN là một chương trình khác đa hệ điều hành, có hai bản quyền: tự do và thương mại, được viết bằng Java.

  11. Subcommander, chương trình khách đa hệ điều hành dựa trên thư viện Qt

  12. svnX, chương trình khách cho Mac OS

  13. TortoiseSVN là một phần mềm bổ sung cho Explorer.

  14. TurtleSVN đi kèm với TortoiseSVN để hỗ trợ môi trường lập trình Visual Studio .NET.

  15. WebSVN, là một giao diện Web cho Subversion, viết bằng PHP

  16. WebClient for SVN là một chương trình khách mã nguồn mở viết bằng Java/JSP, thường được dùng cho các thao tác đơn giản.

  17. ZigVersion là một chương trình khác thương mại cho Mac OS X Subversion.

Link tham khảo” http://subversion.tigris.org/links.html

Hosted source control

In case you need to host your code online, mostly for open source projects, here are some providers you can try:

Notes:

  • Not all accept closed source projects.

  • Not all support binary releases.

  • Most offer more services than just source code hosting: forums, bug tracking, task management, project web site, etc.

Link tham khảo: http://weblogs.asp.net/fmarguerie/archive/2005/04/27/404793.aspx

CÀI ĐẶT, CẤU HÌNH SUBVERSION TRÊN WINDOWS

Cài APACHE.

Trong trường hợp này tôi cài

XAMPP: http://jaist.dl.sourceforge.net/sourceforge/xampp/xampp-win32-1.6.6a-installer.exe

vào ổ D:\xampp

Cấu trúc thư mục: D:\xampp\apache\conf\httpd.conf

D:\xampp\apache\modules\

Cài SUBVERSION: D:\Program Files\Subversion

Tạo thư mục etc: D:\Program Files\Subversion\etc

Copy các file:

  1. mod_dav.so

  2. mod_dav_svn.so

  3. mod_authz_svn.so

từ thư mục: D:\Program Files\Subversion\bin\

vào thư mục: D:\xampp\apache\modules\

(Trước khi chỉnh sửa file D:\xampp\apache\conf\httpd.conf, chúng ta sao lưu trước)

Mở file D:\xampp\apache\conf\httpd.conf bằng trình soạn thảo bất kỳ (Notepad++ chẳng hạn)

D:\xampp\apache\conf\httpd.conf

Thêm vào các dòng sau:

#@@SVN

<Directory />

Options FollowSymLinks

AllowOverride None

#Order deny,allow

#Deny from all

#@@SVN

Order Allow,Deny

Allow from all

#Allow from network (ví dụ 10.0.5 => tất cả các máy trong dải 10.0.5.x có thể #truy cập vào svn server

</Directory>

#@@SVN

<Directory “D:/xampp/htdocs“>

#

#

AllowOverride All

#

#

# Controls who can get stuff from this server.

#

Order allow,deny

Allow from all

#Allow from network (ví dụ 10.0.5 => tất cả các máy trong dải 10.0.5.x có thể #truy cập vào svn server

</Directory>

#@@SVN

Include “D:/Program Files/Subversion/etc/subversion.conf

Nội dung file: D:\Program Files\Subversion\etc\subversion.conf

#Edited by tinh_cx

#

LoadModule dav_module modules/mod_dav.so

LoadModule dav_svn_module modules/mod_dav_svn.so

LoadModule authz_svn_module modules/mod_authz_svn.so

#

#

#Temples cua 1 project nhu sau:

#Voi moi project, ta copy them nguyen doan text nay

######################BEGIN

#<Location /webapp1> ###trong do “/webapp1″ la ten bat ky user tu dat

<Location /webapp1>

DAV svn

#Duong dan tuyet doi chua project

SVNPath “E:/bkProject/WebProject/webapp1

AuthType Basic

AuthName “Subversion Project1 repository”

#File luu thong tin user/password da duoc ma hoa

AuthUserFile “D:/Program Files/Subversion/etc/svn-auth-file

Require valid-user

AuthzSVNAccessFile “D:/Program Files/Subversion/etc/svn-acl

</Location>

######################END

######################BEGIN

#<Location /webapp2> ###trong do “/webapp2″ la ten bat ky user tu dat

<Location /webapp2>

DAV svn

#Duong dan tuyet doi chua project

SVNPath “E:/bkProject/WebProject/webapp2

AuthType Basic

AuthName “Subversion Project1 repository”

#File luu thong tin user/password da duoc ma hoa

AuthUserFile “D:/Program Files/Subversion/etc/svn-auth-file

Require valid-user

AuthzSVNAccessFile “D:/Program Files/Subversion/etc/svn-acl

</Location>

######################END

Người dùng có thể truy cập đến thư mục:

E:/bkProject/WebProject/webapp1 qua URL:

http://<server name>:<port number>/webapp1 hoặc có thể vào trực tiếp

file:/// E:/bkProject/WebProject/webapp1 Apache server có thể đọc các thông tin về user/ password từ file:

D:/Program Files/Subversion/etc/svn-auth-file” , thông tin về quyền truy cập các project:

D:/Program Files/Subversion/etc/svn-acl”

File “D:/Program Files/Subversion/etc/svn-acl” định nghĩa các quyền có thể truy cập đến project1.

Nội dung file: D:\Program Files\Subversion\etc\svn-acl

#Edited by tinh_cx

# ACCESS CONTROL LIST (ACL)

#

# specify groups here

#

###################################### webapp1

[groups]

team1 = tinh_cx, backup

#

# team1 group has a read/write access to webapp1 repository

# all subdirectories

# all others have read access only

#

[webapp1:/]

@team1 = rw #(User nam trong team1 co the doc/ghi)

#* = r #(Tat ca cac user co quyen doc)

######################################

#

#
###################################### webapp2

# webapp2 repository, only harry and sally have read-write access to project2

#

[webapp2:/]

harry = rw

sally = rw

* = r

#

# ross is helping with the time zone part of the project2

#

[webapp2:/timezone]

harry = rw

sally = rw

ross = rw

* = r

######################################

Chú thích cho việc phân quyền ở webapp1:

Các nhóm làm việc có thể định nghĩa trong thẻ groups. Trong file nói trên, nội dung của webapp1 có thể được đọc và ghi bởi những người trong team1. Tât cả các user khác chỉ có quyền đọc

Tạo user:

htpasswd -[c]m “d:\Program Files\Subversion\etc\svn-auth-file” <username>

Mở cmd, chạy lệnh sau:

htpasswd -[c]m “d:\Program Files\Subversion\etc\svn-auth-file” tinh_cx

Chú thích:

htpasswd: File này nằm tại: D:\xampp\apache\bin\htpasswd.exe

Tham số: -[c]: C: Create (dùng khi file svn-auth-file chưa được tạo ra. Nếu đã tạo ra rồi, tham số này sẽ xoá file cũ đi, tạo file mới). Các user sau không cần tham số C. Chỉ thêm tham số M.

Tạo nơi lưu trữ Project:

(không phải thư mục muốn làm project)

C1: Dùng câu lệnh:

svnadmin create “E:\bkProject\WebProject\<project name>”

Mở cmd, chạy lệnh sau:

svnadmin create “E:\bkProject\WebProject\webapp1”

C2: Dùng giao diện:

Tại thư mục muốn lưu trữ project

Thư mục này sẽ được SUBVERSION “lưu các phiên bản” mỗi khi có sự thay đổi

Tạo workspace nơi chứa code thật sự:D:\workspace\WebProject\webapp1

(Thư mục webapp1 phải rỗng – không chứa bất kỳ file/thư mục khác)

Check out thành công:

Thư mục webapp1 sẽ được thêm thư mục ẩn: “.svn”

Không quan tâm thư mục ẩn này. Code của project sẽ được đặt trong thư mục webapp1

Mở Eclipse, chọn workspace nằm tại đường dẫn:

Mọi sự thay đổi trong thư mục webapp1 này sẽ được SVN Server “theo dõi”.

The end.

Minh hoạ cụ thể:

Học cách sử dụng Subversion qua TortoiseSVN:

TortoiseSVN là một chương trình phía client của Subversion system. Chương trình có thể download miễn phí:
http://jaist.dl.sourceforge.net/sourceforge/tortoisesvn/TortoiseSVN-1.4.8.12137-win32-svn-1.4.6.msi

Sau khi cài đặt xong, các bạn có thể dùng thử TortoiseSVN theo hướng dẫn dưới đây

Hướng dẫn sử dụng TortoiseSVN:

Đây chỉ là hướng dẫn để làm quen với khái niệm và các thao tác trên TortoiseSVN. Cách setup một SVN server thực sự và các chức năng cụ thể của TortoiseSVN xin tham khảo file help trong thư mục cài đặt. Để đơn giản, bài viết sẽ tạo cả server lẫn client trên cùng một máy tính.

1. Tạo thư mục Repository(thư mục để chứa các file trên server)
Tạo một thư mục tên bất kì tại nơi bạn muốn đặt server. Vi dụ: C:/SVN/MyRepository.

Click vào thư mục vừa tạo và click chuột phải, chọn TortoiseSVN→Create Repository.

Click OK ở bước tiếp theo

Repository đã được tạo xong. Ban không nên(và không được) tự mình chỉnh sửa những file trong đó.

2. Access vào Repository như một client

Tạo một thư mục bất kì và di chuyển vào đó(ví dụ C:\Client1)

Click chuột phải, chọn SVN Checkout…

Nhập URL repository trên server(trong trường hợp này là file:///C:/SVN/MyRepository), click OK.

Nếu check out thành công, bạn sẽ thấy trong thư mục xuất hiện thư mục .svn(thư mục ẩn) cùng tất cả các file có trên server (hiện tại trên server chưa có file nào nên chỉ có thư mục .svn xuất hiện). Bạn có thể chỉnh sửa cũng như tạo mới, xóa bớt các file trong đó.

3. Upload file lên server (commit)

Sau khi đã chỉnh sửa file, các bạn có thể commit những thay đổi lên server bằng cách click chuột phải, chọn SVN commit…, check những file cần commit, viết thêm ghi chú về thay đổi (nếu cần) vào phần log message rồi click ok. Ở bước này các bạn chú ý là chỉ nên commit những file chung cho project, những file chỉ sử dụng cho riêng mình (ví dụ các file test, backup…) các bạn không nên commit.

4. Xử lí khi bị conflict

Conflict xảy ra khi 2 client đồng thời thay đổi nội dung của của 1 file. Để hiểu rõ hơn về conflict, các bạn làm theo ví dụ sau:

Trong thư mục client1, check out, sau đó tạo file bất kì (ví dụ main.c).

Commit file main.c.

Edit file main.c, thêm vào dòng “I am client1”. Save file. (chưa commit)

Ra khỏi thư mục client1, tạo thư mục client2 (giả định đây là 1 client khác cùng tham gia 1 project với client1). Check out as client2.

Edit file main.c, thêm vào dòng “I am client2”. Commit file main.c

Trở lại thư mục client1. Commit file main.c. Bảng hiển thị lỗi sẽ hiện ra và bạn sẽ không thể commit lên server.

Cách khắc phục:

Trước tiên bạn phải update. Click chuột phải, chọn SVN update. File main.c của bạn sẽ được copy qua main.cpp.mine, còn file main.cpp sẽ có nội dung mà cả 2 client đã thay đổi. Xem file main.cpp để “đoán” xem chuyện gì đã xảy ra và chỉnh sửa lại. Hoặc bạn có thể dùng check modification tool(click chuột phải, chọn TortoiseSVN→Check for modification). Sau khi đã chỉnh sửa xong file main.cpp, bạn phải thông báo cho SVN rằng conflict đã được fix bằng cách click chuột phải, chọn TortoiseSVN→Resolved… Sau đó mới có thể commit được.

6 Free SVN & Project Hosting Services

Open Source seems to be exploding all over the place at the moment and with online services increasingly jumping on the free offerings its been fantastic for developers wanting to host, manage, flaunt and communicate their projects online. Here’s a rundown of 6 free SVN hosting and project management offerings I like the look of.

Unfuddle – Nice name and nice site. Very web 2.0 and slick with project tracking such as issue tickets, source control, time tracking, milestones, etc. The free package only comes with 15Mb and restrictive user allowances so not quite as generous as Assembla mentioned below but they have a shallower pricing curve so the first paid is $9/mo.

Assembla – Part of a large and feature-packed service full of project management features as well as basic 200Mb of SVN hosting. It even has a jobs board but the project hosting comes with wiki pages, blogs, etc. The free package has all of this so even if you don’t stump up the $49 p/m for the paid you’ll get one hell of a service.

OpenSVN – One of the first to release free SVN hosting of open source projects and starting to show its age with a very clunky interface and barebones features. So when I say “free SVN hosting” I really mean just that!

Bounty Source
– Still going strong after I first mentioned it back in June Bounty Source offer your basic SVN along with a wiki and CMS for managing your projects online presence as well as a task tracker. Bounty Source have a unique feature though that enables a developer to be paid for the work they carry out on user feature requests. Something I really like the look of – all I need now is an open source project people are going to pay me to finish!

SourceForge
– Like an old grandfather clock this has been around years and although very reliable its showing its age. They tried to spruce it up with some Web2.0 gradients and curves but you can’t scrub out the moldy smell from that interface and features-set.

Google Project Hosting
– They seem to have taken a lot of the old school methods of project hosting from SourceForge. Unfortunately as mentioned earlier they’re looking old and althoguh Google looks much cleaner its features still lack the richness that the smaller providers have who’ve gone all out on innovation while Google remains formulaic.

SUN: Asia South Training Locations

Vietnam Training Centers
Corporate Program
Ho Chi Minh City
Saigon Institute for Techniques and Technology
DTS Building
287B Dien Bien Phu Street , District 3,
Ho Chi Minh City, VietNam

Tel : (84) 8 933 8888
Fax : (84) 8 932 1186
URL: www.saigonctt.com.vn
<!–Email: phuongck@saigonctt.com.vn
–>

Hanoi
Alliant Joint Stock Company
Room 401, Hanoi IT Transaction Centre
185 Giang Vo street, Dong Da dist.,
Hanoi
Vietnam

Tel: (84) 4 512 1918
Fax: (84) 4 512 1917
URL: www.alliant-corp.com
Email: contact@alliant-corp-com

New Horizons Computer Learning Centers of Hanoi
80 Trieu Viet Vuong, Hanoi
Vietnam

Tel : (84) 4 9437300
Fax : (84) 4 9437298
URL: www.newhorizons.com
Email: info.hanoi@newhorizons.com

Saigon Institute for Techniques and Technology
Room 1103, 11th Floor, HITTC
185 Giang Vo Street, Dong Da District,
Ha Noi City, VietNam

Tel : (84) 4 5121942 / 5121943
Fax : (84) 4 5121929
URL: www.saigonctt.com.vn

SUN(Vietnam): Enjoy 15% Discount for Java Courses & 10% Discount for Sun Certifications

https://www.suntrainingcatalogue.com/eduserv/client/cmsearch.do?meId=4&l=en_VN&cid=e4826

Product ID/Course code
Course
Price excl. VAT (USD)
CX-310-019 Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0 (CX-310-019) 100.00
CX-310-090 Sun Certified Business Component Developer for the Java Platform, Enterprise Edition 1.3 (CX-310-090) 150.00
CX-310-091 Sun Certified Business Component Developer for the Java Platform, Enterprise Edition 5 (CX-310-091) 150.00
CX-310-220 Sun Certified Developer for Java Web Services (CX-310-220) 150.00
CX-310-252A Sun Certified Developer for the Java Platform, Standard Edition: Assignment (Step 1 of 2) (CX-310-252A) 250.00
CX-310-252R Sun Certified Developer for the Java Platform, Standard Edition: Assignment Resubmission (CX-310-252R) 125.00
CX-310-027 Sun Certified Developer for the Java Platform, Standard Edition: Essay (Step 2 of 2) (CX-310-027) 150.00
CX-310-051 Sun Certified Enterprise Architect for J2EE Technology (Step 1 of 3) (CX-310-051) 150.00
CX-310-300A Sun Certified Enterprise Architect for J2EE Technology (Step 2 of 3) (CX-310-300A) 250.00
CX-310-061 Sun Certified Enterprise Architect for J2EE Technology (Step 3 of 3) (CX-310-061) 150.00
CX-310-300R Sun Certified Enterprise Architect for J2EE Technology: Assignment Resubmission (CX-310-300R) 150.00
CX-310-301A Sun Certified Enterprise Architect for the Java EE 5: Assignment (Step 2 of 3) (CX-310-301A) On request
CX-310-301R Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5 (Assignment Resubmission) (CX-310-301R) On request
CX-310-052 Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5 (Step 1 of 3) (CX-310-052) On request
CX-310-062 Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5: Essay (Step 3 of 3) (CX-310-062) On request
CX-310-502 Sun Certified Java CAPS Integrator (CX-310-502) 150.00
CX-310-110 Sun Certified Mobile Application Developer for the Java Platform, Micro Edition, Version 1.0 (CX-310-110) 150.00
CX-310-302 Sun Certified Network Administrator for Solaris 10 OS (CX-310-302) 150.00
CX-310-043 Sun Certified Network Administrator for the Solaris 8 Operating System (CX-310-043) On request
CX-310-044 Sun Certified Network Administrator for the Solaris 9 Operating System (CX-310-044) 150.00
CX-310-025 Sun Certified Programmer for Java 2 Platform 1.2 (CX-310-025) On request
CX-310-035 Sun Certified Programmer for the Java Platform, Standard Edition 1.4 (CX-310-035) 150.00
CX-310-055 Sun Certified Programmer for the Java Platform, Standard Edition 5.0 (CX-310-055) 150.00
CX-310-065 Sun Certified Programmer for the Java Platform, Standard Edition 6 (CX-310-065) On request
CX-310-303 Sun Certified Security Administrator for Solaris 10 OS (CX-310-303) 150.00
CX-310-301 Sun Certified Security Administrator for the Solaris 9 Operating System (CX-310-301) 150.00
CX-310-345 Sun Certified System Administrator for Sun Cluster 3.2 Software (CX-310-345) 150.00
CX-310-203 Sun Certified System Administrator for the Solaris 10 Operating System Upgrade Exam (CX-310-203) 150.00
CX-310-200 Sun Certified System Administrator for the Solaris 10 OS, Part I (CX-310-200) 150.00
CX-310-202 Sun Certified System Administrator for the Solaris 10 OS, Part II (CX-310-202) 150.00
CX-310-013 Sun Certified System Administrator for the Solaris 8 Operating System Upgrade Exam (CX-310-013) On request
CX-310-011 Sun Certified System Administrator for the Solaris 8 Operating System, Part I of II (CX-310-011) On request
CX-310-012 Sun Certified System Administrator for the Solaris 8 Operating System, Part II of II (CX-310-012) On request
CX-310-016 Sun Certified System Administrator for the Solaris 9 Operating System Upgrade Exam (CX-310-016) 100.00
CX-310-014 Sun Certified System Administrator for the Solaris 9 Operating System, Part I of II (CX-310-014) On request
CX-310-015 Sun Certified System Administrator for the Solaris 9 Operating System, Part II of II (CX-310-015) 150.00
CX-310-081 Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 1.4 (CX-310-081) 150.00
CX-310-083 Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 5 (CX-310-083) On request
CX-310-092 Upgrade Exam: Sun Certified Business Component Developer for the Java Platform, Enterprise Edition 5 (CX-310-092) On request
CX-310-053 Upgrade Exam: Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5 (CX-310-053) On request
CX-310-036 Upgrade Exam: Sun Certified Programmer for the Java Platform, Standard Edition 1.4 (CX-310-036) 100.00
CX-310-056 Upgrade Exam: Sun Certified Programmer for the Java Platform, Standard Edition 5.0 (CX-310-056) 100.00
CX-310-066 Upgrade Exam: Sun Certified Programmer for the Java Platform, Standard Edition 6 (CX-310-066) On request
CX-310-082 Upgrade Exam: Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 1.4 (CX-310-082) 100.00
CX-310-084 Upgrade Exam: Sun Certified Web Component Developer for the Java Platform, Enterprise Edition 5 (CX-310-084) On request

Java Programming – IReports & JasperReports: Data Source: VECTOR

You would have to implement a custom data source and potentially a datasource provider, depending on if you would be filling the report programaticially or through the iReports GUI. Just be forewarned.. iReports has known bugs with custom data sources, it may be better to fill the Report programaticially. Alternatively, you can use JasperAssistant to design your reports.

If you had a vector then each element in the vector would be 1 iteration of the detail band in the report, and then you would have to access the “Fields” of the element returned from the vector in your custom data source. So if you had a vector of “Students” (name, student_num as simple fields) the data source would be (a very simple example)…

import java.util.Vector;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;


public class TestDataSource implements JRDataSource {
private int m_nIdx;
private Vector<Student> v;

public TestDataSource() {
this (new Vector<Student>());
}

public TestDataSource(Vector<Student> v) {
m_nIdx = -1;
this.v = v;
}

public Object getFieldValue(JRField field) throws JRException {
Object o = null;

String sName = field.getName();

Student currStudent = v.elementAt(m_nIdx);

if (currStudent == null)
return null;

if (sName.equals("student_name"))
o = currStudent.getStudentName();
else if (sName.equals("student_number"))
o = currStudent.getStudentNum();

return o;
}

public boolean next() throws JRException {
m_nIdx++;
return (m_nIdx < v.size());
}
}

You can use a Data source provider to describe to iReports what fields are available in your data source.

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRDataSourceProvider;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.JRField;


public class TestDataSourceProvider implements JRDataSourceProvider {

public TestDataSourceProvider() {

}

public JRDataSource create(JasperReport report) throws JRException {
TestDataSource ds = new TestDataSource(/**ADD_VECTOR_HERE_SOMEHOW*/);

return ds;
}

public void dispose(JRDataSource dataSource) throws JRException {
// nothing to dispose
}

public JRField[] getFields(JasperReport arg0) throws JRException, UnsupportedOperationException {
JRField[] fields = new JRField[2];
fields[0] = new JRBasicField("Student Name", "student_name", java.lang.String.class, "java.lang.String");
fields[1] = new JRBasicField("Student Number", "student_number", java.lang.String.class, "java.lang.String");

return fields;
}

public boolean supportsGetFieldsOperation() {
// TODO Auto-generated method stub
return true;

}
}

Based on the provider class above, we can see that your report would have 2 fields, $F{student_name} and $F{student_num}

Link tham khảo: http://209.85.175.104/search?q=cache:FCa_c_L7KV8J:forum.java.sun.com/thread.jspa%3FmessageID%3D4438695%26tstart%3D0+how+to+generate+jasperreports+by+passing+a+vector&hl=vi&ct=clnk&cd=1&gl=vn&client=firefox-a

JasperReports For Java Developers

jasper_image3.gif

Elements of a JRXML Report Template
<property>
<import>
<reportFont>
<parameter>
<queryString>
<field>
<variable>
<group>
<background>
<title>
<pageHeader>
<columnHeader>
<detail>
<columnFooter>
<pageFooter>
<lastPageFooter>