Eclipse 给 Java 应用创建 Run configur

2022-10-25  本文已影响0人  _扫地僧_

我在 Eclipse 里选中 com 文件夹下选中一个 .java 文件,这个 Java 文件实现了 public static void main(String[] args) 方法,我想作为一个 Java 应用直接运行它。

选择 Run As -> Java Application

遇到错误消息:Selection does not contain a main type:

我选择 Run Configurations:

New Launch configuration:

创建一个新的 Configuration,却发现找不到 Main Type:


原因可能在于 com 文件夹并没有被 Eclipse 看作是一个 source folder.

把上图的 com 文件夹拖拽到 Java 创建向导自动生成的 src 文件夹内。

出现了大量的 jco 相关错误:


把这些编译错误全部修复后,在 Select type 下拉菜单里就能看到 SimpleCall 了:

总之,只有 source folder 里的 .java 文件才能成为 Main type 搜索的 candidate:

.classpath 为 Java 编译和压缩文件或项目依赖项维护项目的源和目标引用。

此配置通过项目属性中的 Java 构建路径页面进行维护。 源条目可以添加、排序,或者新的 JAR 文件依赖项都可以通过 Java 构建路径页面进行管理。

下图是我一个 jco 项目的 .classpath 明细:

其中 source folder,library folder 和 output folder,都定义在 classpathentry 里:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
        <attributes>
            <attribute name="module" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="lib" path="C:/app/sapjco3-ntamd64-3.1.6/sapjco3.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Eclipse 是插件的运行时环境。 实际上,开发人员在 Eclipse 中看到的所有内容都是安装在 Eclipse 上的插件的结果,而不是 Eclipse 本身。

.project 文件由核心 Eclipse 平台维护,其目标是从通用的、独立于插件的 Eclipse 视图中描述项目。 这个文件负责维护项目名称是什么,它指的是工作区中的其他哪些项目,以及用于构建项目的构建器是什么。

上一篇下一篇

猜你喜欢

热点阅读