Apache Pivot初体验(二)

上一篇我们探究了如何构建Pivot开发框架,编写Pivot桌面应用程序。这一篇我们来说说如何在web环境中部署Pivot程序。webapp发布目录 如下所示:
[img]http://dl.iteye.com/upload/attachment/202821/8d827b01-94e3-367b-a2d2-b62739360fab.jpg[/img]
css中的样式表和js下的JavaScript脚本都是根据官方示例中拷贝下来的,其中最重要的是deployJava.js,它是展示Java applet的工具包,Pivot在页面中就是以Applet的形式展现的,js文件在http://java.com/js/deployJava.js 下载。Lib下是Pivot应用所依赖的类库,可以看出pivot.jar是我自定义的jar,就是编好代码打的包,而WEB-INF/lib下的库和Pivot没有关系,那里的库正常是访问不到的。
下面展示HTML页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>Push Buttons</title>
<script src="/pivot/js/deployJava.js" type="text/javascript"></script>
</head>
<body>
<script xmlns="" type="text/javascript">
var attributes = {
code:'org.apache.pivot.wtk.BrowserApplicationContext$HostApplet',
width:'480',
height:'360'
};
var libraries = [];
libraries.push("/pivot/lib/pivot-core-1.4.jar");
libraries.push("/pivot/lib/pivot-wtk-1.4.jar");
libraries.push("/pivot/lib/pivot-wtk-terra-1.4.jar");
libraries.push("/pivot/lib/pivot.jar");
attributes.archive = libraries.join(",");
var parameters = {
codebase_lookup:false,
java_arguments:'-Dsun.awt.noerasebackground=true -Dsun.awt.erasebackgroundonresize=true',
application_class_name:'pivot.tutorials.buttons.PushButtons'
};
deployJava.runApplet(attributes, parameters, "1.6");
</script>
</body>
</html>

关键是JS段代码,其实都是固定套路,只需修改自定义的jar即可,其他段根据字母意思即可理解,关键是lib库的位置一定要对。下面说说ANT打包。
<?xml version="1.0" encoding="UTF-8" ?>
<project name="pivot" default="all">
<description>The Pivot Application</description>
<!-- 定义文件夹 -->
<property name="srcDir" location="." />
<property name="classDir" location="../webapp/WEB-INF/classes" />
<property name="libDir" location="../webapp/WEB-INF/lib" />
<property name="webDir" location="../webapp" />
<!--用于输出打包的文件夹-->
<property name="tempDir" location="${java.io.tmpdir}/${ant.project.name}" />
<property name="targetDir" location="../target" />
<!-- 定义classpath -->
<path id="master-classpath">
<fileset file="${libDir}/*.jar" />
<pathelement path="${classDir}" />
</path>
<!-- 执行清理 -->
<target name="clean">
<delete dir="${classDir}" />
<delete dir="${tempDir}" />
<delete file="${targetDir}/${ant.project.name}.jar" />
<delete file="${targetDir}/${ant.project.name}.war" />
<delete dir="${targetDir}" />
</target>
<!-- 初始化任务 -->
<target name="init" depends="clean">
<mkdir dir="${targetDir}" />
<mkdir dir="${tempDir}" />
<mkdir dir="${classDir}" />
</target>
<!-- 编译 -->
<target name="compile" depends="init" description="compile the source files">
<javac srcdir="${srcDir}" destdir="${classDir}" debug="true" encoding="UTF-8">
<classpath refid="master-classpath" />
</javac>
<copy todir="${classDir}" overwrite="true">
<fileset dir="${srcDir}">
<include name="**/*.xml" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<!--打jar包-->
<target name="jar" depends="compile">
<jar jarfile="${targetDir}/${ant.project.name}.jar">
<fileset dir="${classDir}">
<include name="**/*" />
</fileset>
</jar>
</target>
<!—准备war包 -->

<target name="preWar" depends="jar">
<copy todir="${tempDir}/WEB-INF/lib" overwrite="true">
<fileset dir="${libDir}">
<include name="*.jar" />
</fileset>
</copy>
<copy todir="${tempDir}" overwrite="true">
<fileset dir="${webDir}">
<include name="**/*" />
</fileset>
</copy>
</target>
<!--打war包-->
<target name="war" depends="preWar">
<jar jarfile="${targetDir}/${ant.project.name}.war">
<fileset dir="${tempDir}">
<include name="**/*" />
</fileset>
</jar>
</target>

<!-- 清理临时目录 -->
<target name="all" depends="war">
<delete dir="${tempDir}" />
</target>
</project>

Eclipse中已经集成了ANT,只要新建build.xml的文件并且编写,右键就能直接运行,非常方便,ANT构建脚本的编写也很简单,关键是目录迭代不能遗漏,还有目录的定位,不过在IDE中都有提示,也很方便。
将打包好的jar放到webapp/lib下并且修改页面的js段代码即可看到效果了。
[img]http://dl.iteye.com/upload/attachment/202823/eaa42970-1c1c-347d-bdaa-dc5a9017d22b.jpg[/img]
欢迎大家交流。
(全篇完)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值