Monday, December 28, 2009

How to change port number in JBoss App Server

1. Open the JBoss Folder

2. Goto its Deploy folder.

3. Goto the jbossweb-tomcat55.sar

4. Find out the server.xml inside that folder. Actually this is the server configure file of the BuildIn Tomcat.

5. Find the folowing Tag

6. Change the port number here.

7. Restart the server.



Source: http://minddiary.com/2008/02/15/how-to-change-post-number-in-jboss-app-server/

Saturday, November 21, 2009

koala chrome

Chrome for Ubuntu linux (works on karmic koala) : http://www.ubuntugeek.com/install-chromium-google-chrome-web-browser-in-ubuntu.html

Sunday, November 15, 2009

How to install adobe flash player 64-bit after upgrading to Ubuntu 9.10 Karmic Koala

You'll need this because of certain glitches occuring when using ff to watch flash-based sites (such as Youtube). Just check out the link: http://news.softpedia.com/news/How-to-Install-Adobe-Flash-Player-64-bit-on-Ubuntu-8-10-98076.shtml
 

Saturday, November 14, 2009

Fixing Eclipse in Ubuntu 9.10 Karmic Koala

The fix is relatively simple. Create a file in your home folder (or wherever you want) called eclipsefix.sh – open it and add the following lines:


export GDK_NATIVE_WINDOWS=true
/opt/eclipse/eclipse

(where /opt/eclipse/eclipse is the location of your eclipse application file).


SOURCE: http://mou.me.uk/2009/10/31/fixing-eclipse-in-ubuntu-9-10-karmic-koala/

Friday, October 30, 2009

Fix Nvidia card resolution problem in Ubuntu (works in 9.10 too)

Sometimes the nvidia x server fails to recognize all the resolution combinations. This is how you fix it: 

Add Option "ModeValidation" "AllowNon60HzDFPModes, NoVertRefreshCheck, NoEdidMaxPClkCheck, NoHorizSyncCheck"

Under device section in the xorg.conf in /etc/X11/xorg.conf

Source: http://ubuntuforums.org/showthread.php?t=444960

Tuesday, October 20, 2009

JSTL taglib declaration reminder

Watch out for what specific JSTL version you're taglib-ing in your JSP's
If you put <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> and perform a basic <c:forEach> (you know... with attributes "var" for indexing and "items" for specifying the collection to loop) you might get a dumb error like this:

org.apache.jasper.JasperException: /index.jsp(65,0) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1174)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:821)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1736)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:183)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
WTF ? you can't do a <c:forEach> without an "items" ... I've googled around and found out that you must include an updated JSTL version in your taglib i.e. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> for it to work. Reason for this error is version incompatibility between JSP, Servlet and JSTL. Matching versions are listed below.
  • JSP 1.2 , Servlet 2.3 , JSTL 1.0
  • JSP 2.0 , Servlet 2.4 , JSTL 1.1

"Un taran la Bucuresti tot taran cauta" - Marin Preda

Sunday, October 18, 2009

Groovy & Grails for Java

Some cool and easy tutorials of Groovy and Grails written in Eclipse IDE
Groovy tutorial: http://www.vogella.de/articles/Groovy/article.html
Grails tutorial: http://www.vogella.de/articles/Grails/article.html

have fun

Friday, October 9, 2009

Disable Your PC Speaker in Ubuntu

You know that annoying, shrill beep that comes not from your speakers, but rather inside the depths of your computer called a system beep? I hate it, but Ubuntu likes to use it when, for example, I'm searching for text in Firefox and I get to the point where the text doesn't match anything. In Windows, this invokes a fairly annoying noise. In Ubuntu, it's the system beep, which is even worse. Here's how to disable it:

Stop it for now by doing the following:

sudo modprobe -r pcspkr

Stop it forever by blacklisting the module.  Edit /etc/modprobe.d/blacklist and add this line:

blacklist pcspkr


That's it



Thursday, October 8, 2009

Ubuntu screen resolution problem

It happens from time to time that ubuntu doesn't recognize multiple screen resolutions in my Nvidia x server settings so i'm stuck with 1024x768 (excuuuse me for wanting more from my Nvidia 9800 card). This problem suddenly appears and disappears randomly after a certain number of reboots. A solution i found is to use the following command and then reboot (you will have to reconfigure the Nvidia x server again using "sudo nvidia-xconfig"
sudo dpkg-reconfigure xserver-xorg


Tuesday, September 1, 2009

[Java] Mixing Generic with Legacy Code

This is kinda weird and troublesome. Even though as of Java 5 introduced generics to create type-safe collections, mixing this new kind of code with older non-generic one can be very tricky. Sun obviously did not want to make pre-Java 5 code redundant so it created a few ways to make these two types of code play nicely. For example:
List<String> l = new ArrayList<String>();  seems to create a type-safe arraylist polymorphically but mind you the JVM doesn't see the generic declaration at runtime; Using generics is ONLY a type of compile-time protection. But why ? Why did they do this ? The answer is simple - to mix this new code with legacy code; so at runtime the JVM only sees List l = new ArrayList(); . Look what happens if a developer is high and isn't careful when tampering with older code in the following example:

import java.util.*;

public class TestBadLegacy {
    public static void main(String[] args) {
          List<Integer> myList = new ArrayList<Integer>();
          myList.add(4);
          myList.add(6);
          Inserter in = new Inserter();
          in.insert(myList); // pass List<Integer> to legacy code
         
          /*
          for (int i=0;i<myList.size();i++){
              System.out.println(myList.get(i));
          }
          */
         
         
          for(Integer i:myList){
              System.out.println(i);
          }
         
         
       }
}
/*
this is the supposedly generic type-safe class, but check out below the legacy Inserter class which has a method that doesn't know
that a type-safe collection is being passed to it
*/

class Inserter {
      // method with a non-generic List argument
      void insert(List list) {
         list.add(new String("42")); // adds to the incoming list
    }
}

The result of running TestBadLegacy is:
4
6
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at TestBadLegacy.main(TestBadLegacy.java:18)

Surprised ? you shouldn't. even though a String element has been added to an integer-only collection the compiler didn't complain because the adding took place in the legacy code but at runtime when we did the foreach we assigned at one poin an Integer reference to a String object so this resulted in a complete meltdown.

Bollocks!


Wednesday, August 26, 2009

[Java] Boxing, ==, and equals() tweak

It shouldn't be surprising that

Integer i1 = 1000;
Integer i2 = 1000;
if(i1 != i2) System.out.println("different objects");
if(i1.equals(i2)) System.out.println("meaningfully equal");

Produces the output:

different objects
meaningfully equal

How about this one:

Integer i3 = 10;
Integer i4 = 10;
if(i3 == i4) System.out.println("same object");
if(i3.equals(i4)) System.out.println("meaningfully equal");

This example produces the output:

same object
meaningfully equal

Yikes! The equals() method seems to be working, but what happened with == and != ? Why is != telling us that i1 and i2 are different objects, when == is saying that i3 and i4 are the same object? In order to save memory, two instances of the following wrapper objects (created through boxing), will always be == when their primitive values are the same:
■ Boolean
■ Byte
■ Character from \u0000 to \u007f (7f is 127 in decimal)
■ Short and Integer from -128 to 127


Source: Sierra & Bates SCJP 6 Study Guide , Chapter 3

Tuesday, August 18, 2009

How to instal Intellij IDEA on Ubuntu

1. get your copy from here http://www.jetbrains.com/idea/download/
2. Unpack the idea-8.1.3.tar.gz file using the following command: tar xfz idea-8.1.3.tar.gz
3.
[this is the tricky part] Edit idea.sh from the bin subdirectory by adding the jdk 6 home directory to the variable IDEA_JDK (i.e. IDEA_JDK=/usr/java/jdk1.6.0 , depends on where you've placed the sdk )

Jah bless

make GRUB menu reappear after installing UBUNTU (having a vista installation to start with)

I had Ubuntu 9.04 (Jaunty) installed on a 80 gigs partition on my pc beacuse i was starting to get sick of Vista but after my first reboot, the system booted vista automatically without prompting me with the boot (grub) meu at startup. I've researched this over the web and came up with the following solution:

1. Use ubuntu live cd to boot into the unix system
2. open a terminal via Accesories menu
3. type "sudo grub"
4. type "find /boot/grub/stage1" - this will return a result, in my case it was (hd0,4)
5. type "root (hd?,?)" - in my case i typed root (hd0,4)
6. type "setup (hd0)"
7. quit and reboot

have a nice day

Sunday, July 5, 2009

GWT ftw

The google web toolkit provides a kickass infrastructure for creating ajax-powered web apps right from java code. The gwt compiler will transform the java into javascript and the results are stunning. Here are 2 very sweet links for easy learning the basics of GWT, mainly the RPC (remote procedure call) feature:
http://www.vogella.de/articles/GWT/article.html
http://developerlife.com/tutorials/?p=125

Friday, May 8, 2009

Misinterpretation (or the reason why FAQ sounds like "fuck you")

I was trying to get the size of a JDBC result set without the usage of some gay code like "while(rs.next()) { //increment an index}" or worse, creating another statement with the query "select count(*) .... " to retreive only the number of rows from the targeted table.
Even though at first you might want to try resultSet.getFetchSize() , it will not get the "fetch size" specified in the nomenclature, i.e. the number of rows you seek. A closer peek at the jdbc documentation states that getFetchSize() "Retrieves the number of result set rows that is the default fetch size for result sets generated from this Statement object" .
The solution for this ? there is no predefined method in the Statement metadata to return the result set size without parsing it... you may need to choose one of the (gay) methods specified above or find some other.

Saturday, May 2, 2009

parse me again blues

Having the DB entity "Message" with ID and text, i was returning with the entity manager a collection of the form Set<Message> . After obtaining this set i needed to line these messages in a forum thread i was building. The problem isn't that i couldn't get the messages but the message list was not sorted by id (which i recon is by default because that's how result sets go), so everytime i refreshed my forum page, i got those messsages in a different order.
My solution? Altough redneck-ish, i've manually sorted the Set<Message> collection before returning it :p
 

Monday, April 27, 2009

note to self (eclipse bug)

If you add a file to the project folder outside the Eclipse IDE, that file will not be seen inside the IDE until that particular project is refreshed :|

Friday, April 24, 2009

Java operators game

Given the following code:
   int var = 2;
   var+= 2.5;
   System.out.println("var="+var);
the result will be var=4
Now we change that to
   int var = 2;
   var=var + 2.5;
   System.out.println("var="+var);
The result should be the same at first sight but it's not. Compound operators do implicit casting whereas the line "var=var + 2.5;" does not. Explicit casting is required in this situation.
       Have a nice day!

Thursday, April 23, 2009

Spring & XML quickie

something nasty occured today as i tried to pass an attribute from a spring controller to a JSP-page view. That attribute is an XML string of the form "<root><item1>...</item1><item2>...</item2>...</root>", written without newlines. all fine and dandy so far, but when i tried to obtain the attribute in my jsp using ${var}, all i got was the item values without any of the tags... to fix this i had to rewrite the code in the jsp to  <% String str = request.getAttribute("var").toString %> . I'm curious why the jsp has interpreted the xml string like that