Sunday, August 10, 2008
Ganymede, m2eclipse, wtp and tomcat hotdeploy
1. install dev version of m2eclipse with most of the optional plugins. The current release version has dependency issues
http://m2eclipse.sonatype.org/update-dev/
2. install subclipse
3. File->New->Other->check out project from SCM.
4. to convert an existing project to wtp web project: run mvn eclipse:eclipse -Dwtpversion=3.0. Note this is not working at the moment as maven eclipse plugin only supports 1.5 and 2.0.
5. instead you can do: check out the project as a regular svn project, create a new dynamic wtp web project in workspace using maven archetype: weba*, copy the existing source into the new project. note: do NOT overwrite the existing .project file
Sunday, November 25, 2007
Getting started with JPA and Hibernate
- hibernate-all
- thirdparty-all.jar
- jboss-ejb3-all.jar
hibernate-annotations-3.3.0.GA
- hibernate-annotations.jar
hibernate-3.2.5.GA
- hibernate3.jar
hibernate-entitymanager-3.3.1.GA
- hibernate-entitymanager.jar
EntityManager Interface - hibernate-all.jar
EntityManagerFactory Interface - hibernate-all.jar
EntityManagerImpl - hibernate-entitymanager.jar
EntityManagerFactoryImpl - hibernate-entitymanager.jar
Note: the current hibernate-all.jar is not compatible with the latest hibernate GA release and therefore, hibernate-all.jar should come after hibernate-annotations.jar in the jar export order. Otherwise it will throw NoSuchMethodError.
Saturday, September 1, 2007
Using M2Eclipse
1. Install M2Eclipse from http://m2eclipse.codehaus.org/update/
2. Create a webapp project using maven
3. Create a dynamic web project with eclipse using the same project name.
4. Fix web content folder, src/main/java and src/test/java folders.
5. add m2 dependencies in j2ee dependencies for the project.
6. ready for hot deploy.
Friday, August 31, 2007
Use Maven2 with Eclipse WTP
Eclipse Version: 3.3.0
Build id: I20070625-1500
The following is how I setup a maven web project that can be hot deployed using eclipse WTP.
1. Create maven web project
mvn archetype:create
-DgroupId=[your projects group id]
-DartifactId=[your project's artifact id]
-DarchetypeArtifactId=maven-archetype-webapp
ref
2. Create dynamic web project in eclipse
Replace maven generated WEB-INF and META_INF with eclipse generated WEB-INF and META-INF
3. Create M2_REPO variable in eclipse and point it to ~/m2/repository
4. Create src/main/java and src/main/test folder
5. Point eclipse source folder to src/main/java and src/main/test folders.
6. Delete eclipse WTP default WebContent folder.
7. Switch to navigaton view and modify org.eclipse.wst.common.component file
i.e.
<?xml version="1.0" encoding="UTF-8"?>
< project-modules id="moduleCoreId" project-version="1.5.0">
< wb-module deploy-name="MyWebApp">
< wb-resource deploy-path="/" source-path="/src/main/webapp"/>
< wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
< wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
< property name="context-root" value="MyWebApp"/>
< property name="java-output-path" value="build/classes"/>
< /wb-module>
< /project-modules>
8. Modify pom.xml file and add the following plugin configuration
< build>
< finalName>MyWebApp</finalName>
< plugins>
< plugin>
< groupId>org.apache.maven.plugins</groupId>
< artifactId>maven-eclipse-plugin</artifactId>
< configuration>
< buildoutputdirectory>src/main/webapp/WEB-INF/classes
< /buildoutputdirectory>
< downloadsources>true</downloadsources>
< /configuration>
< /plugin>
< /plugins>
< /build>
9. Add dependent libraries to the pom.xml
10. run mvn eclipse:eclipse
Friday, August 17, 2007
Architectural view of Web Applications
- The model handles application and business logic
- The view handles presentation logic
- The controller accepts and interprets keyboard and mouse input.
The motivation behind MVC was to separate the model code from its presentation. The model code does not contain any UI information, but it broadcasts notification of any state changes to dependents, which are typically views.
This scheme provides a good separation between these three layers but suffers from two weaknesses.
- It has a simplistic view of the model and does not account for any difference between application logic (for example, flow of control and coordination of multiple Web pages) and business logic.
- Most rich-client libraries and windowing system combine the view and controller functions in a single widget, making the logical separation into view and controller less userful.
MVC framework has evolved.
Controller: object handling application logic.
Model:business objects.
Controller
Input Controller
The input controller is a central feature. There is a single input controller for all pages in a Web application. The input controller parses input, determines the parameter-passing mechanisms, extracts any necessay information from the request, cooperates with the application controller to determine the next operatioin (typically called an action), and invokes that action in the correct context. By having a single component as an input controller, any knowledge of HTTP or naming conventions is localized at the request level. This reduces the amount of code duplication and the total size of code. Note that the input controller component is typicaly a servlet, and there may be one instance for accessing the application over HTTP via a regular Web browser and another instance for mobile applications using a Wireless Application Protocol (WAP) enabled device.
Application Controller
The application controller is typically a regular Java object. It coordinates logic related to the application flow, handles errors, maintains longer-term state, and determines which view to display. Application controllers typically need a mapping orequests to the application objects that manage the flow. Most frameworks maintain these mappings in complex XML configuration files.
Tuesday, July 24, 2007
Install Eclipse WTP build 2.0 and JadClipse
To install JadClipse, first follow the instructions on this page.
Note: make sure the class files you want to decompile is on your classpath.
Thursday, July 12, 2007
Java 101
Speed
- An ArrayList is backed by a primitive Object array. Because of that, an ArrayList is much faster than a LinkedList for random access.
- The standard binary search algorithm starts by checking the search key against the value in the middle of the list. If the middle value is too high, then the upper half of the list is eliminated. However, if the middle value is too low, then the lower half of the list if ignored.
- LinkedList is a bad choice in this situation. The binary search algorithm inherently uses random access, and LinkedList does not support fast random access. The time to do a random access in a LinkedList is proportional to the size of the list. By comparison, random access in an ArrayList has a fixed time.
- If you have lots of element inserting and deleting, LinkedList is a better choice.
- When an element is added to the beginning of an ArrayList, all of the existing elements must be pushed back, which means a lot of expensive data movement and copying. By contrast, adding an element to the beginning of a LinkedList simply means allocating an internal record for the element and then adjusting a couple of links. Adding to the beginning of a LinkedList has fixed cost, but adding to the beginning of an ArrayList has a cost that's proportinal to the list size.
Space
- LinkedList class has a private internal class defined like this:
private static class Entry {
Object element;
Entry next;
Entry previous;
}
Each Entry object references a list element, along with the next and previous elements in the LinkedList -- in other words, a doubly-linked list. A LinkedList of 1000 elements will have 1000 Entry objects linked together, referencing the actual list elements. There is a significant space overhead in a LinkedList structure, given all these Entry objects. - An ArrayList has a backing Object array to store the elements. This array starts with a capacity of 10. When the array needs to grow, the new capacity is computed as:
newCapacity = (oldCapacity *3)/2 +1 - Notice that the array capacity grows each time by about 50%. This means that if you have an ArrayList with a large number of elements, there will be a significant amount of space wasted at the end. This waste is intrinsic to the way ArrayList works. If there was no spare capacity, the array would have to be reallocated for each new element, and performance would suffer dramatically. Changing the growth strategy to be more aggressive (such as doubling the size at each reallocation) would result in slightly better performance, but it would waste more space.
Summary
- Appending elements to the end of a list has a fixed averaged cost for both ArrayList and LinkedList. For ArrayList, appending typically involves setting an internal array location to the element reference. but occasionally results in the array being reallocated. For LinkedList, the cost of uniform and involves allocating an internal Entry object.
- Inserting or deleting elements in the middle of an ArrayList implies that the rest of the list must be moved. Inserting or deleting elements in the middle of a LinkedList has fixed cost.
- A LinkedList does not support efficient random access.
- An ArrayList has space overhead in the form of reserve capacity at the end of the list. A LinkedList has significant space overhead per element.
- Sometimes a Map structure is a better choice than a List.
ref