📄 netbeans.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>How to setup a basic Struts project using Netbeans IDE - Apache Struts</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="James Mitchell" name="author" />
<link href="../struts.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="heading">
<a href="http://apache.org/">
<img id="asf_logo_wide" alt="The Apache Project" src="../images/asf_logo_wide.gif" />
</a>
<a href="http://struts.apache.org/">
<img id="struts-logo" alt="Struts Framework" src="../images/struts.gif" />
</a>
</div>
<!--end heading-->
<div id="content">
<div id="menu">
<p>FAQs</p>
<ul>
<li>
<a href="kickstart.html">Kickstart</a>
</li>
<li>
<a href="newbie.html">Newbie</a>
</li>
<li>
<a href="helping.html">How to Help</a>
</li>
</ul>
<p>Howto Guides</p>
<ul>
<li>
<a href="actionForm.html">Action Forms</a>
</li>
<li>
<a href="apps.html">Building Apps</a>
</li>
<li>
<a href="database.html">Database</a>
</li>
<li>
<a href="indexedprops.html">Indexed Properties</a>
</li>
<li>
<a href="ssl.html">SSL</a>
</li>
<li>
<a href="struts-el.html">Struts-EL (JSTL)</a>
</li>
</ul>
<p>IDE Guides</p>
<ul>
<li>
<a href="eclipse.html">Eclipse</a>
</li>
<li>
<a href="netbeans.html">Netbeans</a>
</li>
</ul>
<p>Quick Links</p>
<ul>
<li>
<a href="../index.html">Welcome</a>
</li>
<li>
<a href="../userGuide/index.html">User and Developer Guides</a>
</li>
</ul>
<div class="authors">
<p>
<strong>Contributors</strong>
</p>
<ul>
<li>James Mitchell</li>
</ul>
</div>
</div>
<!--end menu-->
<div id="main">
<h1 id="netbeans">How to setup a basic Struts project using Netbeans IDE</h1>
<h2>Legal Disclamer</h2>
<div class="indent">
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 />
</div>
<h2>Let's get started</h2>
<div class="indent">
<ol>
<li>
Create a new project.<br />
<img alt="" src="../images/how-to/netbeans/creating-project3.jpg" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/creating-project4.jpg" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/creating-project5.jpg" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/creating-project6.jpg" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/creating-project8.jpg" />
<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" />
<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>
<project name="Struts Example" default="main" basedir=".">
<!-- This is a basic build script, only the minimums here -->
<!-- Tell ant to use my environment variables -->
<property environment="env"/>
<property file="./build.properties"/>
<property name="build.compiler" value="modern"/>
<property name="build.dir" value="./WEB-INF/classes" />
<property name="src.dir" value="./WEB-INF/src"/>
<property name="servlet.jar" value="/Apache_Home/jakarta-servletapi-4/lib/servlet.jar"/>
<property name="war.file" value="struts-example"/>
<property name="war.file.name" value="${war.file}.war"/>
<property name="tomcat.home" value="${env.CATALINA_HOME}"/>
<property name="deploy.dir" value="${tomcat.home}/webapps"/>
<path id="project.class.path">
<fileset dir="./WEB-INF/lib/">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${src.dir}"/>
<pathelement path="${servlet.jar}"/>
</path>
<target name="clean">
<delete dir="${build.dir}" includeEmptyDirs="true" />
</target>
<target name="prep">
<mkdir dir="${build.dir}"/>
</target>
<target name="compile">
<javac srcdir="${src.dir}"
destdir="${build.dir}"
debug="on"
deprecation="on">
<include name="**/*.java"/>
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="cleanWebApp">
<delete file="${deploy.dir}/${war.file.name}" />
<delete dir="${deploy.dir}/${war.file}" includeEmptyDirs="true" />
</target>
<target name="war">
<war warfile="${war.file.name}" webxml="./WEB-INF/web.xml">
<fileset dir="./" includes="**/*.*" excludes="*.war, **/*.nbattrs, web.xml, **/WEB-INF/**/*.*, **/project-files/**/*.*"/>
<webinf dir="./WEB-INF" includes="**/*" excludes="web.xml, **/*.jar, **/*.class"/>
<lib dir="./WEB-INF/lib"/>
<classes dir="${build.dir}" includes="**/*.properties" />
</war>
</target>
<target name="deploy">
<copy todir="${deploy.dir}">
<fileset dir="./" includes="${war.file.name}"/>
</copy>
</target>
<target name="main" depends="clean, prep, cleanWebApp, compile, war"/>
</project>
</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" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/building2.jpg" />
<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" />
<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" />
<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" />
<br />
<br />
<br />
<img alt="" src="../images/how-to/netbeans/building6.jpg" />
<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" />
<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" />
<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 />
<br />
<img alt="" src="../images/how-to/netbeans/building8.jpg" />
<br />
<br />
<br />
</li>
<li>
Feel free to change the code as you like, and then build and deploy your new app.
</li>
</ol>
</div>
</div>
<!--end main-->
</div>
<!--end content-->
<div id="footer">
<img id="powered-logo" alt="Powered by Struts" src="../images/struts-power.gif" />
Copyright (c) 2000-2005, The Apache Software Foundation <span class="noprint">-
<a href="http://wiki.apache.org/struts/StrutsDocComments">Comments?</a>
</span>
</div>
<!--end footer-->
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -