title: Call Java program from PHP
body: <p>I created a Java program which sends an email from my gmail account.  I programmed it in Eclipse and it works fine.  But when I attempt to call it from PHP i get the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Address
    at sendVerificationEmail.main(sendVerificationEmail.java:3)
  Caused by: java.lang.ClassNotFoundException: javax.mail.Address
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  </code></pre>
  
  <p>Here's the command Eclipse uses:</p>
  
  <pre><code>/usr/lib/jvm/java-6-openjdk/bin/java -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:53094 -Dfile.encoding=UTF-8 -classpath /home/****/dir/to/program/java/bin:/home/****/dir/to/program/java/lib/javamail-1.4.4/mail.jar sendEmail
  </code></pre>
  
  <p>Here's the command PHP uses:</p>
  
  <pre><code>exec("java -classpath /home/****/dir/to/program/java/bin:/home/****/dir/to/program/java/lib/javamail-1.4.4/mail.jar sendVerificationEmail $name $email $comments");
  </code></pre>