title: How to include obfuscated jar file into a war file
body: <p>In my web application, to obfuscate the source code, i used <strong>yGuard</strong> and got an obfuscated jar file. Now i placed this jar file into the <strong>WEB-INF/lib</strong> folder (as my jsp files have reference to the java files) and packaged the war file using below ant script :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;    
     &lt;project name="MyWebApp" default="war" basedir="."&gt;
        &lt;property file="build.properties" /&gt;  
        &lt;property name="war-file-name" value="${project-name}.war" /&gt;
        &lt;property name="source-directory" value="src" /&gt;
        &lt;property name="classes-directory" value="WebRoot/WEB-INF/classes" /&gt;
        &lt;property name="web-directory" value="WebRoot" /&gt;
        &lt;property name="web-xml-file" value="WebRoot/WEB-INF/web.xml" /&gt;
        &lt;property name="build-directory" value="build" /&gt;
        &lt;property name="lib-dir" value="WebRoot/WEB-INF/lib" /&gt;
        &lt;property name="main-class"  value="com.Main"/&gt;
  
        &lt;path id="compile.classpath"&gt;
           &lt;fileset dir="${lib-dir}"&gt;
               &lt;include name="*.jar"/&gt;        
           &lt;/fileset&gt;
        &lt;/path&gt;
  
        &lt;target name="clean"&gt;
           &lt;delete dir="${classes-directory}" /&gt;      
           &lt;delete dir="${build-directory}" /&gt;                
        &lt;/target&gt;
  
        &lt;!-- Creates the  build, docs and dist directory--&gt;
        &lt;target name="makedir"&gt;
           &lt;mkdir dir="${classes-directory}" /&gt;       
           &lt;mkdir dir="${build-directory}" /&gt;
        &lt;/target&gt; 
  
        &lt;target name="compile" depends="clean, makedir"&gt;
           &lt;javac srcdir="${source-directory}" destdir="${classes-directory}" includeantruntime="false"&gt;
              &lt;classpath refid="compile.classpath"/&gt;
           &lt;/javac&gt;
           &lt;copy  todir="${classes-directory}"&gt;
              &lt;fileset dir="src" includes="**/*.properties"/&gt;
           &lt;/copy&gt;
        &lt;/target&gt;
  
        &lt;target name="jar" depends="compile"&gt;
               &lt;jar destfile="${build-directory}/${ant.project.name}.jar" basedir="${classes-directory}"&gt;
                    &lt;manifest&gt;
                         &lt;attribute name="Main-Class" value="${main-class}"/&gt;
                    &lt;/manifest&gt;
               &lt;/jar&gt;
         &lt;/target&gt;
  
         &lt;path id="external.lib.path"&gt;
           &lt;fileset dir="${lib-dir}" includes="*.jar"/&gt;
         &lt;/path&gt;
  
         &lt;target name="yguard" depends="jar"&gt;
           &lt;taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="yguard.jar"/&gt;
           &lt;yguard&gt;
  
               &lt;inoutpair in="${build-directory}/${ant.project.name}.jar" out="${build-directory}/${ant.project.name}_obf.jar"/&gt;
  
           &lt;externalclasses refid="external.lib.path"/&gt;
  
               &lt;rename logfile="renamelog.xml"&gt;
                   &lt;keep&gt;
                  &lt;method name="void main(java.lang.String[])"&gt;
                    &lt;patternset&gt;
                       &lt;include name="com.*"/&gt;
                       &lt;include name="misc.*"/&gt;
                       &lt;include name="client.*"/&gt;
                    &lt;/patternset&gt;
                  &lt;/method&gt;
                  &lt;/keep&gt; 
              &lt;/rename&gt;
                  &lt;/yguard&gt;
  
          &lt;copy file="${build-directory}/${ant.project.name}_obf.jar" todir="${lib-dir}"/&gt;
       &lt;/target&gt;
  
       &lt;target name="war" depends="yguard"&gt;
          &lt;war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}"&gt;
          &lt;fileset dir="${web-directory}"&gt;
              &lt;!-- Need to exclude it since webxml is an attribute of the war tag above --&gt; 
              &lt;exclude name="WEB-INF/web.xml" /&gt;
              &lt;exclude name="WEB-INF/lib/servlet-api.jar" /&gt;
              &lt;exclude name="WEB-INF/lib/jsp-api.jar" /&gt;
              &lt;exclude name="WEB-INF/classes/**/" /&gt;
          &lt;/fileset&gt;          
          &lt;/war&gt;
       &lt;/target&gt;
     &lt;/project&gt;
  </code></pre>
  
  <p>But when i deployed this war file to tomcat and accessed the index.jsp it throws following exception on browser :</p>
  
  <pre><code>javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/Main
  </code></pre>
  
  <p>Now my questions are : </p>
  
  <ul>
  <li>After obfuscation why the jsp file is not able to get the reference of class file ?</li>
  <li>What should i do to include my obfuscated jar file into the war file to work it perfectly ( or resolve the above issue)?</li>
  </ul>