Hello,World!
分步骤介绍如何在jdk7u80和Zhiqim Studio上编写一个简单的Hello,World!工程,并发布成可执行程序,分别演示在Windows和Linux上运行!
一、Hello,World!示例体验
JDK安装指南
|
<-- 点击下载JDK --> 64位机器下载:jdk-7u80-windows-x64.exe 32位机器下载:jdk-7u80-windows-i586.exe <-- 点击下载Example执行程序 --> ZhiqimHelloworld.zip |
二、Hello,World!开发前准备
|
<-- 点击下载Zhiqim Studio --> 64位机器下载:Zhiqim-Studio-Win64.zip <-- 点击下载Example工程源码 --> ZhiqimHelloworld_src.zip |
三、Hello,World!源码工程结构
|
|
四、Hello,World!配置说明
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ZHIQIM-CONFIG PUBLIC "-//ZHIQIM //DTD Zhiqim-Config Configuration 1.5.0//EN" "https://zhiqim.org/xmldtds/zhiqim_config_1_5_0.dtd">
<zhiqim-config>
<group id="boot" desc="系统启动引导配置">
<item key="name" value="Helloworld" type="protected" desc="系统名称" />
<item key="version" value="1.0" type="protected" desc="系统版本" />
<item key="port" value="50080" type="protected" desc="系统监听端口,用于启动监听和命令关闭工程" />
<item key="home" value="d:/Java/jdk1.8.0_202/" type="protected" desc="JDK根目录,路径符统一顺斜杠,MAC系统下该配置无效" />
<item key="process" value="zhiqim" type="protected" desc="使用的进程名,MAC系统下该配置无效" />
</group>
<group id="service" desc="系统服务配置,有依赖时注意顺序,系统按顺序加载,按倒序销毁">
<item key="helloworld" value="org.zhiqim.example.Helloworld" type="protected" desc="Hello,World!服务"/>
</group>
</zhiqim-config>
五、Hello,World!编写Helloworld服务类
package org.zhiqim.example;
import org.zhiqim.kernel.Servicer;
import org.zhiqim.kernel.logging.Log;
import org.zhiqim.kernel.logging.LogFactory;
/**
* HelloWorld服务
*
* @version v1.0.0 @author zouzhigang 2016-12-21 新建与整理
*/
public class Helloworld extends Servicer implements Runnable
{
private static final Log log = LogFactory.getLog(Helloworld.class);
private Thread thread;
@Override
public boolean create() throws Exception
{
log.info("Hello, World! create!!!");
thread = new Thread(this);
thread.start();
return true;
}
@Override
public void run()
{
while (true)
{
log.info("Hello, World! running...");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{//线程中断退出
break;
}
}
}
@Override
public void destroy() throws Exception
{
log.info("Hello, World! destroy!!!");
//通知线程状态
thread.interrupt();
thread = null;
//关闭前停5秒,演示关闭时销毁操作
log.info("5");
Thread.sleep(1000);
log.info("4");
Thread.sleep(1000);
log.info("3");
Thread.sleep(1000);
log.info("2");
Thread.sleep(1000);
log.info("1");
Thread.sleep(1000);
}
}
六、Hello,World!调试
配置调试信息
单步调试Helloworld
|
<-- debug配置 --> <-- debug状态 --> |
七、Hello,World!发布(导出执行程序和工程源码打包)
|
|
|
八、Hello,World!运行(Windows和Linux)
配置[/conf/zhiqim.xml]文件
Windows运行
Linux运行
|
<-- Windows下运行 --> <-- Linux下运行 --> |