<?xml version="1.0"?>

<document url="./ssl.xml">

<properties>

<author>James Mitchell</author>

<title>How to setup a basic Struts project using Netbeans IDE - Apache Struts</title>

</properties>

<body>

<chapter href="netbeans" name="How to setup a basic Struts project using Netbeans IDE">
<section name="Legal Disclamer">

Please read <a href="http://jakarta.apache.org/site/idedevelopers.html">this</a> first.<br/>
<p>
* DISCLAIMER - This simple How-To shows you one of many ways to setup a working project using<br/>
the Struts framework.  This is mainly geared toward struts users who are new to Netbeans, and<br/> 
don't want to spend a lot of time figuring out the differences between their old IDE (if any)<br/>
and this one.<br/>
<br/>
I will also apologize ahead of time for the formatting of this page.<br/>
</p>
<br/>
In this How-To, I will demonstrate (using Netbeans 3.4) how to setup, compile, and build
a customized version of the struts-example.<br/> 
</section>


<section name="Let's get started">
<ol>
 <li>
  Create a new project.<br/>
  <img alt="" src="../images/how-to/netbeans/creating-project3.jpg"></img><br/><br/><br/>
  <img alt="" src="../images/how-to/netbeans/creating-project4.jpg"></img><br/><br/><br/>
  <img alt="" src="../images/how-to/netbeans/creating-project5.jpg"></img><br/><br/><br/>
  <img alt="" src="../images/how-to/netbeans/creating-project6.jpg"></img><br/><br/><br/>
  <img alt="" src="../images/how-to/netbeans/creating-project8.jpg"></img><br/><br/><br/>
  </li>
 <li>
  Now let's create (or reuse) a directory to hold the project.
  What I did was copy the struts-example.war from the Struts distribution
  and extracted it (using Winzip) like this:
  <br/>
  <img alt="" src="../images/how-to/netbeans/directory.jpg"></img><br/><br/><br/>
  </li>
 <li>
  Next we need to create a build.xml to build our project.  This file will sit in the root<br/>
  directory of your project. (Actually, it doesn't matter where sits so long as you make <br/>
  the appropriate changes to directories and such.)<br/>
  <br/>
  *Note - I will not spend any time here trying to convince you why you should be <br/>
  using Ant to build your projects.  I guess I consider this to be obvious.<br/>
  Here is the build.xml file I use for this demonstration (you MUST modify this <br/>
  to use your environment):<br/>
  <pre>
  
  &lt;project name="Struts Example" default="main" basedir="."&gt;
  
    &lt;!--  This is a basic build script, only the minimums here --&gt;
    
    &lt;!-- Tell ant to use my environment variables --&gt;
    &lt;property environment="env"/&gt;
  
    &lt;property file="./build.properties"/&gt;
  
      &lt;property name="build.compiler"     value="modern"/&gt;
      &lt;property name="build.dir"          value="./WEB-INF/classes" /&gt;
      &lt;property name="src.dir"            value="./WEB-INF/src"/&gt;
    &lt;property name="servlet.jar"        value="/Apache_Home/jakarta-servletapi-4/lib/servlet.jar"/&gt;
      &lt;property name="war.file"              value="struts-example"/&gt;
      &lt;property name="war.file.name"      value="${war.file}.war"/&gt;
      &lt;property name="tomcat.home"       value="${env.CATALINA_HOME}"/&gt;
      &lt;property name="deploy.dir"         value="${tomcat.home}/webapps"/&gt;
  
    &lt;path id="project.class.path"&gt;
        &lt;fileset dir="./WEB-INF/lib/"&gt;
            &lt;include name="**/*.jar"/&gt;
        &lt;/fileset&gt;
        &lt;pathelement path="${src.dir}"/&gt;
        &lt;pathelement path="${servlet.jar}"/&gt;
    &lt;/path&gt;
  
      &lt;target name="clean"&gt;
          &lt;delete dir="${build.dir}" includeEmptyDirs="true" /&gt;
      &lt;/target&gt;
  
  
      &lt;target name="prep"&gt;
          &lt;mkdir dir="${build.dir}"/&gt;
      &lt;/target&gt;
  
      &lt;target name="compile"&gt;
        &lt;javac   srcdir="${src.dir}"
                    destdir="${build.dir}"
                    debug="on"
                deprecation="on"&gt;
          &lt;include name="**/*.java"/&gt;
          &lt;classpath refid="project.class.path"/&gt;
        &lt;/javac&gt;
      &lt;/target&gt;
  
      &lt;target name="cleanWebApp"&gt;
        &lt;delete file="${deploy.dir}/${war.file.name}" /&gt;
          &lt;delete  dir="${deploy.dir}/${war.file}" includeEmptyDirs="true" /&gt;
      &lt;/target&gt;
  
      &lt;target name="war"&gt;
          &lt;war warfile="${war.file.name}" webxml="./WEB-INF/web.xml"&gt;
                 &lt;fileset dir="./" includes="**/*.*" excludes="*.war, **/*.nbattrs, web.xml, **/WEB-INF/**/*.*, **/project-files/**/*.*"/&gt;
                 &lt;webinf  dir="./WEB-INF"    includes="**/*" excludes="web.xml, **/*.jar, **/*.class"/&gt;
                 &lt;lib     dir="./WEB-INF/lib"/&gt;
                 &lt;classes dir="${build.dir}" includes="**/*.properties" /&gt;
          &lt;/war&gt;
      &lt;/target&gt;
  
      &lt;target name="deploy"&gt;
          &lt;copy todir="${deploy.dir}"&gt;
            &lt;fileset dir="./" includes="${war.file.name}"/&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
 
    &lt;target name="main" depends="clean, prep, cleanWebApp, compile, war"/&gt;
  
  &lt;/project&gt;
  
  </pre>
  </li>
  <li>
  Build the project using Ant from the command line.<br/>
  Here's what I get:
  
  <pre>
  
  C:\personal\development\Projects\struts-examples\struts-example>ant
  Buildfile: build.xml
  
  clean:
     [delete] Deleting directory C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\classes
  
  prep:
      [mkdir] Created dir: C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\classes
  
  cleanWebApp:
     [delete] Deleting: C:\Apache_Home\jakarta-tomcat-4.0.6\webapps\struts-example.war
     [delete] Deleting directory C:\Apache_Home\jakarta-tomcat-4.0.6\webapps\struts-example
  
  compile:
      [javac] Compiling 22 source files to C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\classes
      [javac] C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\src\org\apache\struts\webapp\example\memory\MemoryDatabasePlugIn.java:78: warning: org.apache.struts.config.ApplicationConfig in org.apache.struts.config has been deprecated
      [javac] import org.apache.struts.config.ApplicationConfig;
      [javac]                                 ^
      [javac] C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\src\org\apache\struts\webapp\example\memory\MemoryDatabasePlugIn.java:185: warning: org.apache.struts.config.ApplicationConfig in org.apache.struts.config has been deprecated
      [javac]     public void init(ActionServlet servlet, ApplicationConfig config)
      [javac]                                             ^
      [javac] C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\src\org\apache\struts\webapp\example\memory\MemoryDatabasePlugIn.java:185: warning: init(org.apache.struts.action.ActionServlet,org.apache.struts.config.ApplicationConfig) in org.apache.struts.action.PlugIn has been deprecated
      [javac]     public void init(ActionServlet servlet, ApplicationConfig config)
      [javac]                 ^
      [javac] C:\personal\development\Projects\struts-examples\struts-example\WEB-INF\src\org\apache\struts\webapp\example\memory\MemoryDatabasePlugIn.java:185: warning: org.apache.struts.config.ApplicationConfig in org.apache.struts.config has been deprecated
      [javac]     public void init(ActionServlet servlet, ApplicationConfig config)
      [javac]                                             ^
      [javac] 4 warnings
  
  war:
        [war] Building war: C:\personal\development\Projects\struts-examples\struts-example\struts-example.war
  
  main:
  
  BUILD SUCCESSFUL
Total time: 11 seconds
  </pre>  
  <br/>
 </li>
 <li>
  If it did not build for you, verify that the external jars (external to this project) are 
  specified correctly.<br/>
  </li>
  <li>
  Now we can finish setting up our Netbeans project<br/><br/>
  Mount the directory where we extracted the example and where we ran the build:<br/>
  <img alt="" src="../images/how-to/netbeans/building1.jpg"></img><br/><br/><br/>
  <img alt="" src="../images/how-to/netbeans/building2.jpg"></img><br/><br/><br/>
  </li>
  <li>
  If specified correctly, Netbeans will parse the build.xml automatically and will use <br/>
  (mount jars) the resources that you've declared for building.<br/>
    <img alt="" src="../images/how-to/netbeans/building3.jpg"></img><br/><br/><br/>
  </li>
  <li>
    I usually get rid of the additional mounted directory under /WEB-INF/classes.  <br/>
    Since everything there gets overwritten with each build, I don't usually need to<br/> 
    see this (or possibly make changes in the wrong place)<br/>
    <img alt="" src="../images/how-to/netbeans/building4.jpg"></img><br/><br/><br/>
  </li>
  <li>
    In order for Netbeans to understand the package structure for our source code, we need<br/>
    to mount all source directories directly.  <br/><br/>
    *Note - Some IDEs will do this automatically <br/>
    (Eclipse) or can be configured from the project config file (JBuilder)<br/>
    <img alt="" src="../images/how-to/netbeans/building5.jpg"></img><br/><br/><br/>
    <img alt="" src="../images/how-to/netbeans/building6.jpg"></img><br/><br/><br/>
  </li>
  <li>
    Use your source mount point to add/edit/delete your .java files<br/>
    <img alt="" src="../images/how-to/netbeans/building7.jpg"></img><br/><br/><br/>
  </li>
  <li>
    Using the initial mount point, expand until you can right-click on the build.xml file (or one<br/>
    of the targets) and build the project<br/>
    <img alt="" src="../images/how-to/netbeans/building8.jpg"></img><br/><br/><br/>
  </li>
  <li>
    If you receive errors from Netbeans (choking on the XML parse), don't worry, I did too.<br/>
    I always call ant on the command line anyway, so I don't worry too much about the IDE's <br/>
    internal XML jars.<br/>
    <!--[:TODO:] finish this section with solution to Netbeans ant/xml incompatibility woes--><br/>
    <img alt="" src="../images/how-to/netbeans/building8.jpg"></img><br/><br/><br/>
  </li>
  <li>
    Feel free to change the code as you like, and then build and deploy your new app.
  </li>
  
</ol>

</section>


</chapter>
</body>
</document>
