Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Sunday, February 28, 2010

Khmer Unicode with Ireport 3.7.1 works fine with Kh fonts

Just quick configuration with Ireport 3.7.1 without detail here:
  1. Download ireport from http://jasperforge.org 3.7.1
  2. Install ireport 3.7.1
  3. Open ireport design
  4. Use blank design
  5. Go to ireport tool configuration: Tool --> Options --> Fonts and click install fonts
I install two fonts: Khmer OS System and Kh System

First tested with Khmer OS System font, found it's not display correctly, see screen shot:

Now I use font: Kh System, it displays correctly:
Printed the report into PDF format also work for me.

To configure, I just change the font name to JasperReports Properties (find in Options menu):

In my local PC, I have already installed the font (Kh System) so please consider to add also if above configuration not yet work for you.

As I'm not using iReport, just wanna to test with Khmer Unicode only.

Thanks for comment any idea to improve it.

Tested Package download here.

Monday, January 25, 2010

JBoss 4.2.2.GA - Deploying issue on class loading and out of memory

While deploying my applications with JBoss 4.2.2.GA, using JDK 1.5 I got some issue with class loading issue something like:

1. If meet such error:
org.jboss.deployment.DeploymentException: Error while fixing table name; - nested throwable: (org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver)); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: Failed to register driver for: oracle.jdbc.driver.OracleDriver; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: oracle.jdbc.driver.OracleDriver))))


For sure, missing Oracle JDBC driver so Copy the Oracle JDBC Driver (10.2.0.1.0) (ojdbc14.jar) to lib folder of %JBOSS_HOME%/lib or at your server %JBOSS_HOME%/server/default/lib directory.

2. If something around:

2010-01-25 15:03:27,113 DEBUG [org.jboss.web.tomcat.service.TomcatDeployer] Classes needed for clustered webapp unavailable
java.lang.NoClassDefFoundError: org/jgroups/blocks/MethodCall
at org.jboss.web.tomcat.service.session.JBossCacheService.(JBossCacheService.java:70)
at org.jboss.web.tomcat.service.session.JBossCacheManager.init(JBossCacheManager.java:157)
at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:336)

So please try as following:
  • Define a isolated classloader. To do it, change %JBOSS_HOME%/server/default/conf/jboss-service.xml :
<mbean code="org.jboss.naming.NamingService" name="jboss:service=Naming" dd="resource:xmdesc/NamingService-xmbean.xml">
[ ... ]
<attribute name="CallByValue">true</attribute>
[ ... ]
</mbean>

  • change %JBOSS_HOME%/server/default/deploy/ear-deployer.xml :
<server>
[...]
<attribute name="Isolated">true</attribute>
[...]
<attribute name="CallByValue">true</attribute>
[...]
</server>

  • change %JBOSS_HOME%/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml :
[...]
<attribute name="Java2ClassLoadingCompliance">true</attribute>
[...]
<attribute name="UseJBossWebLoader">true</attribute>
[...]


3. When you wanna to deploy more than 2 applications on the same JBoss server instance, you may face some issues with unsuccessful deployment and with some error around Out of Memory.
So we need to increase memory allocation for Jboss, let's try to add/change JAVA_OPTS for memory allocation in file %JBOSS_HOME%/bin/run.bat as
set JAVA_OPTS=%JAVA_OPTS% -Xms512m -Xmx1024m -XX:MaxPermSize=128m

My applications are now deployed.

Sunday, October 4, 2009

At BarCamp 2009, topic: The State of The Art of Web Development

Hi,
Here is my presentation at barcamp phnom penh 2009, on Sunday 4th of October at Pannasastra University (Norodom), in hall room, Room Phnom Tamao at 11:30am to 12:30pm.

It was about the state of the art of web development, wanna to express how web technologies going on since it was started and today; also a bit view on how the future is.

The presentation, it's just starting or a beginning of the topic. Among those points, parts related to technologies of Java/J2EE, Django/Ruby on Rails, PHP style coding need to improve in the presentation, hope to do it more in next part.

Enjoy here:

Thursday, October 1, 2009

Run maven commands in Eclipse as External Tool

You might already know what is maven; it's a tool to build / compile or package java project...
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
Here, I want to show how to configure maven to use as external tool in eclipse IDE so easy for you to execute maven commands from the Eclipse interface easy without needing to open a DOS prompt to use. Here is the procedure:

1. Suppose maven 2 already install some where on your PC, (mine is in D:\Work\install\Tools\maven-2.0.4)
2. From the menu bar, select Window > Preferences. Select the Run/Debug > String Substitution. Add a new variable e.g. maven_exec.
3. Set up a new external launcher from the menu bar, select Run > External Tools. Select Program
4. Create each maven task, example: in here, I create only the build classpath
  • On program, create a new program and name as: build_classpath (any name as you wish)
  • In location box: choose our created variable: maven_exec
  • In Working Directory: choose variable: project_loc
  • In Argument, give maven command, in here is: eclipse:clean eclipse:eclipse
  • Click on Apply and Run if you wish now
5. So you can execute the external tool program by execute Run button, result should be in console tab:

Enjoy,

Friday, September 25, 2009

Jibx XML loading & Digester, which one is more flexible?

Jibx is one of the popular XML parsing in Java and also Digester.

Jibx bases on binding.xml file to map XML nodes to Java Objects
Digester also base on digester-rule xml file to map to Java Objects

What I found here, in Jibx we need to map all fields of the XML to the binding but in digester, we can filter for which fields we want...

To prove, will see in next post for more analyze..

Friday, August 28, 2009

In brief about Eclipse IDE

Eclipse is a multi-language software development environment comprising an IDE and a plug-in system to extend it. It is written primarily in Java and can be used to develop applications in Java and, by means of the various plug-ins, in other languages as well, including C, C++, COBOL, Python, Perl, PHP, and others.[1]

Website: http://www.eclipse.org/

Download: http://www.eclipse.org/downloads/

Current version: Galileo, 3.5: http://wiki.eclipse.org/Galileo

Eclipse IDE is suitable with:

- J2EE Development (To use Eclipse IDE for Java EE Developers)

- Java Development (To use Eclipse IDE for Java Developer)

- PHP Development (To use Eclipse IDE for PHP Development)

- C/C++ Development (To use Eclipse IDE for C/C++ Development)

- Etc.

Installation/To start:

- Jdk requires to install before install Eclipse, in new version of Eclipse 3.5 requires at least jdk 1.5

- Just extract the eclipse and copy to some where in your PC

- Point to your workspace, create project and develop your application as well.

Screenshot: (Other screens see: http://www.eclipse.org/screenshots/)

Easy ways/Shortcuts:

- Wanna to go every where can start with shortcut: Ctrl + 3

- To see all shortcut: Ctrl + Shift + L

- Rename on variable/method to change all reference: Alt + Shift + R

- Search any file: Ctrl + Shift + R

- Go to line number: Ctrl + L

- Create View Object (set / get methods): Alt + Shift + S and choose: Generate Getters and Setters

- Etc.



[1] See wiki: http://en.wikipedia.org/wiki/Eclipse_(software)

Monday, December 22, 2008

Write a string to the specific line or position in the written file in java

I got doubt on this point almost 2 hours to seek how can I write a string to a file at the position, I want.

Let me try to explain my issue that would help others who will have the same:
I extracted the data from database and write it to a file, I have so many queries for one group of lines, the layout of the file is:


1 line header
many lines detail


On the header, it's the summary of all lines in detail, it's in one query and I need to write first line of the header and a group of lines for detail to prevent OutOfMemory Exception at run time (As my file can have data around 1000 MB or much more than this).
One day, I got a request on my dev to modify a rule at the header that i need to count all lines of detail and put in in the header line in one position (position 27),
1. I don't want to execute count all queries of detail to find the record as we can count it when each query extract data so that we can reduce some cost of performance issue.
2. And we should not keep all lines of detail in StringBuffer or String or in list or map and after finish iterate them to write into file from header and then the details (this way we can count the record lines till queries of detail finished and then add it to header as normal), this solution for sure, we will meet OutOfMemory Exception for hug amount of data.
3. So the only solution to write the lines of header and details as normal but try to integrate the record count value to the header line in written file which should not rewrite the new file by read from the written file (performance issue!)..

With solution 3/ above, I got the way with RandomAccessFile functionality: Seeking the byte position of records and after the position integrate the value we prefer.
As my file is fixed length file, and the field to add is at position 27 so the end position of it is 26, here is example:

file.txt: 1 line header and 12 lines of detail:
000000000005400000221020080 98136
...

I need to add value: 12 to the position 27, here is the code:


/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
RandomAccessFile reReadWriteFile = null;
try {
reReadWriteFile =
new RandomAccessFile("file.txt", "rw");
} catch (FileNotFoundException e) {
System.out.println("Error: " + e.getMessage());
throw e;
}

try {
// To search on 26 bytes of field total detail lines
// at header line
reReadWriteFile.seek(26);
reReadWriteFile.writeBytes("12");
reReadWriteFile.close();
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
throw e;
}
}


After execute, file.txt: will be

0000000000054000002210200812 98136
...

Hope it helps you!
Metrey,

Learning Tip: API of RandomAccessFile

Thursday, November 13, 2008

Software Development and Logging

Beside understanding programming language and programming model etc. We must know how to manage the message from the development for user, for developer etc. We called logging.

To manage log, we have many ways according to programming language and platform.

Normally, most of the developers neglect on logging during development parse and starting to expect the log files when an issue happens. That's why log management becomes very important for software development that we need to spend time to manage it as much as possible during development parse.

Log Management proceed into 4 levels:
1. Debug : this is a developer logging level. Should use it for any technical test or technical information that not requires to understand the business process.
2. Info : This is user logging level. Use it to describe the business process or information.
3. Warning: This log level is to focus on not mandatory missing element.
4. Error : Use this log level in case of technical or functional error.

There are many tools or add-on tool to help handling for various log management: (but I would suppose for open source project one, Apache)
- log4j : For Java
- log4Net : For MS DotNet
- log4PHP : For PHP
- log4plsql : For PL/SQL or SQLPlus of Oracle