Migrate Eclipse 3.2 to 3.3.1

java No Comments »

I migrated Eclipse 3.2 to 3.3.1, at first I used the same workspace and I had some problems with myln plugins and the server did not start correctly. Then i tried with a new workspace and everything was smooth except at server startup:

Timeout waiting for Tomcat v5.5 Server at localhost to start. Server did not start after 45s.

You need to set server timeout delay = Unlimited from Window>Preferences>Server…

SVN Merge Branch into Trunk using Eclipse

java No Comments »

I needed to merge the branch changes into trunk of the project, after many changes at both the branch and trunk…

First we have to commit all changes, in case of some failure at the merge operation we may revert all changes.

Select Team > Merge from menu, select the path of the branch and the revision. Revision number is selected from the Show Log, and is number when we created the branch.

svn_merge

Some useful links for SVN merge:

Eclipse SDK - Subversion Eclipse Plugin Manual

SVN Book

Code Analysis - Finding Duplicate Code

java No Comments »

I tried Maven plugins for code analysis and finding duplicate/similar code.

CPD-PMD’s Copy/Paste Detector can be used for finding duplicate code, which is included in PMD, a Java code analysis tool.
run mvn pmd:cpd ,
The report is displayed at cpd.html file, and the results are very efficient.

Simian - Similarity Analyser is also an alternative for finding duplicates.

Code Analysis using PMD and Checkstyle

java No Comments »

We started code review using Crucible, so i searched for some code analysis maven plugins. PMD is a Java code analysis tool and used to find potential problems like unused code, duplicate code, unused variables… PMD is useful and easy:

pom.xml:

    <reporting>
        <outputDirectory>target/reporting/pmd</outputDirectory>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-pmd-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>

If you get the following error, simply add target-jdk configuration:
Caused by: net.sourceforge.pmd.ast.ParseException: Can’t use generics unless running in JDK 1.5 mode!

    <reporting>
        <outputDirectory>target/reporting/pmd</outputDirectory>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-pmd-plugin</artifactId>
              <configuration>
                  <targetJdk>1.5</targetJdk>
              </configuration>
            </plugin>
        </plugins>
    </reporting>

The PMD report is at pmd.html, but i couldn’t find categories, and more detailed reports.

We can also customize PMD rules & rulesets:

How to write a PMD rule?
How to make a new rule set?

CheckStyle is also a strong Maven 2 plugin for java code analysis. Simply running mvn checkstyle:checkstyle gives us detailed html/rss report(mvn site gives heap or memory error for some projects).

    <reporting>
    ……
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>

We can customize the reports generated by Maven’s site plugin. Simply add or overwrite <reports> tag at project.xml. The result gives us reports of project like dependencies, project info, project reports (CMD and PMD reports included), source repository, …

<reports>
    <report>index</report>
    <report>dependencies</report>
    <report>project-team</report>
    <report>mailing-list</report>
    <report>cim</report>
    <report>issue-tracking</report>
    <report>license</report>
    <report>scm</report>
    <report>maven-pmd-plugin</report>
    <report>maven-checkstyle-plugin</report>
</reports>

Format and Color Code Snippets For Blog

java No Comments »

I need formatting java code snippets at my blogs so i use an eclipse plugin, simply you can copy html code to editor.

java2html Eclipse Plugin

I think the most practical way to format html and xml code snippets is using:
http://www.manoli.net/csharpformat

Thanks to Truong Hong Thi for sharing :)

Edit: I also found a brilliant wordpress plugin for formatting source code.
SyntaxHighlighter

Easy to use, just add source language=’java’ tag :)


public class FileComponent implements Serializable{
private String fileName;
private String contentType;
private int size;
private String localPath;

public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
}

}

maven 2.0.7 filtering

java No Comments »

I upgraded maven 2.0.4 to 2.0.7 and the i couldn’t compile the existing projects because of filtering problem - filtering files couldn’t be read, the source of problem was maven-assembly-plugin. I think such kind of incongruities generally may occur. The simplest solution of such problems is simply renaming the maven folder …\.m2\repository\org\apache\ and installing the project again for full download of all maven and maven plugins :)

The details of the problem and the solution is below:

http://jira.codehaus.org/browse/MASSEMBLY-178

Tomcat - VerifyError Fix

java No Comments »

Using Tomcat 5.5.17 after starting application, jsp pages couldn’t be rendered and the following error is taken with an empty page. To fix the problem simply check the commons-el.jar versions and also remove geronimo-spec-jsp.jar from WEB-INF\lib directory if this jar is not already excluded:

java.lang.VerifyError: (class: org/apache/jasper/runtime/PageContextImpl, method: getExpressionEvaluator signature: ()Ljavax/servlet/jsp/el/ExpressionEvaluator;) Wrong return type in function
at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:99)
at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:61)
at org.apache.jsp.pages.P60.Common.StandardPageParentTemplate_jsp._jspService(StandardPageParentTemplate_jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Adsız Kent

personal No Comments »

Sonsuza dek yatan sanma ölüdür,
Tuhaf çağlarda ölüm de ölür.

Korku Öyküleri Antolojisi - Karanlıkta 33 Yazar kitabında en beğendiğim öykülerden biri Adsız Kent, ve yazarı H.P. Lovecraft‘in diğer kitapları ve öykülerini okumak için sabırsızlanıyorum :)

Creating Dynamic JSF Components

jsf No Comments »

Creating Dynamic Components at JSF is really easy but because of performance problems and the large number of components to generate i choose different way at project. A simple sample:

Use datagrid/datatable object to add your components:

<h:panelgrid id=”grid1″ styleclass=”panelGrid” columns=”2></h:panelgrid> <hx:commandexbutton id=”newComponentBtn”

action=”#{pc_DynaComponentView.addNewComponent}” styleclass=”commandExButton”

type=”submit” value=”New Component”>

</hx:commandexbutton>

Sample JSF:

<h:form id=”form1″ styleclass=”form”> <h:panelgrid id=”grid1″ styleclass=”panelGrid” columns=”2″></h:panelgrid>

<hx:commandexbutton id=”newComponentBtn”

action=”#{pc_DynaComponentView.addNewComponent}” styleclass=”commandExButton”

type=”submit” value=”New Component”></hx:commandexbutton>

<h:panelgrid id=”grid1″ styleclass=”panelGrid” columns=”2″></h:panelgrid>

<hx:commandexbutton id=”newComponentBtn”

action=”#{pc_PageView.addNewComponent}” styleclass=”commandExButton”

type=”submit” value=”New Component”></hx:commandexbutton>

</h:form>

Sample Code at Backing Bean:


public void addNewComponent() {
// create sample components
HtmlSelectOneListbox listbox = new HtmlSelectOneListbox();
HtmlInputText text1 = new HtmlInputText();
text1.setValue("TEST");
List valueList = new ArrayList();
SelectItem selectItem = new SelectItem("TEST1", "TEST1");
valueList.add(selectItem);
selectItem = new SelectItem("TEST2", "TEST2");
valueList.add(selectItem);
UISelectItems items = new UISelectItems();
items.setValue(valueList);
listbox.getChildren().add(items);
grid1 = getGrid1();
// Add components
grid1.getChildren().add(listbox);
grid1.getChildren().add(text1);
}

JSF Custom Messages

jsf No Comments »

..\IBM\Rational\SDP\6.0\rwd\eclipse\plugins\com.ibm.etools.jsf.
runtime.ri_6.0.0\runtime\jsf-impl.jar added to project lib.

com.xxx.model.data.messages.messages.properties edited.

faces-config.xml :

<application>
<variable-resolver>com.ibm.faces.databind.SelectItemsVarResolver</variable-resolver>
<property-resolver>com.ibm.faces.databind.SelectItemsPropResolver</property-resolver>
<locale-config>
<default-locale>tr</default-locale>
</locale-config>
<message-bundle>com.hbtr.model.data.messages.messages</message-bundle>
</application>