Eclipse launch configuration----Eclipse运行外部工具

Eclipse运行外部工具

工具条中点击如下按钮,可以看到External Tools Configurations,点击打开使用外部工具配置对话框。


也可以通过 Run > External Tools > Open External Tools Dialog打开,默认支持Ant Build和Program两种。



一)运行Program

如写一个简单的bat,如下:

example.bat:

@time /t

@echo "%*"

按照上图在Main中做配置,点击配置的Run按钮运行,则在Eclipse的Console栏中显示如下结果:

22:43
"container_loc:D:\workspace container_name: container_path:""

${workspace}\.metadata\.plugins\org.eclipse.debug.core\.launches中可以看到Eclipse的配置文件example_bat.launch,内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/practise/example.bat}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="&quot;container_loc:${container_loc}&quot; &quot;container_name:${container_name}&quot;&#13;&#10;&quot;container_path:${container_path}&quot;"/>
</launchConfiguration>

二)运行Ant

首先在工程主目录下编写Ant脚本build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project name="myAntExample" default="publish">
    <description>
        Short description here.
    </description>

    <property name="versionName" value="1.0.0" />
    <property name="dist.dir" value="dist" />
    <property name="publish.dir" value="published" />
    <property name="classes.jar" value="${dist.dir}/classes.jar" />
    <property name="sources.jar" value="${dist.dir}/sources.jar" />

    <target name="publish" depends="package" description="Published the files">
        <copy file="${classes.jar}" tofile="${publish.dir}/classes-${version}.jar" />
        <copy file="${sources.jar}" tofile="${publish.dir}/sources-${version.jar}" />
    </target>

    <target name="package" depends="prepare" description="Packages the jars">
        <jar destfile="${classes.jar}">
            <fileset dir="${classes.dir}">
                <include name="**/*.class" />
            </fileset>
        </jar>
        <jar destfile="${sources.jar}">
            <fileset dir="${sources.dir}">
                <include name="**/*.java" />
            </fileset>
        </jar>
    </target>

    <target name="prepare">
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${publish.dir}" />
    </target>

</project>
然后在Eclipse中做相应配置,如下图:

1)Main标签:



关于Arguments:

传送给Ant的属性需要以-D<property name>=<value>的格式,如果想要verbose模式的输出并重写dist.dir变量,则需要传入 -v -Ddist.dir=out.

除了像上面一样使用静态数据外,还可以在运行时动态设置参数,通过将上面的<value>改为${string_prompt}。如我们要在运行时动态设置版本号,可以这样配置:-DversionName=${string_prompt}.

其它,如-q, -v , -d 表示输出的模式:quiet, verbose 和 debug. 通过设置-logfile <filename>指定log的输出位置。


关于Variables:

可以配置的变量及含义见下表:

Table 1. Variables for launch configurations
Variable Description
build_files If automatic building is turned on, this variable includes the absolute paths of the files that triggered the build. It support parameters to narrow the choices, such as f for files only.
build_project This is the absolute path of the project currently being built.
build_type This variable represents the type of build being executed (incremental, full, auto, or none). The value isnone if you try to use this variable when your launch configuration is not a builder.
container_loc This is the absolute name of the current resource's container, which is the folder or directory.
container_name This is the name of the container in which the current resource resides.
container_path This variable represents the path of the container relative to the workspace.
eclipse_home This is the location in which Eclipse is installed.
env_var This variable inputs the value of the given environment variable, where the name of the variable can be supplied as an argument to the variable.
file_prompt When Eclipse launches the program, it displays a file selector. The name of the file you select when prompted is put into the value of the variable.
folder_prompt This variable is the same as the file prompt, but is limited to folders.
java_extensions_regex This is a regex-matching registered Java-like file extensions.
java_type_name This variable is the fully qualified Java type name of the primary type in the selected resource.
project_loc This is the absolute path of the project on the file system.
project_name This is the name of the project.
project_path This is the path of the current project relative to the workspace.
resource_loc This variable represents the absolute path of the current resource on the file system.
resource_name This is the name of the resource.
resource_path This is the path of the current resource relative to the workspace.
selected_text This is the value of the text that is selected, if any.
string_prompt If used, Eclipse prompts you for a string value. Whatever you type in the prompt is substituted into the variable.
system This is the value of an Eclipse system variable (ARCH, ECLIPSE_HOME, NL, OS, WS).
system_path This variable is the absolute path of a tool — supplied as an argument — in the file system.
system_property This is the value of a system property from the Eclipse runtime, where the name of the property is an argument to the variable.
target.arch This variable represents the target processor architecture (for example, x86 for Intel® processors).
target.nl This is the target locale (for example, en_US or fr_FR).
target.os This is the target operating system (for example, macosx).
target.ws This variable represents the target windowing system (for example, Carbon for Mac).
target_home This is the target home, which is the same as the Eclipse home.
workspace_loc This is the absolute path of the workspace on the file system.
2)Refresh标签


选中Refresh resources upon completion.可以选择自动刷新的资源位置,省却每次手动刷新的烦恼。各选项的含义如下:

The entire workspace
When selected, Eclipse refreshes every resource in the workspace. If you have a large workspace, you may not want to select this checkbox for performance reasons if you don't absolutely need it.
The selected resource
For the example Ant build in this tutorial, this refresh wouldn't be very effective. The selected resource could often be the build file.
The project containing the selected resource
This option would effectively refresh the project containing the build file (if the build file were selected), but would not be useful if a resource in another project were selected, instead.
The folder containing the selected resource
The same applies here for the Ant build, but this option could be useful with other launch configurations.
Specific resources
This allows you to select specific resources to be refreshed. For this example, select this option, then click Specify Resources. Select the out, published, and dist directories.
3)Targets标签

这里可以选择运行的Task。


4)ClassPath标签

可以修改默认的Ant Home路径,也可以添加JAR包等。



可以修改默认的Ant Home路径,也可以运行上述配置,即可使用Ant脚本编译。

5)Common标签

默认情况下,launch Configuration是在本地保存的。 可以通过Shared file选项选择保存路径。Eclipse会自动命名该文件为<configuration name>.launch.好处之一是可以与他人共享该配置。但是需要注意使用到的变量的通用型。




三)定位问题
标准的输入,输出不能解决问题时,可以使用上面的脚本( example.bat) 来打印出参数,大部分情况下错误都是由于参数不正确引起的。


三)定位问题
标准的输入,输出不能解决问题时,可以使用上面的脚本来打印出参数,大部分情况下错误都是由于参数不正确引起的。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值