爪哇岛的一个山洼。

2006-11-28

【技术心得】采用编程的方式将当前Persptive

采用编程的方式切换当前的Persptive,代码如下:

String resourcePesId = "org.eclipse.ui.resourcePerspective";
// get Perspective Registry
IPerspectiveRegistry registry = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getWorkbench()
.getPerspectiveRegistry();
// find Resource Perspective with extenion Id
IPerspectiveDescriptor pd = registry
.findPerspectiveWithId(resourcePesId);
// get current active perspective
IPerspectiveDescriptor currentPerspective = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getPerspective();
// testing current perspective is "Resource Perspective" ,not then show
// it.
if (!resourcePesId.equals(currentPerspective.getId())) {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getWorkbench()
.getActiveWorkbenchWindow().getActivePage().setPerspective(
pd);
}

【技术心得】如何让GWT运行在Tomcat中

OK got it running on Tomcat. Here are the steps

1. Strip the javax.* packages from gwt-user.jar . You can do it with
winzip/winrar etc. Open the jar in such tools and delete all files in
javax folder including the folder


2. Copy the stripped jar in your webapps/YourApp/WEB-INF/lib. Copy the
compiled classes (e.g copy the folder "com" in samples/dynatable/bin )
to webapps/YourApp/WEB-INF/classes


3. Modify your Service Entry point code (if required). Note the text
you put in place /calendar line. You will use this text in web.xml
later
ServiceDefTarget target = (ServiceDefTarget) calService;
String staticResponseURL = GWT.getModuleBaseURL();
staticResponseURL += "/YourApp/calendar";
target.setServiceEntryPoint(staticResponseURL);
4. Run DynaTable-compile.cmd (replace dynatable with app name). File
will be generated in www\com.google.gwt.sample.dynatable.DynaTable\ .
Copy all files within this folder to webapps/YourApp/


5. Create modify web.xml and place it in WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<web-app>


<servlet>
<servlet-name>SchoolCalendarService</servlet-name>


<servlet-class>com.google.gwt.sample.dynatable.server.SchoolCalendarService-Impl</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>SchoolCalendarService</servlet-name>
<url-pattern>/calendar</url-pattern>
</servlet-mapping>


</web-app>
5. Launch tomcat. Open browser e.g.
localhost:8080/YourApp/DynaTable.html
6. Enjoy

2006-11-23

【java教程】实践MDA之AndroMDA教程:[第六节]代码生成

执行生成代码命令

在模型设计好并且工程配置完成以后,就可以进行代码生成了。在第二节中,我们介绍过一些的常用命令,其中的各个命令均可以组合着使用。
下面按照第二节中在UltraEdit执行命令的方法,执行 maven install 命令,代码生成工具将首先验证模型,在这个过程中,可能会提示一些模型的错误信息,这些错误信息都是由于模型的某个地方不符合规范造成的。因此,如何有错误提示,则先修改模型,在执行 maven install 命令,直到验证通过为止。
验证通过以后,就会生成代码。在工程的目录结构中,core/src 下面的文件是可以修改的,也是我们填写业务逻辑方法实现的地方,代码生成工具将不会覆盖此目录下面的文件,而 core/target 下面的文件是不可以修改的,每次重新生成代码的时候,代码生成工具将覆盖该目录下面的文件。
在重复生成代码的时候,可以加上 clean 命令,首先清空(不会清空 core/src 下面的文件)以前生成的代码,然后生成的代码。
当模型验证通过,并且 core/src 下面业务逻辑已经编写测试完成,那么此时执行 maven clean install ,代码生成工具将把应用程序以jar包的方式安装在 maven 的 repository 里面,例如在我本地的 C:\Documents and Settings\Administrator\.maven\repository\CarManagement\jars\ 目录下面,代码生成工具安装了 CarManagement- common- 1.0.jar 和 CarManagement-core-1.0.jar 两个文件。

如何使用

代码生成工具产生的两个jar包,能够很方便的在其他各个工程里面使用。通过一个 ServiceLocator 类可以获取到各个 Service 对象,例如可以用下面语句获取到 UserService 对象:
UserService userService = ServiceLocator.instance().getUserService();
获取到 Service 对象以后,就可以使用 Service 里面定义的各种方法了。

总结

实践 MDA 的 AndroMDA 教程到此结束了,该教程主要以一个示例为主线来介绍 AndroMDA 代码生成工具的使用过程,是作者对使用过程的一个回顾和总结,难免存在很多错误和不妥的地方,欢迎大家指出并充分交流。

教程中的示例代码可以到 http://www.javava.org/prima/java_tutorial.html 进行下载。

2006-11-22

【技术心得】Puzzles on getting start GWT and eclipse.

于此主题的全部 10 个帖子 - 树式浏览
发件人: jack.tang - 查看个人资料
日期: 2006年5月19日(星期五) 上午2时26分
电子邮件: "jack.tang"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


>From the document


http://code.google.com/webtoolkit/gettingstarted.html#New.
It said:
Just click the green "Run" button at the top of the window to start
your project in hosted mode.

And I wonder what it exactly to "Run", you know, there is drop-down
list in "Run" button, and what Class should specified? or I lost
something?


Thanks
/Jack


回复 为此帖评分: Text for clearing space





发件人: Mr. Monster - 查看个人资料
日期: 2006年5月19日(星期五) 上午2时32分
电子邮件: "Mr. Monster"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


You missed something, if you follow the instructions exactly and click
Run it will start up the example app. No need to configure anything
inside eclipse.

回复 为此帖评分: Text for clearing space





发件人: jack.tang - 查看个人资料
日期: 2006年5月19日(星期五) 上午2时40分
电子邮件: "jack.tang"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


Well, can you explain how to hook hosted browser into eclipse manually?
using MyApplication.launch?

回复 为此帖评分: Text for clearing space





发件人: Roux - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时02分
电子邮件: "Roux"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


It doesn't work for me either. The directions are either wrong,
incomplete, or don't work with every version of eclipse.

回复 为此帖评分: Text for clearing space





发件人: jack.tang - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时07分
电子邮件: "jack.tang"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


When I click "Run" button, it always run the first application in the
drop list and the *.launch doesnot work at all. How to load the
*.launch, anyone knows?

回复 为此帖评分: Text for clearing space





发件人: Adrian Marti - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时17分
电子邮件: "Adrian Marti"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


in the docs it says to use com.google.gwt.dev.GWTShell as the startup
class, which may mean main class for Run dialog? I tried this but had a
null pointer on logging setup.
Caused by: java.lang.NullPointerException
at org.apache.commons.logging.LogFactory.newFactory

回复 为此帖评分: Text for clearing space





发件人: jack.tang - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时18分
电子邮件: "jack.tang"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


Well, I think I found something.
The main class is com.google.gwt.dev.GWTShell, which hosts in
gwt-dev-windows.jar. It is missed in the tutorial. and
swt-win32-3139.dll should be in the same dir as gwt-dev-windows.jar.
You can try to run it.

But,still, i don't have to hook the *.launch:(


回复 为此帖评分: Text for clearing space





发件人: drusifer - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时24分
电子邮件: "drusifer"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


I was having a similar issue originally too. When I pressed Run it
just ran my other project. Then I went into the "Run..." dialogue and
noticed that a new Runner was set up for my GWT project and that one
worked.
-Drusifer

回复 为此帖评分: Text for clearing space





发件人: jack.tang - 查看个人资料
日期: 2006年5月19日(星期五) 上午3时27分
电子邮件: "jack.tang"
评级: (2 位用户)
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子


Bingo! I got the answer!

eclipse 3.1.1
pls copy MyApplication.launch to
{eclipse.home}\.metadata\.plugins\org.eclipse.debug.core\.launches


And you will find MyApplication in the "Run" list, Runnnnn it....


回复 为此帖评分: Text for clearing space





发件人: dealyb - 查看个人资料
日期: 2006年5月19日(星期五) 上午4时34分
电子邮件: "dealyb"
尚未评分评级:
显示选项
回复 答复作者 转发 打印 显示个别帖子 显示原始邮件 报告滥用行为 查找此作者的帖子



jack.tang wrote:
> >From the document
> http://code.google.com/webtoolkit/gettingstarted.html#New.
> It said:
> Just click the green "Run" button at the top of the window to start
> your project in hosted mode.

> And I wonder what it exactly to "Run", you know, there is drop-down
> list in "Run" button, and what Class should specified? or I lost
> something?


> Thanks
> /Jack



Hi Jack, when I launch the configuration page reads
com.google.gwt.dev.GWTShell for the main class
and my project name "opportunity" under the project
tab with no checkboxes checked. and this launches
the hosted mode for me. I hope this helps you.
regards,
Brian

回复 为此帖评分: Text for clearing space





帖子的结尾

【技术心得】如何从应用服务器的数据源中获取jdbc连接

从应用服务器数据源中获取jdbc连接,在很多时候非常有用,例如使用该连接直接访问数据库做特殊处理,或者提供给报表工具使用等等。利用数据源中提供的连接,使得在效率上有很大的提高。

代码如下:


/**
* 从应用服务器获取指定名称的数据源
*
* @return
* @throws Exception
*/
public static Connection getConnFromDS(String dsName)
throws Exception
{
Connection conn = null;
try
{
Context context = new InitialContext();
DataSource ds = (DataSource) context.lookup(dsName);
conn = ds.getConnection();
System.out.println("获取数据源[" + dsName + "]成功 ... ...");
} catch (Exception e)
{
System.err.println("获取数据源[" + dsName + "]失败,尝试直接使用jdbc连接...");
e.printStackTrace();
}
return conn;
}

【记录备份】jar命令的详细使用说明

jar {ctxu}[vfm0Mi] [jar/war-文件] [manifest-文件] [-C 目录] 文件名 ...
选项:
-c 创建新的存档
-t 列出存档内容的列表
-x 展开存档中的命名的(或所有的〕文件
-u 更新已存在的存档
-v 生成详细输出到标准输出上
-f 指定存档文件名
-m 包含来自标明文件的标明信息
-0 只存储方式;未用ZIP压缩格式
-M 不产生所有项的清单(manifest〕文件
-i 为指定的jar文件产生索引信息
-C 改变到指定的目录,并且包含下列文件:
如果一个文件名是一个目录,它将被递归处理。
清单(manifest〕文件名和存档文件名都需要被指定,按'm' 和 'f'标志指定的相同顺序。
示例1:将两个class文件存档到一个名为 'classes.jar' 的存档文件中:
jar cvf classes.jar Foo.class Bar.class
示例2:用一个存在的清单(manifest)文件 'mymanifest' 将 foo/ 目录下的所有
文件存档到一个名为 'classes.jar' 的存档文件中:
jar cvfm classes.jar mymanifest -C foo/ .