msgbartop
用铅笔写日记,记录那最原始的美丽
msgbarbottom

Google App Engine(谷歌应用程序引擎) JAVA 试用手册

就在前天吧,谷歌应用程序引擎(简称GAE)继python后,开放了对Java的支持.让人兴奋不已

比较Java是当今最流行的高级语言,在TIOBE的编程语言榜单上,JAVA已经蝉联了十几个月的冠军,这一点是毋庸置疑的。

相关链接: 4月编程语言排行榜

由于这个功能是刚刚开放的,所以用句通俗的话来讲,现在还在内测阶段。所以 必须向 谷歌申请,才能开通。

这个在你用 谷歌帐号 登录 GAE 时候 会发现,在页面上方会有黄色的提示。 只要点击 "sign me " 按钮就可以了。注意这个是有名额限制的,前1万名申请者才有资格开通,所以要抓紧呀

下面是引用GAE官方博客的声明:

we're giving the first 10,000 interested developers an early look at Java language support

之后,在你的注册邮箱里收到一封开通的通知,如图

至此,你的 GAE 就开始可以跑 JAVA 程序了,哈哈

要想你开发出的程序能在GAE上运行,首先得安装App Engine Java software development kit (SDK)

下面提供两种方法:

1.到这个地址:http://code.google.com/appengine/downloads.html 下载×××.msi 的安装包,安装即可。然后可以利用它自带的相关工具开发。这个方法,对于我这个酷爱绿色软件的人 不太适用。

2.安装 Google Plugin for Eclipse,这个我比较推荐,毕竟我们开发Java 大多用的都是这款开源的IDE。

下载地址是针对eclipse的两个版本,大家可以自行下载,

  • The Google Plugin for Eclipse, for Eclipse 3.3 (Europa):
    http://dl.google.com/eclipse/plugin/3.3
  • The Google Plugin for Eclipse, for Eclipse 3.4 (Ganymede):
    http://dl.google.com/eclipse/plugin/3.4

因为我的版本是 基于3.4.2的Ganymede,所以选择后者,打开eclipse-->help--->software update--->add site 输入地址,

再刷新一下,就可以看到谷歌GAE的插件了,如图

点击 Update 即可。 默认安装完毕后重启eclipse.

再打开eclipse 时候,会发现面板上多了一些图标,这些就是GAE的按钮。如图

点击 蓝色 小"g" 图标 创建 Web 应用 项目,这个就是 能在GAE上运行的程序的雏形。呵呵

新建项目的结构大体是:

ProjectName/
  src/
    ...Java source code...
    META-INF/
      ...other configuration...
  war/
    ...JSPs, images, data files...
    WEB-INF/
      ...app configuration...
      lib/
        ...JARs for libraries...
      classes/
        ...compiled classes...

其实如果你经常做JSP的项目会发现和它一样,只不过Webcontent 被改名为 War 了

如图:

现在我们要做的就是 像平时一样,写好自己的程序就可以了。

不过有一点要注意的是,在 war/WEB-INF下有个 appengine-web.xml,它是和将来程序在GAE上的具体设置有密切关系的,

主要是这两点:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>你的GEA ID名称</application>
    <version>程序的版本号</version>
</appengine-web-app>

更多的设置,比如 静态文件 和 资源文件,以及 是否开启session,ssl安全浏览 等,可以到下面这个地址去查看
URL:http://code.google.com/intl/zh-CN/appengine/docs/java/config/appconfig.html

这是我 appengine-web.xml 的设置情况(仅供参考),如图


在编写java 类是要用到GAE提供的包,如
packagepackageName;importjava.io.IOException;importjavax.servlet.http.*;importcom.google.appengine.api.users.User;importcom.google.appengine.api.users.UserService;importcom.google.appengine.api.users.UserServiceFactory;这些,大家可以参考GAE的api文档,在此不再多说

关于JSP页面,也与一般的web project 没两样,不过如果eclipse默认用的是JRE的话,是会报错的,
所以请确保eclipse的JRE System library是 JDK.

还有就是数据库,GAE提供两种类型的数据库访问,1 是
Java Data Objects (JDO),2 是 Java Persistence API (JPA). 具体信息可以参见:SUN的 技术文档 或 GAE文档 地址:http://code.google.com/intl/zh-CN/appengine/docs/java/datastore/usingjdo.html 想要实现对数据库的访问,得设置---位于src/META-INF目录下的 jdoconfig.xml文件. 具体内容如下: <?xml version="1.0" encoding="utf-8"?> <jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> <persistence-manager-factory name="transactions-optional"> <property name="javax.jdo.PersistenceManagerFactoryClass" value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/> <property name="javax.jdo.option.ConnectionURL" value="appengine"/> <property name="javax.jdo.option.NontransactionalRead" value="true"/> <property name="javax.jdo.option.NontransactionalWrite" value="true"/> <property name="javax.jdo.option.RetainValues" value="true"/> <property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/> </persistence-manager-factory> </jdoconfig> 在类里实现对数据库的列名声明方法简称POJOs(Plain Old Java Objects) 代码编写如下: packagepackageName;importjava.util.Date;importjavax.jdo.annotations.IdGeneratorStrategy;importjavax.jdo.annotations.IdentityType;importjavax.jdo.annotations.PersistenceCapable;importjavax.jdo.annotations.Persistent;importjavax.jdo.annotations.PrimaryKey;importcom.google.appengine.api.users.User;@PersistenceCapable(identityType=IdentityType.APPLICATION)publicclassGreeting{   @PrimaryKey   @Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)   privateLongid;   @Persistent   privateUserauthor;   @Persistent   privateStringcontent;   @Persistent   privateDatedate; 更多数据库语法,参见 http://code.google.com/intl/zh-CN/appengine/docs/java/datastore/dataclasses.html 而后,是数据在数据库里的物理,永久写入: 见实例代码: packagepackageName;importjavax.jdo.JDOHelper;importjavax.jdo.PersistenceManagerFactory;publicfinalclassPMF{   privatestaticfinalPersistenceManagerFactorypmfInstance=       JDOHelper.getPersistenceManagerFactory("transactions-optional");   privatePMF(){}   publicstaticPersistenceManagerFactoryget(){       returnpmfInstance;   }} 新建一个操作类,导入上面的相关类: 以日期为例,写入数据库 Datedate=newDate();       Greetinggreeting=newGreeting(user,content,date); // user,content 假设上面已定义       PersistenceManagerpm=PMF.get().getPersistenceManager();       try{            pm.makePersistent(greeting); //待jsp 页面传入       }finally{            pm.close();       } 在JSP页面的调用方法实现: 局部代码: <%   PersistenceManagerpm=PMF.get().getPersistenceManager();   Stringquery="select from "+Greeting.class.getName();   List<Greeting>greetings=(List<Greeting>)pm.newQuery(query).execute();   if(greetings.isEmpty()){%><p>目前无消息</p><%   }else{       for(Greetingg:greetings){           if(g.getAuthor()==null){%><p>匿名人士写道:</p><%           }else{%><p><b><%=g.getAuthor().getNickname()%></b>写道:</p><%           }%><blockquote><%=g.getContent()%></blockquote><%       }   }    pm.close();%>这样,一个GAE 程序访问数据库 操作的过程就完成了。 JDO操作数据库语句 叫做 JDOQL (和T-SQl 等差不多). 具体介绍见:http://code.google.com/intl/zh-CN/appengine/docs/java/datastore/queriesandindexes.html 接下来就是 静态文件 的问题,这个应该不成问题,所谓 静态文件 就是一些 无需改变的,如 图片,CSS样式表 等 而关于 静态文件 等的 声明在 appengine-web.xml 里面有详细说明,本人不再多说. 至此,一个 GAE JAVA 项目就算是完成了,待写好代码,测试完毕后,就可以通过 eclipse 的插件 上传到 GAE 服务器运行了了。 点击那个 蓝色小引擎 的图标 即可,如图:
至此,我们对 GAE JAVA 的第一次接触 到此结束了。

这是我上传的一个留言板测试页面,大家可以去看看, http://xia-zhengxin.appspot.com

PS:我发现了一个问题,貌似 GAE 对 中文的支持好像不太好,我在本地的中文字符,上传后都会变成了乱码。可能是还有什么没有设置好吧
但是 我的pageEncoding 和 charset 都改成了 gbk 或 utf-8,好像都不太有用。
现在问题得到了解决:
详见:http://www.jxva.com/blog/personal-diary/change-the-google-app-engine's-javac-compiler-encoding.html
原因是因为调用了系统默认的编码格式,而windows的默认字符编码不是 utf-8,所以导致中文变乱码了,呵呵
下载上面地址 人家提供的反编译好的application.class 文件,覆盖原来的,就OK了
不同的是:此人用的是SDK, 而我们用的是 plugin ,路径可能不一样。插件路径如下:
Eclipse路径\plugins\com.google.appengine.eclipse.sdkbundle_1.2.0.v200904062334\appengine-java-sdk-1.2.0\lib\appengine-tools-api.jar
 

谷歌音乐 上线啦

最近听说google 开通了在线音乐服务,但是不知道究竟是怎么个样子。最近看到国内各大新闻都在关注这件事情 前几天在cnbeta 上看到说正式上线了,一直没用过。 因为对于我这个只喜欢在本地硬盘上用播放器听歌的人来说,的确没什么诱惑力 不过,在谷歌之前,在线音乐&下载 貌似一直是 百度 的天下,这次不知道谷歌是不是要抢夺地盘啊,我本人也是百度mp3 的用户,也会经常搜索一些 或 下载 音乐. 于是,今天特地去用了下谷歌的这个新产品. 打开谷歌首页,发现 谷歌音乐 已经成为谷歌首推的服务 出现在了 下方 如图:

呵呵,看来谷歌对 这个是抱有了很大信心呀 点开之后,进入了 谷歌音乐的 页面,一个鲜明的logo 出现在 上方,我们可以清楚的看到 "测试"的字样

如图:

一看之下,发现内容还挺丰富的,有排行榜之类的

我试着搜索了一位歌手的名字,系统自动罗列出了他自出道以来的 所有发行的歌曲.

给人感觉很不错。 随机点了一首歌曲

便跳出网页播放器了,不过,在播放之前,用户得先同意一个协议,才能继续

如图:

这个 可能是 涉及到版权问题,同意便是. 毕竟人家提供的是正版的音乐试听

播放速度貌似也不错,如果觉得歌曲不错,还可以下载到本地。

如图:

看看 文件大小,果真是正版的音乐呀,和我们从CD里面提取出来的 分毫不差

哈哈,以后再也不用 花冤枉钱去买 周董的 专辑啦.

_________________________________________

相关链接:
谷歌签约四大唱片公司 将发布音乐搜索正式版

SourceForge.net Update: 2009-03-31 Edition

SF三月份monthly newsletter 来了

NOTAPAD++ 荣登榜首.

== Statistics and Top Projects ==

Daily SourceForge.net Stats for 30-Mar-2009:

9,288,349 pages served
2,658,463 files downloaded
117 new projects approved

Top 25 Projects on 30-Mar-2009:

1. Notepad++
http://sourceforge.net/projects/notepad-plus
Notepad++ is a generic source code editor (it tries to be anyway) and
Notepad replacement written in c++ with win32 API. The aim of Notepad++ is
to offer a slim and efficient binary with a totally customizable GUI.

2. Openbravo ERP
http://sourceforge.net/projects/openbravo
Openbravo ERP is a Web based ERP for SME, built on proven MVC & MDD
framework that facilitate its customization. | IMPORTANT NOTICE. Openbravo
ERP project has been migrated to a new home
http://forge.openbravo.com/projects/openbravoerp

3. ADempiere ERP Business Suite
http://sourceforge.net/projects/adempiere
ADempiere Business Suite ERP/CRM/MFG/SCM/POS done the Bazaar way in an open
and unabated fashion. Focus is on the Community that includes Subject
Matter Specialists, Implementors and End-Users. We are a community fork of
Compiere.

4. ZK - Simply Ajax and Mobile
http://sourceforge.net/projects/zk1
ZK is Ajax Java framework without JavaScript. With direct RIA, 200+ Ajax
components and markup languages, developing Ajax/RIA as simple as desktop
apps and HTML/XUL pages. Support JSF/JSP/JavaEE/Hibernate/.., and Ajax
script in Java/Ruby/Groovy/Python/..

5. Zenoss Core - Enterprise IT Monitoring
http://sourceforge.net/projects/zenoss
Zenoss Core is an enterprise network and systems management application
written in Python/Zope. Zenoss provides an integrated product for
monitoring availability, performance, events and configuration across
layers and across platforms.

6. MediaInfo
http://sourceforge.net/projects/mediainfo
Get technical information and tags of a lot of multimedia files. Supported
formats : - Video : AVI/OGM/MKV/MPG/VOB/MP4/3GP/... - Audio :
MP3/OGG/MKA/MP4/AAC/...

7. PostBooks ERP, accounting, CRM by xTuple
http://sourceforge.net/projects/postbooks
Free open source ERP, accounting, CRM package for small to midsized
businesses. ERP client runs on Linux, Mac, and Windows (built with open
source Qt framework). Business logic resides in PostgreSQL database.
International ERP, accounting, and CRM tools.

8. Mumble
http://sourceforge.net/projects/mumble
Low-latency, high-quality voice communication for gamers. Includes game
linking, so voice from other players comes from the direction of their
characters, and has echo cancellation so the sound from your loudspeakers
won't be audible to other players.

9. phpMyAdmin
http://sourceforge.net/projects/phpmyadmin
phpMyAdmin is a tool written in PHP intended to handle the administration
of MySQL over the Web. Currently it can create and drop databases,
create/drop/alter tables, delete/edit/add fields, execute any SQL
statement, manage keys on fields.

10. ffdshow tryouts
http://sourceforge.net/projects/ffdshow-tryout
ffdshow is a DirectShow filter and VFW codec for many audio and video
formats, such as DivX, Xvid and H.264. Over 70 bugs have been fixed, codecs
have been updated, and support for a few new formats has been added in the
tryouts. Vista is now supported.

11. webERP web-based ERP Accounting
http://sourceforge.net/projects/web-erp
Integrated accounting ERP system. Multi-language/currency/inventory
locations. Full double entry. SO/AR/PO/AP/GL/Bank/Sales Analysis.
BOMs/assemblies/kit-sets. Flexible pricing. Emailable pdf reports. Fast PHP
created html for any browser.

12. OrangeHRM - Human Resource Management
http://sourceforge.net/projects/orangehrm
OrangeHRM is an Open Source Human Resource Management System that covers
Personnel Information Management, Employee Self Service, Leave, Time &
Attendance, Benefits, and Recruitment. Tags: HRM, HRMS, HCM, HRIS, EHRMS,
Human Capital Management

13. Stellarium
http://sourceforge.net/projects/stellarium
Stellarium renders 3D photo-realistic skies in real time with OpenGL. It
displays stars, constellations, planets, nebulas and others things like
ground, landscape, atmosphere, etc.

14. KeePass Password Safe
http://sourceforge.net/projects/keepass
KeePass Password Safe is a free, open source, light-weight and easy-to-use
password manager for Windows. You can store your passwords in a
highly-encrypted database, which is locked with one master password or key
file.

15. Azureus
http://sourceforge.net/projects/azureus
Azureus: Vuze is a powerful, full-featured, cross-platform bittorrent
client and open content platform.

16. Sweet Home 3D
http://sourceforge.net/projects/sweethome3d
Sweet Home 3D is an interior design Java application for quickly choosing
and placing furniture on a house 2D plan drawn by the end-user, with a
final 3D preview.

17. WinMerge
http://sourceforge.net/projects/winmerge
WinMerge is a Windows tool for visual difference display and merging, for
both files and directories. Unicode support. Flexible syntax coloring
editor. Windows Shell integration. Regexp filtering. Side-by-side line diff
and highlights diffs inside lines.

18. ScummVM
http://sourceforge.net/projects/scummvm
ScummVM is a cross-platform interpreter for several point-and-click
adventure engines. This includes all SCUMM-based adventures by LucasArts,
Simon the Sorcerer 1&2 by AdventureSoft, Beneath a Steel Sky and Broken
Sword 1&2 by Revolution, and many more.

19. Fink
http://sourceforge.net/projects/fink
Fink is an attempt to bring the full world of Unix OpenSource software to
Darwin and Mac OS X. Packages are downloaded and built automatically and
installed into a tree managed by dpkg, all with full dependency tracking.

20. TCPDF - PHP class for PDF
http://sourceforge.net/projects/tcpdf
TCPDF is a PHP class for generating PDF documents without requiring
external extensions. TCPDF Supports UTF-8, Unicode, RTL languages and HTML.

21. PortableApps.com: Portable Software/USB
http://sourceforge.net/projects/portableapps
PortableApps.com allows you to carry your favorite computer programs and
all of your bookmarks, settings, email and more with you on a portable
device (USB flash drive, iPod, portable hard drive, CD, etc) and use them
on any Windows computer.

22. JMRI Model Railroad Interface
http://sourceforge.net/projects/jmri
Java interfaces and sample implementations for controlling a model railroad
layout from a personal computer.JMRI is intended as a jumping-off point for
hobbyists to build their own layout controls. Includes the DecoderPro and
PanelPro applications.

23. FreeMind
http://sourceforge.net/projects/freemind
A mind mapper, and at the same time an easy-to-operate hierarchical editor
with strong emphasis on folding. These two are not really two different
things, just two different descriptions of a single application. Often used
for knowledge and content mgmt.

24. Gallery
http://sourceforge.net/projects/gallery
A slick, intuitive web based photo gallery. Gallery is easy to install,
configure and use. Gallery photo management includes automatic thumbnails,
resizing, rotation, and more. Authenticated users and privileged albums
make this great for communities.

25. Audacity
http://sourceforge.net/projects/audacity
A fast multi-track audio editor and recorder for Linux, BSD, Mac OS, and
Windows.Supports WAV, AIFF, Ogg, and MP3 formats.Features include envelope
editing, mixing, built-in effects and plug-ins, all with unlimited undo.

sf项目主页全攻略

很多在 Sourceforge.net 上做项目的朋友,大多会忽视的一个服务----就是SF免费提供的 项目主页的功能。

其实,有一个类似于 xxx.sourcefoge.net  的主页,对自己项目的宣传也不是一件坏事呀,哈哈。而且SF提供的Virtual Host 功能非常优质,几乎支持所有语言,如  PHP (via mod_php), Perl, Python, Tcl, Ruby, and shell scripts.

不支持的很少,是

  • SSL (encryption)
  • SF.net User Authentication
  • JSP (programming language) support
  • Microsoft Front Page and Extensions
  • Dreamweaver Remote Admin support
  • 并且还提供 mysql 数据库支持,还可以用自己的域名去访问,只需要做一下A ,Cname记录:

    Using the tools provided by your DNS provider, configure the following:

    • yourdomain.com should be a IN A to 216.34.181.97.
    • www.yourdomain.com should be a CNAME to vhost.sourceforge.net.
    • cvs.yourdomain.com should be a CNAME to PROJECTNAME.cvs.sourceforge.net.

    把自己在本地做好的网页文件上传到空间里面,有两种途径。

    1.通过sftp----比较简易,功能较少

    就拿putty 套件里面的PSFTP.EXE 来说,打开后 ,输入 "open 用户名,项目名@web.sourceforge.net"   回车。再输入密码就可以了

    如图:

     

    2.就是通过shell.sourceforge.net 访问.

    Project shell server: shell.sourceforge.net

    PROJECTNAME.cvs.sourceforge.net

    PROJECTNAME.svn.sourceforge.net

    这个要用到SSH,首先得生成一个SSH Key ,我们可以用putty 套件里面的 PUTTYGEN.EXE, 运行后 在parameter 里选择 "SSH2 DSA". 然后点击 "Generate" 按钮,你所要做的事是:把鼠标指针在 上方空白处 晃动,以便随机生成KEY,完了后在Key comment 处 填上 "用户名@shell.sourceforge.net" ,最后 点击 "Save private key" 保存为 *.ppk 文件. 

    注:"Key passphrase " 和 "Confirm passphrase" 可以不填。

    如图:

    现在你要做的是:把 上方  "Public key for pasting into OpenSSH authorized_keys2 file" 框里面的所有字符复制下来。

    然后,登录你的sf帐号,切换到 "Account Options",  在 “Host Access Information ” 处点击 [Edit SSH Keys for Shell/CVS], 把 复制的字符粘贴进去。点击 update 即可。

    注:如果是两个KEY或者多个的话,要确保KEY与KEY之间有且只有一个回车,KEY中间不能有空格.

    如图:

    如果没有错误的话,应该会即时显示出 SSH key 的数量。如图

    SSH KEY 生效大概只要几分钟就可以了,很快的

    好了后就要去激活 SSH shell. 我们要用到PUTTY 套件里面的 PAGEANT.EXE 和 PUTTY.EXE.

    首先,运行PAGEANT.EXE ,在任务栏找到它,双击,点击 "Add Key ",浏览到先前保存的 *.ppk ,确定即可。

    如图:

    然后,运行 putty.exe , 注意:在此后的操作都建立在 Key Agent 基础上,所以 PAGEANT.EXE  不能关闭.

    设置putty,见下面的表格

    Session Host Name: "shell.sourceforge.net"
    Session Connection Type: "SSH"
    Connection > SSH > TTY uncheck "Don't allocate a pseudo-terminal"
    Connection > SSH Remote command: "create"
    Connection > Data Auto-login username: "用户名,项目名"

    如图:

    在 链接之前,先要确保该用户拥有访问此项目shell的权限,这个可以在项目里面的"Projece Admin"   里面的"Membership"看到。如图

    然后,点击 open 即可 登录激活 shell.

    成功 如图:

    之后,就可以用WINSCP登录shell,进入我们熟悉的图形界面了

    登录成功后,就可以像管理FTP一样管理项目网站的文件了

     

    -END -

    ghs.google.com 正常了

    具体是什么原因不知道,我也猜不出来

    什么也不说了,一切都在截图里

    [caption id="" align="alignnone" width="508" caption="ping"]ping[/caption]

    .
    .
    .
    .
    .

    [caption id="" align="alignnone" width="561" caption="trace route"]trace route[/caption]