`
zhxmyself
  • 浏览: 40677 次
  • 来自: ...
社区版块
存档分类
最新评论

Commons launcher

阅读更多
Launcher 组件是一个与平台无关的Java 应用载入器。 Commons-launcher 消除了需要批处理或者Shell脚本来载入Java 类。
假如你需要在linux/windows上运行一个带有main方法的类,而该类又引用了许多jar和class文件,可以用Launcher。

Apache提供了一个Lanucher的应用例子,我们可以通过修改该demo来实现。

实现的步骤:
1、下载commons-launcher-example
http://commons.apache.org/downloads/download_launcher.cgi
2、解压下载的文件,然后修改该解压包里面bin文件夹中的launcher.xml文件

代码如下:
<!--项目名-->
<project name="Demo Launcher" default="demo" basedir=".">
    <property name="base.dir" value="${basedir}/.."/>
    <!—加载的class路径-->
    <property name="etc.dir" value="${base.dir}/etc"/>
    <!--加载的jar路径-->
    <property name="lib.dir" value="${base.dir}/lib"/>
    <!--日志存放路径-->
    <property name="log.dir" value="${base.dir}/log"/>
    <path id="base.class.path">
        <pathelement path="${etc.dir}"/>
        <fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<!--一个target指定一个带main方法的类,假如需要多个main,可以通过定义多个target, target name 必须与你定义的.bat或者.sh中的 target的名字一致-->
    <target name="demo">
        <mkdir dir="${log.dir}" />
        <!--带有mian的执行类-->
        <launch classname="org.apache.launcher.example.Main">
            <classpath refid="base.class.path"/>
            <syspropertyset>
                <sysproperty key="log.dir" file="${log.dir}"/>
            </syspropertyset>
        </launch>
    </target>
</project>


3、修改demo.bat和demo.sh文件
java -cp . LauncherBootstrap -executablename launcher-demo demo

注意这句话中最后一个单词demo必须与你在target的名称一致。

应用commons-launcher的开发例子
为公司的系统网站开发一个全文索引功能,为了可以随时在linux进行全文索引创建和增量索引,也是通过修改commons-launcher-example来实现的。在windows下开发调试的代码如下:
<project name="Demo Launcher" default="demo" basedir=".">
<property name="base.dir" value="${basedir}/.."/>
<!—在linux下,更改成相应的路径 -->
    <property name="etc.dir" value="d:/Program Files/Apache Software  Foundation/Tomcat5.5/webapps/cms99/WEB-INF/classes"/>
    <!—在linux下,更改成相应的路径 -->
    <property name="lib.dir" value="d:/Program Files/Apache Software Foundation/Tomcat5.5/webapps/cms99/WEB-INF/lib"/>
    <property name="log.dir" value="${base.dir}/log"/>

    <path id="base.class.path">
        <pathelement path="${etc.dir}"/>
        <fileset dir="${lib.dir}" includes="*.jar"/>
    </path>
    <!—全文索引--> 
    <target name="full">
        <mkdir dir="${log.dir}" />
        <launch classname="com.foresee.cms.search.MakeIndex">
            <classpath refid="base.class.path"/>
            <syspropertyset>
                <sysproperty key="log.dir" file="${log.dir}"/>
            </syspropertyset>
			    <!—参数值,main函数的args[]参数的值,0为全文索引,1为增量 -->
				<arg value="0"/>
        </launch>
</target>
    <!—增量索引--> 
    <target name="inc">
        <mkdir dir="${log.dir}" />
        <launch classname="com.foresee.cms.search.MakeIndex">
            <classpath refid="base.class.path"/>
            <syspropertyset>
                <sysproperty key="log.dir" file="${log.dir}"/>
            </syspropertyset>
			
				<arg value="1"/>
			
        </launch>
    </target>
</project>

修改demo.sh和demo.dat文件
java -cp . LauncherBootstrap -executablename launcher-demo full
创建一个增量索引生成的执行文件inc.sh和inc.bat
java -cp . LauncherBootstrap -executablename launcher-inc inc

注意:代码中的中文注释只是为了方便理解,可能会引起运行错误,请去掉.
分享到:
评论

相关推荐

    commons-launcher-1.1.zip_Commons launcher_commons-launcher_shell

    Commons Launcher是Apache Commons项目的一部分,它提供了一个统一的、跨平台的方式来启动Java应用程序。这个工具主要解决了在不同操作系统上管理Java应用启动脚本的问题,确保无论在Windows、Linux还是其他Unix-...

    commons-launcher.jar

    commons-launcher.jar

    JAKARTA COMMONS

    22. **Commons Launcher**: 提供跨平台的 Java 应用加载器,避免使用批处理或 Shell 脚本启动 Java 类。 23. **Commons Logging**: 作为各种日志 API(如 log4j、java.util.logging 等)的抽象层,简化日志集成。 ...

    Apache Commons 所有包最新版本 含SRC (4/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    apache commons jar(commons所有的jar包,从官网下载提供给大家)

    fileupload-1.3.1-bin commons-fileupload-1.3-bin commons-io-2.4-bin commons-jexl-1.1 commons-lang-2.6-bin commons-lang3-3.4-bin commons-launcher-1.1 commons-logging-1.2-bin ccommons-math-2.2 commons-...

    apache commons 常用jar包 commons-validator commons-transaction commons-lang等

    jar包大小:43KB commons-launcher.jar jar包大小:239KB commons-lang-2.3.jar jar包大小:237KB commons-lang-2.2.jar jar包大小:202KB commons-lang-2.1.jar jar包大小:165KB commons-lang-2.0.jar jar包大小:278KB ...

    Apache Commons 所有包最新版本 含SRC (6/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    apache-commons源码及jar文件

    Commons-launcher 消除了需要批处理或者Shell脚本来载入Java 类。.原始的 Java 类来自于Jakarta Tomcat 4.0 项目 Logging Commons-Logging 是一个各种 logging API实现的包裹类. Math Math 是一个轻量的,自包含...

    apache-commons源代码2,包括doc,src,jar

    commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-math3-3.1-bin.zip commons-modeler-2.0.1.zip commons-net-3.2-bin.zip commons-pool-current-bin.zip commons-primitives-1.0.zip ...

    Apache Commons 所有包最新版本 含SRC (5/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    Apache Commons 所有包最新版本 含SRC (1/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    Apache Commons 所有包最新版本 含SRC (3/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    Apache Commons 所有包最新版本 含SRC (7/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    Apache Commons 所有包最新版本 含SRC (2/7)

    lang-2.4-src.zip commons-launcher-1.1-src.zip commons-launcher-1.1.zip commons-logging-1.1.1-bin.zip commons-logging-1.1.1-src.zip commons-math-1.2-src.zip commons-math-1.2.zip ...

    junit-platform-commons-1.8.2-API文档-中英对照版.zip

    赠送jar包:junit-platform-commons-1.8.2.jar; 赠送原API文档:junit-platform-commons-1.8.2-javadoc.jar; 赠送源代码:junit-platform-commons-1.8.2-sources.jar; 赠送Maven依赖信息文件:junit-platform-...

    Jakarta commons docs API CHM 格式

    commons-launcher 提供多平台的 Java 程序加载 commons-logging 提供日志的实现 commons-math 是一个轻量的,自包含的数学和统计组件,解决了许多非常通用但没有及时出现在Java标准语言中的实践问题. commons-...

    比较全面的:Jakarta-commons jar包(附: chm参考手册 & 资源简介)

    commons-launcher 提供多平台的 Java 程序加载 commons-logging 提供日志的实现 commons-math 是一个轻量的,自包含的数学和统计组件,解决了许多非常通用但没有及时出现在Java标准语言中的实践问题. commons-...

    commons包介绍1

    21. **Launcher**: Launcher组件是一个跨平台的Java应用加载器,简化了启动Java应用程序的过程。 22. **Logging**: Commons-Logging是一个日志API包装器,可以适配多种日志实现,如Log4j、Java内置的日志框架等。 ...

    apache压缩解压zip,支持中文

    - `ant-launcher.jar`:Ant的启动器,帮助运行Ant脚本。 - `jyzip.java` 和 `yszip.java`:这两个可能是Java源代码文件,实现了自定义的ZIP操作,可能是为了演示或补充Apache Commons Compress的功能。 总的来说,...

Global site tag (gtag.js) - Google Analytics