snippetjournal

- notes, snippet codes, and my journal

Eclipse STS Trivial Configuration

leave a comment »

Lately i was using eclipse STS to develop some information system, after a long time using netbeans, using STS is so much painful for me.

Yes eclipse STS fan boy can hate me, hatters gonna hate after all …  :P

In netbeans some trivial things like deployment process using eclipse, synchronized source in tomcat, auto deploy, maven configuration, and another deployment issues in tomcat,  are never occur when i was using netbeans

That kinds of trivial thing some time are so painful, you must configure it so you will have good sleep at night. :D , in the netbeans this kind of configurations are the default configuration, and i can say that netbean have improve so much than STS, it more easier develop using netbeans :P. You can focus on development rather get confused by configure your IDE to behave like you want to.

this are some STS issue that sometime occur when i was using it for development.


java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4909)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

this error occur because your maven dependency or your libs that manage by maven didnt included in tomcat deployment. here the solution :

right click in your project, properties – deployment assembly : add java build path entries – maven dependencies – finish.

refresh your poject, re-build , clean your tomcat resources to make sure it will deploy your new source (right click in tomcat server – clean), after that run your project in tomcat server.

another error is un-synchronized source in your tomcat server when you trying to deploy it. i spent more than an hours facing this kind of issue, i try to clean the project using maven, clean – build project in STS, rebuild and clean tomcat resources for many times.

this probably occur because STS didnt refresh the resources in workspace and tomcat when the project rebuild in STS or netbeans.

the solution you must configure STS to automatically refresh the resources, go to preferences – workspace : checklist this options :

  • build automatically
  • refresh using native hooks or pooling
  • refresh on access
  • save automatically before build

and another tricks is when you have many resources file like CSS or java script you must configure STS memory more than the default memory, just change memory size in STS.ini in your STS installation location :

–launcher.XXMaxPermSize
512M

-Xms512m
-Xmx1024m
-XX:MaxPermSize=512m

Written by snippetjournal

January 17, 2015 at 3:42 am

Posted in Uncategorized

Tagged with , , , , ,

Ajax posting as Data Map in spring MVC

leave a comment »

post data dengan ajax sebagai data Map di java dan spring mvc

Javascript code :


	param = {
		xx1 : "xx",
		xx2 : "xx",
		xx3 : "xx",
		xx4 : "xx"
	};
		
	// post data when page loaded
	var postParamForDatatable = $.ajax({
		url : urlContext + "post/param/xxx",
		type : "POST",
		contentType : "application/json",
		data : JSON.stringify(param)
	});

	console.log("get data ");
	// callback handler that will be called on success
	postParamForDatatable.done(function(repliedData) {
		console.log("repliedData "+repliedData);
	});

	// callback handler that will be called on failure
	postParamForDatatable.fail(function(jqXHR, textStatus, errorThrown) {
		alert("The following error occured: " + textStatus, errorThrown);
	});

	// callback handler that will be called regardless if the request failed or
	// succeeded
	postParamForDatatable.always(function() {
		console.log("callback handler that will be called regardless if the request failed or succeeded");
	});

Java controller dengan spring mvc


	@RequestMapping(value = "/post/param/xxx", method = RequestMethod.POST)
	public @ResponseBody String getdataParam(@RequestBody Map<String, Object> searchParam, HttpServletRequest request, HttpServletResponse response) {
		System.out.println("================ "+searchParam);
		
		return "ok";
	}

Written by snippetjournal

January 15, 2015 at 6:57 am

Posted in Uncategorized

Get Context Url from Java Servlet

leave a comment »

Get Context Url from Java Servlet


<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="req" value="${pageContext.request}" />
<c:set var="url">${req.requestURL}</c:set>
<c:set var="uri" value="${req.requestURI}" />
<c:set var="urlContext" value="${fn:substring(url, 0, fn:length(url) - fn:length(pageContext.request.requestURI))}${pageContext.request.contextPath}/" />

Written by snippetjournal

December 31, 2014 at 2:55 am

Posted in Uncategorized

Hibernate : Understanding First level and Second level cache

leave a comment »

found this article, a good article and easy explanation tutorial :)

note :

  • SessionFactory provides session, session maintains cache.
  • How will session cache object get update from DB if any changes happen. Will get update automatically or explicitily.?

In case of single session, your application code always update this cache object so it is always updated. Hibernate takes care of synchronizing the changes with database at time of flushing the session.

Now consider another example:

machine 1: reads the data and returns it for editing somewhere else
machine 2: also reads the data for modification
machine 1: updates the data and commits.
machine 2: tries to do an update and commit.

What will happen when the second machine tries to commit its changes? Hibernate will see that the data has changed while machine 2 was working on the data. That is, machine 2’s update is on stale data. Hibernate can’t always merge the two changes (nor is that always desired behaviour), so it rejects the second update by throwing org.hibernate.StaleObjectStateException.

The simplest solution, perhaps, is to add a version field using @Version on your data objects. Hibernate will automatically maintain the “version” of the data. Whenever an update takes place, the version will be changed automatically by Hibernate. Your job is the check that the version hasn’t changed between when you read the data and when you update the data. If they don’t match, you can do something to handle the problem (i.e. tell the user). There are some more sophisticated techniques for preventing concurrent updates, but this is the simplest.

Written by snippetjournal

November 24, 2014 at 3:33 am

Sonatypes Maven References

leave a comment »

Written by snippetjournal

November 20, 2014 at 2:47 am

Posted in Uncategorized

SVN: trunk, branch and tag, explanation

leave a comment »

Written by snippetjournal

November 20, 2014 at 2:34 am

Posted in Uncategorized

IVY Tutorial

leave a comment »

I found this was a great tutorial about ivy, credits to the author

Written by snippetjournal

November 18, 2014 at 3:33 am

Posted in Uncategorized

Follow

Get every new post delivered to your Inbox.

Join 77 other followers