Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to setup a cronjob to download my daily and weekly reports from iTunes Connect. I have downloaded Apple's Autoingestion.class and I have made the following shell script to download the weekly reports:

java Autoingestion <MyAccountName> <MyPassword> <MyVendorID> Sales Weekly Summary

This shell script is stored inside the same directory as the Autoingestion.class. When I run this shell script inside the directory, it works fine. If I go to another directory and run it, I am getting the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Autoingestion
Caused by: java.lang.ClassNotFoundException: Autoingestion
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClassInternal(
Could not find the main class: Autoingestion. Program will exit.

Because it does not work when being ran from another directory, my cronjob does not work.

Does anyone have an idea why this happens and if there is anything to do to get rid of it?

share|improve this question
Have you tried specifying the classpath with -cp /path/to/your/stuff? – slhck Oct 22 '11 at 11:06
up vote 3 down vote accepted

Use the following script:

#!/usr/bin/env bash
cd "$( dirname "$0" )"
java Autoingestion <MyAccountName> <MyPassword> <MyVendorID> Sales Weekly Summary

This will change the working directory to the location of the script, then execute the Java program.

The reason is probably the implied class path .. From man java:

   -cp classpath
          Specifies a list of directories, JAR archives, and ZIP  archives
          to  search for class files.  Class path entries are separated by
          colons (:). Specifying -classpath or -cp overrides  any  setting
          of the CLASSPATH environment variable.

          If -classpath and -cp are not used and CLASSPATH is not set, the
          user class path consists of the current directory (.).

Since java doesn't find Autoingestion in your current working directory if you call the script from somewhere else, it fails to launch.

Depending on the exact behavior of the program (e.g. writing files in the current working directory) you can also try specifying a proper -classpath, e.g.:

java -cp "$( dirname "$0" )" Autoingestion <MyAccountName> <MyPassword> <MyVendorID> Sales Weekly Summary

share|improve this answer
I'm not 100% sure the -cp parameter will work exactly like this. It might depend on other libraries you also need. – Daniel Beck Oct 22 '11 at 11:20
Thank you very much! This solved the issue. Also, thanks for the explanation. That makes sense :-) I chose to add cd "$( dirname "$0" )" to the shell script and that did the trick. – SimonBS Oct 22 '11 at 11:48

I just had this error, and the reason was I was being a bit stupid - Apple provide I simply hadn't unzipped the class before running the class. Doh!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .