2014-06-27 106 views
1

我刚开始学习Haxe,但遇到了编译错误。未找到类:helloworld.Main

Main.hx

package helloworld; 

import js.Lib; 

class Main { 

    static function main() { 
     Lib.alert("Hello World"); 
    } 

} 

请小心目标类是helloworld.Main

build.hxml

-js bin/HelloWorld.js 
-cp src 
-main helloworld.Main 
-debug 

构建过程日志

Building HelloWorld_p140627 
Running Pre-Build Command Line... 
cmd: C:\HaxeToolkit\haxe\haxe.exe X:\tmp\HelloWorld_p140627\build.hxml 
Class not found : helloworld.Main 
Build halted with errors. 
Done(1) 

enter image description here

为什么?类helloworld.Main肯定存在。我甚至不能说“你好,世界”?现在

回答

5

更新,我可以看到你的项目的截图:

您试图编译“helloworld.Main”,这意味着被称为“主”套“HelloWorld”的类,所以HAXE将在你的“src /”目录下寻找名为“helloworld/Main.hx”的文件。

但是你有“src/Main.hx”,而不是“src/helloworld/Main.hx”。创建一个名为“helloworld”的子文件夹,在那里移动“Main.hx”,你会没事的。您在Haxe中使用的软件包必须与目录结构相匹配。


请确保您的软件包与您的文件夹以及您的文件名与您的类名对齐。所有这些应该在你的“-cp”类路径文件夹中。

对于上面的例子中,代码看起来不错,我希望您的布局看起来像:

build.hxml     <-- build file 
src/helloworld/Main.hx  <-- classpath/package/class.Hx 
bin/      <-- output folder 
bin/HelloWorld.js   <-- will be created once it compiles 

然后你会运行haxe build.hxml。如果这不起作用,请发布项目的确切文件结构(哪些文件夹和哪些目录)以及用于构建它的命令以及输出。

希望有帮助,

+0

我确认了项目的文件格式,但没有什么好奇的。我已经添加了上面的布局。你能找到编译错误的原因吗? – weed

+1

更新我的答案。你错过的是你要求“helloworld.Main”,即“src/helloworld/Main.hx”,而这个不存在。 –

+0

非常感谢Jason,我明白了。我成功编译。 – weed