snippetjournal

– notes, snippet codes, and my journal

Archive for January 2015

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 …  😛

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. 😀 , 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 Programming

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 Programming

Tagged with ,