JAVAMARCO

JAVA, J2EE AND MORE

Eclipse is running in a JRE, but a JDK is required

I have installed maven and everytime eclipse starts in the console appears this error.
To solve it just launch eclipse using the -vm parameter, for example:

/opt/eclipse/eclipse -vm /usr/lib/jvm/java-1.5.0-sun-1.5.0.19/bin

October 2, 2009 Posted by javamarco | eclipse, maven | , , , , | No Comments Yet

Liferay, Theme and Velocity variables

Here you have a table of the output of some Velocity variables used in Liferay, I’ve used the portal_normal.vm to print the value.

  • $portalUtil.getHost($request) –> localhost
  • $request.getClass().getName() –>com.liferay.portal.kernel.servlet.ProtectedServletRequest
  • $themeDisplay.getPathThemeRoot() –> /nameoftheme/
  • $full_templates_path –> volkswagenexpeience-theme_SERVLET_CONTEXT_/templates

Some interesting links:
Themes at Liferay

I will update this post as soon as possible because now I can’t finish it.

April 14, 2009 Posted by javamarco | Liferay, Snippets, Velocity | , , | 1 Comment

jsp:include vs jsp include directive

In JSP technology you can include another page in two modes: using jsp:include tag:

<jsp:include page=”dir/file.jsp” flush=”true”/>

Or with the include file directive:

<%@ include file=”dir/file.jsp” %>

What’s the difference?

In the first case the page is called and compiled at run-time and in the second case is called and compiled at compiled-time.

I notice that a jsp file is re-compiled everytime it changes.

For example if you are using the inlcude directive and you modify the included page you still see the same previously compiled result. You need to recompile the father jsp in order to recompile the child jsp. In this case you need to change (or touch) the both.

Using the jsp:include it is not necessary because everytime the both jsp are re-compiled.

You say: “Ok, but I’m sure I’ll not change the included/child jsp”.

Perfect! Change the param flush to false.

Here you can find moreĀ jsp directives.

April 2, 2009 Posted by javamarco | JSP | , , , | No Comments Yet

Object Cast 1: from String to int

In Java to cast from String to int you can use three lines of code:

String numberString = “27″;

Integer numberInteger = new Integer(numberString);

int nimberInt = numberInteger.intValue();

or just one line:

int nimberInt = new Integer(“27″).intValue();

January 11, 2009 Posted by javamarco | Snippets, String | , , , , , | No Comments Yet

java.util.Enumeration vs java.util.Iterator

The next example print, using the standard output, all the java.lang.String Object included in a java.util.Map using a java.util.Iterator

Iterator oIterator = oMap.values().iterator();
while(oIterator.hasNext()){
String[] theParam = (String[])oIterator.next();
String theValue = (String)oMap.get(theParam[0]);
System.out.println("\n= param: " + theParam[0] + " --> " + theValue);
}

The next one use the java.util.Enumeration to print a java.util.Hashtable

if(!oHashtable.isEmpty()){
Enumeration oEnumeration = oHashtable.keys();
while(oEnumeration.hasMoreElements()){
String theParam = (String)oEnumeration.nextElement();
String theValue = oHashtable.get(theParam);
System.out.println("\n=param: " + theParam + "=" + theValue);
}
}

Notice that it needs an if to check the status of the Hashtable because the method .keys() can throw a java.lang.NullPointerException.

September 12, 2008 Posted by javamarco | Snippets | , | No Comments Yet

Java String Capitalize

When I was looking for first time the method to capitalize a Java String, I was searching in the Sun Official API but… there isn’t.

Strange not?

No problem this is the code to capitalize a Java String:

String mystring = (mystring.substring(0, 1).toUpperCase() + mystring.substring(1).toLowerCase()).trim();

You can also download it from Javamarco google code repository

September 8, 2008 Posted by javamarco | Snippets | , , | 2 Comments

Another blog… another begin…

Hi all, I decided to open this blog because I need a centralized repository where put my java code.

Yes, I know that a blog is not a repository for java developers but is a good media to transmit the know-how to the others programmers.

LET’S GO JAVA CODE!!!

September 7, 2008 Posted by javamarco | NEWS | | No Comments Yet