2010年3月20日星期六

在 Ubuntu 下安装 SUN JDK 6 和 Eclipse

在Ubuntu下安装JDK 6和Eclipse

开发笔记:在Ubuntu下安装JDK 6和Eclipse 
首先需要安装JDK 6 
sudo apt-get install sun-java6-jdk 

之后需要设置默认的java程序 
sudo update-alternatives --config java 
按照提示输入对应的选项,指定为JDK 6 

下面设置 
sudo vim /etc/environment 

在其中添加如下两行: 
CLASSPATH=/usr/lib/jvm/java-6-sun/lib 
JAVA_HOME=/usr/lib/jvm/java-6-sun 
如果其中已经设置了CLASSPATH和JAVA_HOME,则将其修改为上面的形式,保存退出。 

接下来安装Eclipse 
sudo apt-get install eclipse 

需要注意的是,此时Eclipse并不关心之前设置的update-alternative 

所以应该修改Eclipse的配置。首先将 SUN-JDK-6彻底设为系统默认: 

sudo update-java-alternatives -s java-6-sun 

然后编辑JVM配置文件: 
sudo vim /etc/jvm 

在文件顶部添加 
/usr/lib/jvm/java-6-sun 
(如果没有则自己新建) 

sudo vim /etc/eclipse/java_home 

也是在文件顶部添加 
/usr/lib/jvm/java-6-sun 

之后启动Eclipse,选择Help->About Eclipse SDK,选择Configuration Details,可以看到JDK6的设置已经生效。 

ubuntu下设置华文黑体

如何安装Mac的华文黑体来美化汉字的显示:
(1)先到这里sthei.ttf.gz去下载sthei.ttf字体,解压;
(2)把它copy到"/usr/share/fonts/custom/cn"目录下;fonts下没有custom/cn目录就先建一个
(3)减少中文字体过度渲染:sudo fontconfig-voodoo -f -s zh_CN
(4)修改字体配置文件,加入sthei字体:sudo gedit /etc/fonts/language-selector.conf;在<family>Bitstream Vera Sans</family>行下面添加:<family>STHeiti</family>保存后退出
(5)强制刷新字体缓存:sudo fc-cache -f -v
(6)系统 -首选项 � 字体:设置所有非等宽字体为 Bitstream Vera Sans 10号,其中窗口标题字体设置为粗体。等宽字体设置为Courier 10 Pitch,在AA时,Courier 10 Pitch比Courier New字体更清楚。
(7)顶顶重要的:在"字体渲染"中,选择"细节","平滑"设置为"灰度","微调"设置为"无"。
(8)打开firefox,设置firefox字体,无衬线字体:Bitstream Vera Sans;等宽字体:Courier 10 Pitch 大小:13;其它的可以不改。
(9)退出当前登录,重新登录。一切OK了。

以上来自我2006年在donews的博客。现在网站已经打不开来。好在还有google cache。
最关键的是box.net的文件共享依然还在,每当有人下载了我共享的华文黑体,它都会发一封邮件给我。
作为一个美国网站,免费到为一个中国人提供来长达5年的免费文件寄存服务,这是怎样的一种精神病啊!
类似这样到外国公司,你们要把他们赶出中国去,你们连精神病都不如。

2010年2月22日星期一

GAE(Google App Engine) 对 struts Spring 等的支持情况

完整描述见这里:(要fuckgfw)
http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine

Spring MVC
Version: 2.5.6
Status: COMPATIBLE
To see Spring's MVC framework running on App Engine, check out the autoshoppe sample application.
If you're using Spring forms (e.g. using the spring-form.tld tag library and subclassing SimpleFormController), you will need to register custom editors for your properties. This is covered in http://groups.google.com/group/google-appengine-java/browse_thread/thread/d93fd7385bf85bf7.

Spring ORM
Version: 2.5.6
Status: COMPATIBLE
To get Spring working with the App Engine-provided JPA interface, follow the instructions at http://objectuser.wordpress.com/2009/05/19/spring-jpa-in-google-app-engine/, which discusses a workaround to the dependency on javax.naming needed for @PersistenceContext. A more complex workaround is available at http://groups.google.com/group/google-appengine-java/browse_thread/thread/187d41712ec1d394.

Spring Security
Version(s): ?
Status: SEMI-COMPATIBLE
To work around a ClassNotFoundException, you can use a re-compiled version of the library which adds a StringInsensitiveComparator class -- the download is provided at http://www.google-app-engine.com/blog/post/Spring-security-fix-for-google-app-engine.aspx.
See http://www.dotnetguru2.org/bmarchesson/index.php?p=1100 for tips on how to get Spring Security running with App Engine and GWT (in French).

Stripes Framework
Version(s): ?
Status: COMPATIBLE
The default multipartwrapper implementation needs a temporary directory on the local file system for file uploads, which App Engine doesn't allow. The workaround is to create your own implementation -- more details at http://groups.google.com/group/google-appengine-java/browse_thread/thread/81dbcf7cf2281014.

Struts 1
Version: 1.2.28
Status: COMPATIBLE

Struts 2
Version(s): ?
Status: COMPATIBLE (see notes)
Struts will not initially work because the OGNL permissions which the framework relies on can't be set due to security restrictions in App Engine's sandbox. However, some users have documented a workaround at http://groups.google.com/group/google-appengine-java/browse_thread/thread/19018b0317f27817.
A tutorial on uploading files using Struts running on App Engine is available at http://whyjava.wordpress.com/2009/10/04/file-upload-on-google-app-engine-using-struts2/.
Will need to set devMode to false in struts.xml: <constant name="struts.devMode" value="false" />


这个人的博客上也描述了如何使用 Struts 2 with App Engine:

还有这个博客,关于GAE、Spring、JPA、JDO 内容非常丰富:(要fuckgfw)

  • Spring + JDO in Google App Engine
  • 17 Minute JDO!
  • Spring + JPA in Google App Engine
  • More on Spring Security in Google App Engine
  • Spring Security in Google App Engine
  • Google App Engine Testing with Spring
  • Queries in GAE: One to Many Relationships
  • Google App Engine
  • Queries in GAE: Many to Many Relationships
  • Queries in GAE: One to One Relationships

Spring + JPA in Google App Engine


I've been playing around with Google App Engine because it's new and cool and has some interesting possibilities. However, it's in a preview mode currently and has some limitations, as expected.

One difficulty I encountered was getting Spring (2.5.6) to work nicely with the App Engine-provided JPA. But now I have it working. Here's how.

The basic problem is that PersistenceAnnotationBeanPostProcessor has a dependency on javax.naming. But that's the thing you need to get @PersistenceContext to work. And you want that to work because you want to be able to have transactions that span DAOs (or, at least, I wanted that).

That dependency is easy to resolve, however. Just grab the source to PersistenceAnnotationBeanPostProcessor, put it in your own package, and replace the catch blocks with NamingException with just Exception … you won't be using those things anyway.

Now, use that bean in your context configuration file.
<bean id="persistienceAnnotationBeanPostProcessor"
class="your.package.name.PersistenceAnnotationBeanPostProcessor" />

Finally, use the @PersistenceContext annotation in your DAO just like it says in the Spring documentation:
@PersistenceContext
private EntityManager entityManager;

You're done. Thank me.

Update 5/25: As Alex points out I spelled the bean ID incorrectly. However, that was right from my code, so the id doesn't really matter. In fact, now I have:
<bean class="your.package.name.PersistenceAnnotationBeanPostProcessor" />

2010年2月5日星期五

Oralce游标定义、游标变量、游标循环的实际例子


--给销售订单加上行号
--同一个单据号(djh)之内,行号(rowno)按照10的步长来编号
--新单据号,行号要重新从10开始
declare
--本例子演示了Oralce游标定义、Oracle游标变量、Oracle游标循环
--以及在游标里面更新数据库的技巧
cursor cc is select nno,djh,rowno
from temp_so order by nno;
--定义游标变量
ccrec cc%rowtype;
--定义自己的变量
irowno number;
idjh varchar2(50);
begin
--打开游标
open cc;
--提取一行数据到ccrec中
fetch cc into ccrec;
--判断是否提取到值,没取到值就退出
--取到值cc%notfound 是false
--取不到值cc%notfound 是true
idjh := ccrec.djh;
irowno:=10;
loop --loop循环
--exit when (cc%notfound or cc%rowcount =300);
exit when (cc%notfound);

if (idjh = ccrec.djh) then
update temp_so set temp_so.rowno = irowno where temp_so.nno = ccrec.nno;
--dbms_output.put_line(cc%rowcount||' '||ccrec.djh||' '||idjh||' '||irowno);
else
irowno:=10;
idjh := ccrec.djh;
update temp_so set temp_so.rowno = irowno where temp_so.nno = ccrec.nno;
-- dbms_output.put_line(cc%rowcount||' '||ccrec.djh||' '||idjh||' '||irowno);
end if;
fetch cc into ccrec;
irowno:=irowno+10;
end loop;
close cc;
commit;
end;


-------------------
A Contre Courant