title: Executing Java from CGI (Java cannot find or load the main class)
body: <p>I have a weird problem running cgi's from Apache. I have the following cgi:</p>
  
  <pre><code> #!"C:\xampp\perl\bin\perl.exe"
  use File::Basename;
  use Cwd 'chdir';
  
  $DIR=dirname($0);
  chdir $DIR;
  
  print "Content-type: text/plain; charset=iso-8859-1\n\n";
  #print $DIR;
  $Result = `java -classpath . CONCATARR`;
  print $result;
  </code></pre>
  
  <p>This cgi is working fine from the command line, but not from the browser. From the browser java is throwing the following error: Error: Could not find or load main class CONCATARR</p>
  
  <p>The file CONCATARR.class is, of course, in the cgi folder. When I printed the dir, it is pointing the cgi folder too.</p>
  
  <p>That is the problem, to test it in a different way I did also a php file:</p>
  
  <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Test&lt;/title&gt; &lt;/head&gt;
  
  &lt;body&gt; &lt;?
  chdir('C:/xampp/cgi-bin');
  $output = shell_exec("java -classpath . CONCATARR");
  echo $output;
  ?&gt; &lt;/body&gt; &lt;/html&gt;
  </code></pre>
  
  <p>which has the same problem, is running fine from the command line but not from the browser (same error). </p>
  
  <p>The cgi-bin folder has been configured as suggested in the manual (in fact, the cgi is executed, java is failing...), all the files and folders inside cgi-bin have the permissions to be read and executed, Apache service is allowed to interact with desktop.</p>
  
  <p>I have been trying to make it work for two days and checked tens of forums, so probably I have tried more things that I do not remember now...</p>
  
  <p>Any help is very welcome.</p>
  
  <p>Configuration: Windows Server 2008 R2, xammp. (If some more details are needed to find out a solution please ask)</p>
  
  <p><strong>Edit in response to the first answer:</strong></p>
  
  <p>Thanks for the answer, about those three things, I think I have cover them: </p>
  
  <p>1: the name is right and the file is there, all with caps. </p>
  
  <p>2: The .class has a main method, in fact is was used before in an iOS system. The .java correspondent to that class is starting like this: </p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  import java.net.URLDecoder;
  class CONCATARR
  {
  public  static  void  main( String  args[] ) throws Exception
  {
  System.out.print("Content-type: text/xml\n");
  System.out.print("Access-Control-Allow-Origin: *\n\n"); 
  </code></pre>
  
  <p>3: this is the httpd.conf file (the part regarding the cgi directory </p>
  
  <pre><code>ScriptAlias /cgi-bin/ "C:/xampp/cgi-bin/"
  
  &lt;/IfModule&gt;
  &lt;IfModule cgid_module&gt;
  &lt;/IfModule&gt;
  
  &lt;Directory "C:/xampp/cgi-bin"&gt;
      AllowOverride None
      Options None FollowSymLinks
      Order allow,deny
      Allow from all
  &lt;/Directory&gt;
  </code></pre>
  
  <p>The file and the folder have all the permissions to read and execute for all the users... </p>
  
  <p>Am I missing anything?</p>