Stories

Detail Return Return

Eclipse 給 Java 應用創建 Run configuration 時找不到 main type 的錯誤消息 - Stories Detail

我在 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 視圖中描述項目。 這個文件負責維護項目名稱是什麼,它指的是工作區中的其他哪些項目,以及用於構建項目的構建器是什麼。

user avatar lenglingx Avatar kohler21 Avatar devlive Avatar gupan Avatar fkcaikengren Avatar aixiaodewulongcha_ehoerm Avatar baoliweishipinyun Avatar csh_716 Avatar object_684147fd5fae2 Avatar liushuigs Avatar yangjunyi_612de77e8a34b Avatar
Favorites 11 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.