2009年10月18日
今天废了老劲了,终于找到为何deploy/lib目录下一个包从哪里来的了。在项目的dependency里没有发现这个包,但是deploy目录下总可以找到。
查了半天,终于发现了,在项目dependency里依赖到的第三方的一个包里它依赖到了我需要查找的包,导致这个包被貌似莫名其妙的进入到了deploy/lib下面。
Attended Scrum training theses two days.
Some highlights from the training:
- Scrum master is a facilitator, does not assign task. Team owns tasks itself.
- Each feature has a unique rank, decided by product owner and scrum master and the team. Always finish rank high feature first, before continue rank low feature.
- Scrum always encourage communication and collaboration.
- Scrum is not a project management, but a framework for all the teams to do the things in same way. Project management methodology is still needed in Scrum.
- Scrum deliver value sooner than waterfall method.
- Scrum fits the product/project that requirements are not so fixed.
- Each team/person has its own customer.
- Successful software development projects are mainly based on people interactions.
- Advocate zero defect in iterations, ready to release after each iteration.
- XP is next level of Agile after Scrum.
I upgraded to IntelliJ IDEA 7.0 the day it came out and was, at first, let down by how poorly it performed on my machine. Since then, I tweaked a bunch of settings, and now have it performing just as fast as IDEA 5 ever did on the same box. Enjoy, and happy coding!
1. Change your Look and Feel
Change your look and feel to something other than native. On Windows, the “IDEA (4.5 Default)” look and feel performs much better than the native one. On Mac, just pick something other than the native. The new graphics will bother you for about 30 minutes and then you’ll forget all about them. This setting is in the Settings (Ctrl+Alt+S) -> Appearance (B) dialog. (Tip courtesy of Howard Lewis Ship)
2. Use Structure View Instead of Project View
In IDEA 7.0.2 on Windows, I seem to pay a heavy performance price for the Project View (Alt+1), especially with autoscrolling to and from source enabled. My alternative is to use the Structure View (Alt+2) as my default sidebar and rely on the Navigation Bar (View->Navigation Bar) for project navigation. I find I actually prefer this setup and 7.0.2 performs noticeably faster.
3. Turn off Synchronize Files
When you activate the IDEA frame, IDEA will scan the disk for file changes, giving you a nice progress bar to wait for. If you’re not editing files outside of IDEA then turn this feature off in Settings (Ctrl+Alt+S) -> General (A). Uncheck “Synchronize Files on Frame Activation”. Now you’ll have to manually synchronize the files using Ctrl+Alt+Y (File->Synchronize on the menu). (Tip courtesy of Tyler)
4. Disable Spring Model Validation on Build
I used to get a progress bar every time I ran or debugged my project, with the message “Validating Spring Model”. I don’t need this feature except when I’m working on the Spring files, so I turned it off. Settings (Ctrl+Alt+S) -> Project Settings (1) -> Modules… then click Spring, then click the Options Tab. Deselect the checkbox for “Enable Spring model validation on build”.
5. Disable Unused Plugins
Disable all of the plugins you are not currently using. For example, if you’re not using Geronimo, Commander or Jabber, then turn them off. Settings (Ctrl+Alt+S) -> Plugins (T). Uncheck anything you have installed that is unused (Tip courtesy of Carl)
6. Use Scopes to Speed Up Searches
I rarely really want to search my entire project for a string or reference. Any search dialog allows you to pick a custom scope, such as production files or test files. But “Changed Files” is a helpful option too. On large, monolithic projects you may want to define your own to only search certain packages. A little time creating new scopes will save you a lot of time in waiting for searches to complete. Define scopes in Settings (Ctrl+Alt+S) -> Scopes (5).
7. Increase Your Heap Size
Several sources include directions on increasing your heap size in IDEA. This is changed in your idea.exe.vmoptions file.
8. Always Get the Latest Version
I’ve already suggested this, so I’ll be brief. Each minor release seems to have good performance improvements.
9. Reduce Size of Local History
Another blog recommended that you turn off or reduce Local History. I love this feature so I’ll never turn it off, but the default is to save 3 days worth of work. I typically check in to version control more often than that, so I trimmed it up to 1 day of history. Do this in Settings (Ctrl+Alt+S) -> Local History (J).
10. Optimize Your Disk?
I haven’t tried this myself, but the tip came directly from JetBrains. Beyond just defragmenting, you can also optimize the MFT tables, disk folder structure, and the paging file. Direction appear on their site. Simply upgrading to a newer hard drive is find at home, but I don’t have that much control of my work machine. It’s Friday, so I’ll try this today. If things go horribly wrong I’ll redact the entry!
————————————————————————————————————————————————————————————————————————————
IntelliJ IDEA Performance
There're some concerns about IntelliJ IDEA Performance. And here is the tips that I used to make mine run fast. Some of them come from my own experience, some of them come from the know-everything internet.
* Make sure you have all your libraries on your local harddrive (as opposed to mounted network drive). After I moved all my libraries from a network drive to local harddrive, the time for a 'make' on the project is reduced from around 60 seconds to just 5-7 seconds!
* Defragment your Disk and reboot your computer. IDEA creates lots of small files and too much fragmentation is a nightmare.
* Turn off Anti Virus completely. Yes I mean completely. It affects the performance dramatically.
* Turning off Local History or even reducing the number of history days improved the performance significantly.
* Adjust VM settings. Here is my idea.exe.vmoptions file (on windows):
-Xms512m
-Xmx512m
-XX:MaxPermSize=99m
-ea
Change it as you see fit per your hardware configuration.
More information is available at http://blogs.jetbrains.com/idea/2006/04/configuring-intellij-idea-vm-options/.
* The Debugger in IDEA may work slowly if the Force classic VM option is not selected in the File Project Properties Debugger dialog. Using Method Breakpoints may also slow down the debugging process. I had two breakpoints on the method name instead of the first line of the method. It was taking a half hour to get to the breakpoint Changing these to line breakpoints gave me two orders of magniture
* You may notice IDEA hang for several seconds when you switch to it from other applicationDisable Settings General Synchronize files on frame activation.
* Disable windows paging file if you have enough memory. Get more memory if you don't have enough. Swapping is a performance nightmare.
* Turn off windows indexing services, either set it to Disabled or Manual unless you do lots of file system search (even you do, I recommend Google Desktop Search). IDEA use lots of small files so background indexing can have a big negative effect on it's performance.
* Control Panel/System/Properties/Advanced/Visual Effcts, Adjust for best performance. Unless you're willing to sacrify performance for visual effects like windows animation, fading/sliding etc.
一般而言,兔子在出生两个月后,就有繁殖能力,一对兔子每个月能生出一对小兔子来。如果所有兔都不死,那么一年以后可以繁殖多少对兔子?
我们不妨拿新出生的一对小兔子分析一下:
第一个月小兔子没有繁殖能力,所以还是一对;
两个月后,生下一对小兔民数共有两对;
三个月以后,老兔子又生下一对,因为小兔子还没有繁殖能力,所以一共是三对;
------
依次类推可以列出下表:
所经过月数:0、1、2、3、4、5、6、7、8、9、10、11、12
兔子对数:1、1、2、3、5、8、13、21、34、55、89、144、233
表中数字1,1,2,3,5,8---构成了一个序列。这个数列有关十分明显的特点,那是:前面相邻两项之和,构成了后一项。
这个数列是意大利中世纪数学家斐波那契在<算盘全书>中提出的,这个级数的通项公式,除了具有a(n+2)=an+a(n+1)/的性质外,还可以证明通项公式为:an=1/√5[(1/2+√5/2)^ n-(1/2-√5/2)^ n](n=1,2,3.....)(√5表示根号5)
这个通项公式中虽然所有的an都是正整数,可是它们却是由一些无理数表示出来的
If you want the entry to be garbage collected, use WeakHashMap. Once the key is not strongly referenced, the entry will be automatically reclaimed.
Here is a good article to understand this:
http://www.codeinstructions.com/2008/09/weakhashmap-is-not-cache-understanding.html
附录 A. 需要搞清楚几个问题
A.1. Maven2的优点
1.
对第三方依赖库进行统一的版本管理。
只要用了Maven2就不用再为每个项目复制spring.jar和hibernate.jar了,Maven2会在你需要的时候,自动把这些第三方依赖库找到,你需要编译,Maven2就把这些jar包放到classpath里,你需要打包,Maven2就帮你把需要的jar包都复制到WEB- INF/lib/目录下。
2.
统一项目的目录结构。
可以保证所有项目的目录结构都是一样的,目录结构统一的好处就是,你要找源代码就去src/main/java/下,你要找需要放到classpath下的资源,就去src/main/resources/下,你要找单元测试对应的代码和资源,就去src/test/下。每个目录下放什么东西,程序编译,发布的时候,每个目录起什么作用都很清楚明了,不会出现打开项目找不到要找的文件的情况。
3.
统一软件构建阶段
Maven2把软件开发的过程划分成了几个经典阶段,比如你先要生成一些java代码,再把这些代码复制到特定位置,然后编译代码,复制需要放到 classpath下的资源,再进行单元测试,单元测试都通过了才能进行打包,发布。
以前使用Ant,最令人头疼的就是要为不同的项目写很多build.xml脚本,而且这些脚本还不太通用,现在我们可以使用Maven2提供的这些经典构建阶段,让每个项目就经过相同的步骤,从源代码一步一步变成可以部署的成品。如果想要什么附加功能,把对应的插件绑定到一个构建阶段上,那么到了执行这个构建阶段的时候,就会执行绑定的插件了。
4.
支持多种插件
在http://maven.apache.com/和http://mojo.codehaus.org/上可以找到大量的Maven2插件,通过这些插件可以完成多种多样的扩展功能。
不过,如果比插件的易用性,Ant的插件实际上更简单方便,与之相比,在Maven2中配置插件的步骤太复杂了,既要配置groupId和 artifactId,还要配置绑定在哪个阶段运行。
不过因为Maven2可以把插件连同第三方依赖一起进行统一版本管理,所以这方面也算比Ant有一点儿优势,至少使用时不需要自己再去下载插件的发布包了。
5.
自动生成项目网站和报表
如果说Ant可以使用ivy实现第三方依赖库的统一管理,如果说Ant可以自己统一项目的目录结果,如果说Ant支持插件更灵活,那么这个特性绝对是 Ant无法比拟的。
Maven2 可以自动为项目生成一个网站,里面包含了项目信息,参与人,项目管理相关的资源,第三方依赖库,使用的插件,以及通过其他扩展插件生成的各种报表。Ant 使用某些插件也可以生成html格式的报表,但是各个报表之间都没什么关联,不像Maven2中将网站和报表都关联在一起,查看起来十分方便。
A.2. Maven2的问题
1.
Maven2使用前需要像Ant一样需要配置环境变量。
本来绿色安装是一件好事,但是因为太多人都只会用IDE,不了解如何配置环境变量,所以这第一步就很成问题。
2.
Maven- 2.1.0本身只有2.844M,可是这只是一个核心,实际使用时,还需要去公网上的资源库下载各种插件,然后才能实现各种功能,问题是公网上的资源库一般都是在国外,网路速度稍慢就无法完成下载,没法下载就没法使用Maven2里提供的那些功能,Maven2就用不起来。
尤其对于新手来说,第一次下载插件的过程,实在是太痛苦了,大多数人都在这一阶段放弃了对Maven2的尝试。
3.
第三方依赖库版本混乱。
java的依赖库管理一直没有约定规范,导致多个项目,引用多个第三方依赖,这些第三方依赖又使用同一个项目的不同版本的发布包,最后就是弄得一团糟。
Maven2 尝试通过一些约定解决这个版本混乱的问题,但实际上并没有达到预想中的效果。例如,commons.apache.org中的项目,本来应该放在 org/apache/commons/目录下,现在却都各自放在commons-logging,commons-lang,commons- beanutils目录下,估计这是因为刚开始使用Maven2的那些人,懒得把常用包放到那么深的目录结构中,偷懒放到了顶级目录下。可随着 Maven2的发展,加入资源库的包越来越多,他们又把新发布的依赖包按照正常的方式,放到了org/apache/commons/目录下,而旧依赖还有很多人在用,所以也不能删除,这就造成了现在这种一种依赖库多种存放形式的问题。
每次在资源库上找依赖都要花费很多时间,因为你不清楚它究竟使用的哪种目录形式,比如sourceforge.net上的项目就有两种目录形式,一些项目放在net/sf /目录下,而另一些例子放在net/sourceforge/目录下,所以你就算知道项目的网站地址,也要在多个目录下都找一遍。
4.
缺乏详细的教程
入门教程一般都很简略,现在似乎使用的人多了起来,可以在网上找到一些新手教程,但是一般都很简略,只能自己玩玩,实际中遇到问题的话,还是很难解决。
实际上Maven2的教程一直是一块短板,就算是国外的两本书《Maven: The Definitive Guide 》和《Better Build With Maven》也没有涉及到富含价值高级技术。
就算是讲的比较详细的Maven2教程,也都是停留在Maven2本身的使用上,或者稍微提及一下使用到得官方插件,对于很多强力的扩展插件都没有介绍。
至今很多人用Maven2都处在摸索阶段,没看到谁总结出使用Maven2最佳实践。这点上,一般都是把国外开源项目中的pom.xml拿来研究学习。
5.
资源库不完整
一般来说,我们可以从Maven2的资源库上下载到我们所需要的第三方依赖库,但是有些依赖库在Maven2的资源库上是找不到的。
其中有因为发布协议的限制,比如j2ee的一些规范api。有因为项目所在厂商的原因,比如jbpm。有因为项目社区的问题,比如birt。还有很多情况是因为Maven2官方处理事情太慢,很多小型开源项目,比如dozer,虽然两个月前就已经提出了最新版本的上传申请,但是迟迟没有给予答复。
在这种情况下,我们只能自己在本地资源库中安装需要的依赖了,造成的问题是,如果相关的项目使用了Maven2的项目管理文件,那么可以使用Maven2 将项目发布到本地库中,这样一来就可以获得项目自身的依赖设置。如果相关项目没有使用Maven2的项目管理文件,那么需要自己再去为这个项目找到所需要的依赖,并配置到对应的pom文件中,着实非常麻烦。
6.
Maven2没有IDE支持
没有良好的IDE支持也是个大问题,虽然说有m2eclipse,但是实际上似乎没那么易用。
本身我们没有使用m2eclipse,而是使用maven2 + editplus的组合,不过介于广大开发者还是要用eclipse的,所以稍后我们还是会讨论到m2eclipse的相关知识。
follow steps 不用netbean,按照下文的指示手工操作。
http://dev.firnow.com/course/3_program/java/javajs/20090507/166773.html
碰到问题:
在执行 ant -f build.xml setup的时候会报一个错误
连接到端口1527上的服务器localhost 时出错,消息未connetion refused:connect
原因是java derby db 没有启动。
解决方法:启动它
<glassfish_dir>/bin/asadmin start-database
<glassfish_dir>指的是glassfish的安装目录
I got above error notes shows google take serious consideration about its security.
- must end with a new line
- Main-Class attribute is case sensitive
- file name is random, file extension is mf, eg. mymanifest.mf
- example jar command to package a app: jar cfm myapp.jar MANIFEST.MF *.*
eg:
Manifest-Version: 1.0
Main-Class: ButtonTest
When developing a Java program it is
important to select the appropriate Java Graphical User Interface (GUI)
components. There are two basic sets of components that you will most
likely build your Java programs with. These two groups of components
are called the Abstract Window Toolkit (AWT) and Swing. Both of these
groups of components are part of the Java Foundation Classes (JFC).
An Overview of the AWT
AWT stands for Abstract Window ToolKit. The Abstract Window Toolkit
supports GUI Java programming. It is a portable GUI library for
stand-alone applications and/or applets. The Abstract Window Toolkit
provides the connection between your application and the native GUI.
The AWT provides a high level of abstraction for your Java program
since it hides you from the underlying details of the GUI your program
will be running on.
AWT features include:
- A rich set of user interface components.
- A robust event-handling model.
- Graphics and imaging tools, including shape, color, and font classes.
- Layout managers, for flexible window layouts that don't depend on a particular window size or screen resolution.
- Data transfer classes, for cut-and-paste through the native platform clipboard.
The AWT components depend on native code counterparts (called peers)
to handle their functionality. Thus, these components are often called
"heavyweight" components.
An Overview of Swing
Swing implements a set of GUI components that build on AWT
technology and provide a pluggable look and feel. Swing is implemented
entirely in the Java programming language, and is based on the JDK 1.1
Lightweight UI Framework.
Swing features include:
- All the features of AWT.
- 100% Pure Java certified versions of the existing AWT component set (Button, Scrollbar, Label, etc.).
- A rich set of higher-level components (such as tree view, list box, and tabbed panes).
- Pure Java design, no reliance on peers.
- Pluggable Look and Feel.
Swing components do not depend on peers to handle their
functionality. Thus, these components are often called "lightweight"
components.
AWT vs. Swing
There are, of course, both pros and cons to using either set of
components from the JFC in your Java applications. Here is a summary:
AWT:
Pros
- Speed: use of native peers speeds component performance.
- Applet Portability: most Web browsers support AWT classes so AWT applets can run without the Java plugin.
- Look and Feel: AWT components more closely reflect the look and feel of the OS they run on.
Cons
- Portability: use of native peers creates platform specific
limitations. Some components may not function at all on some platforms.
- Third Party Development: the majority of component makers,
including Borland and Sun, base new component development on Swing
components. There is a much smaller set of AWT components available,
thus placing the burden on the programmer to create his or her own
AWT-based components.
- Features: AWT components do not support features like icons and tool-tips.
Swing:
Pros
- Portability: Pure Java design provides for fewer platform specific limitations.
- Behavior:
Pure Java design allows for a greater range of behavior for Swing
components since they are not limited by the native peers that AWT
uses.
- Features: Swing supports a wider range of features like icons and pop-up tool-tips for components.
- Vendor Support: Swing development is more active. Sun puts much more energy into making Swing robust.
- Look
and Feel: The pluggable look and feel lets you design a single set of
GUI components that can automatically have the look and feel of any OS
platform (Microsoft Windows, Solaris, Macintosh, etc.). It also makes
it easier to make global changes to your Java programs that provide
greater accessibility (like picking a hi-contrast color scheme or
changing all the fonts in all dialogs, etc.).
Cons
- Applet Portability: Most Web browsers do not include the Swing classes, so the Java plugin must be used.
- Performance:
Swing components are generally slower and buggier than AWT, due to both
the fact that they are pure Java and to video issues on various
platforms. Since Swing components handle their own painting (rather
than using native API's like DirectX on Windows) you may run into
graphical glitches.
- Look and Feel: Even when Swing components are set to use
the look and feel of the OS they are run on, they may not look like
their native counterparts.
- System event
- system timer
- system finish on an asynchronous event
- user event
- user move mouse
- user click mouse
- user input via keyboard
激励你一生的36句话
1、有识有胆,有胆有识,知识与胆量是互相促进的。
2、体育锻炼可以(有时可以迅速)使人乐观(科学实验证明)。
3、勤奋,机会,乐观是成功的三要素。(注意:传统观念认为勤奋和机会是成功的要素,但是经过统计学和成功人士的分析得出,乐观是成功的第三要素)
4、自信是人格的核心。
5、获得的成功越大,就越令人高兴。(野心是使人勤奋的原因,节制使人枯萎)
6、热爱你所拥有的。——列夫·托尔斯泰
7、(一般情况下)不想三年以后的事,只想现在的事(现在有成就,以后才能更辉煌)
8、把问题看宽广些,没有解决不了的事。(真理路广,人欲路窄;当然不要超越时代去想现在任何人都解决不了的事)
9、不问收获,只问耕耘。(如同种树,先有根茎,再有枝叶,尔后花实,好好劳动,不要想太多,那样只会使人胆小、懒惰)
10、忍耐和信仰
11、有恒则断无不成之事。
12、智慧之泉必须畅饮才能使人清醒。
13、生活的乐趣的大小取决于我们对生活的关心程度。
14、中年以前不要怕,中年以后不要悔。
15、机遇对于有准备的头脑有特别的亲和力。
16、守业最好的办法就是不断的发展
17、心急吃不了热汤圆
18、必死则生,幸生则死——《吴子兵法》(武经典籍中仅次于《孙子兵法》)
19、要改变命运,首先改变自己
20、走自己的路,让别人说去吧!
21、学习的关键——重复
22、只为成功找方法,不为失败找借口(蹩脚的工人总是说工具不好)
23、困难就是机遇——温斯顿·丘吉尔
24、我奋斗,所以我快乐——格林斯潘(挽救东南亚金融危机的人,我的偶像)
25、好奇者,知识之门
26、生气是用别人的错误惩罚自己。——康德(这个哲学家让人眉开眼笑)
27、失去金钱的人损失甚少,失去健康的人损失极多,失去勇气的人损失一切。
28、只要下定决心克服恐惧,便几乎能克服任何恐惧。因为,请记住,除了在脑海中,恐惧无处藏身。——戴尔·卡耐基
29、害怕时,把心思放在必须做的事情上,如果曾经彻底准备,便不会害怕。——戴尔·卡耐基
30、“不可能”这个字(法语是一个字),只在愚人的字典中找得到。——拿破仑
31、去做你害怕的事,害怕自然就会消失。——罗夫·华多·爱默生
32、这世上的一切都借希望而完成。农夫不会播下一粒玉米,如果他不曾希望它长成种籽;单身汉不会娶妻,如果他不曾希望有小孩;商人或手艺人不会工作,如果他不曾希望因此而有收益。——马丁·路德
33、目标的坚定是性格中最必要的力量泉源之一,也是成功的利器之一。没有它,天才也会在矛盾无定的迷径中,徒劳无功。——查士德斐尔爵士
34、要冒一次险!整个生命就是一场冒险。走得最远的人,常是愿意去做,并愿意去冒险的人。“稳妥”之船,从未能从岸边走远。——戴尔·卡耐基
35、当一个青年人站起来面对这个大莽汉——这个世界——并勇敢地抓住他的胡须时,常会吃惊地发现,胡须脱落在他手上,原来它只是系上去吓唬胆怯的冒险者的。——罗夫·华多·爱默生
36、勇气很有理由被当作人类德性之首,因为这种德性保证了所有其余的德性。——温斯顿·丘吉尔
Following is the syntax of vararg method.
public
void
testVar(
int
count, String... vargs) { }
String.. . actualy is a list of String.
You may use for(String s : vargs) to iterate through it.
Mainly used in Reflection API, when you do not know exactly how many parameters of a method has.
When evaluating open-source software for an enterprise Web or application
platform, the following are important considerations:
• Size and activity level of the open-source community. There is a lot happening in open source and the most popular projects (determined by downloads and community involvement numbers) are the ones that will likely survive and thrive, providing a steady stream of innovation
• Open-source license (not just free). Projects must have an open-source license (GPL, CDDL, Apache, etc.) that is endorsed by the Open Source Initiative (OSI—
http://www.opensource.org/) This is the only way to determine if it is truly open source; otherwise, it is just another proprietary license
• Active deployments. Are there other customers using this in production? You probably don’t want to be first unless there are compelling business reasons.
Linux + Apache + Mysql + PHP
May use the AOP function to modify the bytecode for java applications.