[solved] Compiling when your main class is in another folder/package

If you have a main class (your program’s starting point class) that is in another folder/package like src/package_a/package_b/hello and not just in the src folder you need to specify that in your haxe-command or in the .hxml-file.

Usually you have two solutions

  1. Either, when it’s just a single class in another folder, you add the following to your haxe-command or .hxml-file:
-cp src
-p folder_a/folder_b
-main Hello
  1. or, when it’s another package, you need to define the package by package package_a.package_b; inside of your Hello.hx class (typically at the top of the file). You can now access the class by
-cp src
-main package_a.package_b.Hello

Otherwise these are some errors you might get:

Type not found : Hello

Invalid commandline class : Hello should be package_a.package_b.Hello

Invalid commandline class : package_a.package_b.Hello should be Hello

src/package_a/Hello.hx:15: characters 40-67 : Type not found : package_a.Hello

→ See also: haxe compiler-usage and [modules and paths](http s://

(Not sure, but maybe this could be sort of added to the haxe code cookbook. It’s trivial, however there’s only an old [article](http :// concerning this.)

Solution 1 is not correct, adding a classpath to Hello’s directory won’t respect its package structure.

Yes, I didn’t test that properly enough. Solution one only works for single main class in another folder, right? I edited the post.