Java
文章平均质量分 55
smile_juan
这个作者很懒,什么都没留下…
展开
-
Java Date Convert(long, String, Date)
1. Date convert to long Date now = new Date(); long time = now.getTime(); getTime(): Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object. 2. lo转载 2012-11-15 01:27:53 · 1672 阅读 · 0 评论 -
Spring global exception handling with standalone app
I have a standalone app, I need to catch all exceptions. There's one case that when I disconnect the internet, I couldn't connect the database, and database operations are in another component. It'll转载 2013-01-10 05:12:46 · 1526 阅读 · 1 评论 -
Spring config different datasource based on different environment(dev, test, prod) Two ways now
Spring is very powerful when I use Spring more and more, it provides a lot of fancy functions. In my standalone app, I config datasource in context.xml, jdbc.driver.name, url, username, password, all原创 2012-12-14 06:56:52 · 1110 阅读 · 0 评论 -
Make IDE(Eclipse) not overwrite our configured server setting
This is because of the default setting of IDE. By default, it overwrites every thing we configured when we restart the server. Go to Windows->Preferences->Server, and uncheck the selectbox.原创 2013-01-12 04:21:18 · 615 阅读 · 0 评论 -
When start tomcat, got the error: Resource /WEB-INF/classes not found
javax.naming.NameNotFoundException: Resource /WEB-INF/classes not found at org.apache.naming.resources.BaseDirContext.listBindings(BaseDirContext.java:733) at org.apache.naming.resources.ProxyDirCon转载 2013-01-30 00:09:36 · 2491 阅读 · 0 评论 -
Java Iterate directory to find files and edit
After mannually modified about 100 pages, I'm tired of doing that. So it's better to write a small program to deal with those thing. 1. We need to find those files which we need to modify in differen原创 2013-01-18 01:13:50 · 673 阅读 · 0 评论 -
JAXB annotations
Here is an example I need to deal with, it looks complicated. With the help of JAXB, it's really easy to get all values from the xml file. For example: article.xml world World A co原创 2013-01-22 06:29:59 · 924 阅读 · 0 评论 -
Interesting way to validate number
Today when I read my co-worker's codes, I found an interesting way to validate if a string is numeric. Here is my way to do. Because I'm not good at regex, every time I need to search online and fin原创 2013-02-08 03:36:51 · 620 阅读 · 0 评论 -
log4j create a new log file every day
After I joined in new project, I realized log is very important. We can log in console or file. Here is to introduce a way to log in file without overwrite. It's really easy to use log4j. # Define原创 2013-01-22 01:24:31 · 1239 阅读 · 0 评论 -
RESTeasy to make a REST Call
Previously I wrote an article to use Jersey to make a REST call. Afterwards, we changed to use RESTeasy to do that. The reason we changed that doesn't convince me, because we decided to use JSON inste原创 2013-03-06 23:15:33 · 1510 阅读 · 0 评论 -
Spring load properties file and MessageFormat
During yesterday's code review, learn another way to load properties file by using Spring. Spring is so powerful, I love it! I found there are two ways to do that: 1. use 1) Define your properties原创 2013-03-09 04:03:29 · 1590 阅读 · 0 评论 -
Jersey make REST call
When we make a rest call and the response is XML or JSON, it would be better to use plugins other than from scratch. I chose to use Jersey and JAXB. It's very convenient to code. 1. We need to add je原创 2013-01-22 06:15:51 · 1019 阅读 · 0 评论 -
Read properties file in a jar
When I set the path of properties file, it's OK when we run in IDE. When I packed it in a jar and tried to run that, it won't pass. It seems strange because the path of the properties will be changed原创 2013-01-22 01:56:05 · 702 阅读 · 0 评论 -
Sql Sever 2008 jar Maven pom.xml dependency
When I add sqlserver04.jar into my maven project, it's a little bit different others. For other jars, I directly add dependency into pom.xml. For sqlserver.jar, the dependency works on others' project原创 2012-12-01 00:22:44 · 15945 阅读 · 1 评论 -
Java Load Properties example
http://www.mkyong.com/java/java-properties-file-examples/ public static Map getProperties(){ Map properties = new HashMap(); try { prop.load(new FileInputStream("src/main/java/config.properties"))转载 2012-11-21 06:29:37 · 937 阅读 · 2 评论 -
Collections sort by Entity property like Date
For example, Tweet entity has two properties: Id, tweetCreateDate. I have a list of tweets, I need to sort them by tweetCreateDate desc. Here is the way I do it. Collections.sort(tweets, new Comparat原创 2012-11-22 01:02:16 · 555 阅读 · 0 评论 -
Eclipse or IDE integrated with Eclipse .project and .classpath files
Recently, I got a very interesting task. In our daily work, we use Liferay, Liferay uses Ant to create projects. All projects created by Liferay is basic not targeted to our client. So when we create原创 2012-12-12 22:47:23 · 1774 阅读 · 0 评论 -
Config log4j in standalone app
1. First make sure you've added the log4j.jar 2. config log4j.xml and log4j.properties Show an example: log4j.xml log4j.properties log4j.rootLogger=DEBUG, CA log4j.ap转载 2012-12-14 07:39:42 · 813 阅读 · 1 评论 -
JSP "items" does not support runtime expressions
${datatables.engine} ${datatables.browser} ${datatables.platform} ${datatables.version} ${datatables.grade} In my JSP page, I import JSTL taglib like above, but it gives me the e原创 2012-12-27 00:07:53 · 9490 阅读 · 1 评论 -
Java JDBC Performance vs. iBatis vs. Hibernate
http://phillips4jc.blogspot.com/2011/03/java-jdbc-performance-vs-ibatis.html http://arxiv.org/ftp/arxiv/papers/0710/0710.1404.pdf转载 2012-12-14 23:21:56 · 1131 阅读 · 0 评论 -
Get value from properties file outside a jar using Spring
I have a jar file which need to dynamically load external properties file and read values from this properties file. Those values are needed in the java program. With Spring, it's very easy to do that原创 2012-12-19 06:56:10 · 1418 阅读 · 1 评论 -
java.lang.String cannot be resolved, Indirectly referenced from required .class file
Here is the solution. It's similar to the link I found. http://dev-answers.blogspot.com/2009/06/eclipse-build-errors-javalangobject.html Go to properties of project with the build error (right c转载 2013-01-08 00:37:27 · 1659 阅读 · 0 评论 -
Java Send email
Sometimes we want to send an email out when catch an exception. We need to use javax.mail jar to help us to do that. Actually we have several ways to do that. Here is to introduce the easiest way with原创 2013-01-22 01:37:49 · 1860 阅读 · 1 评论 -
Java compareTo, equals and hashcode
Last time, when our team reviewed my code, they pointed several problems of my code. I'm really happy to learn from them. Until now, what I do is only to make the code work. Then, I'll try to refactor转载 2013-03-23 03:07:23 · 1045 阅读 · 0 评论