What does if __name__ == “__main__”: do?

Short Answer It’s boilerplate code that protects users from accidentally invoking the script when they didn’t intend to. Here are some common problems when the guard is omitted from a script: If you import the guardless script in another script (e.g. import my_script_without_a_name_eq_main_guard), then the second script will trigger the first to run at import … Read more

Can’t execute jar- file: “no main manifest attribute”

First, it’s kind of weird, to see you run java -jar “app” and not java -jar app.jar Second, to make a jar executable… you need to jar a file called META-INF/MANIFEST.MF the file itself should have (at least) this one liner: Where com.mypackage.MyClass is the class holding the public static void main(String[] args) entry point. Note that there are several ways to … Read more

What does “Could not find or load main class” mean?

The java <class-name> command syntax First of all, you need to understand the correct way to launch a program using the java (or javaw) command. The normal syntax1 is this: where <option> is a command line option (starting with a “-” character), <class-name> is a fully qualified Java class name, and <arg> is an arbitrary command line argument that gets passed to your application. 1 – There … Read more

What does if __name__ == “__main__”: do?

Short Answer It’s boilerplate code that protects users from accidentally invoking the script when they didn’t intend to. Here are some common problems when the guard is omitted from a script: If you import the guardless script in another script (e.g. import my_script_without_a_name_eq_main_guard), then the second script will trigger the first to run at import … Read more