Hello all,
Here's a little post that documents my experience adding the tutorial
(electricity app) to NetBeans. You should already have your Tomcat
server and MySQL server registered in the IDE and know how to run an
SQL file on a database from the services tab.
Unzipped and moved the electricity folder to <mypath>
\netbeans_projects directory and begin by using the New Project
wizard.
File > New Project...
1)
Category = Java Web
Projects = Web Application with Existing Sources
Next >
2)
Location = <mypath>\netbeans_projects\electricity
Project Name = electricity
Project Folder = <mypath>\netbeans_projects\electricity
Next >
3)
Server = Tomcat 6.0
Java EE Version = Java EE5
Context Path = /electricity
Next >
4)
Web Pages Folder = <mypath>\netbeans_projects\electricity
WEB-INF Content = <mypath>\netbeans_projects\electricity\WEB-INF
Libraries Folder = <mypath>\netbeans_projects\electricity\WEB-INF\lib
An error is displayed on page 4 of the wizard saying the Web Pages
folder overlaps the Project folder.
Ooooops, Hmmmm. Hit Cancel.
I look in the projects tab for an old Java Web Application I've made
in the past (found CustomerDB) and then use the Files tab to look at
the directory structure:
CustomerDB
+build/
+dist/
+nbproject/
+src/
+test/
-web/
+WEB-INF/
index.jsp
+build.xml
I go to <mypath>\netbeans_projects\electricity and create a new folder
called web. Then I dump all of the contents of <mypath>
\netbeans_projects\electricity\ into <mypath>\netbeans_projects
\electricity\web\.
Try the wizard again. File > New Project...
1)
Category = Java Web
Projects = Web Application with Existing Sources
Next >
2)
Location = <mypath>\netbeans_projects\electricity
Project Name = electricity
Project Folder = <mypath>\netbeans_projects\electricity
Next >
3)
Server = Tomcat 6.0
Java EE Version = Java EE5
Context Path = /electricity
Next >
4)
Web Pages Folder = <mypath>\netbeans_projects\electricity\web
WEB-INF Content = <mypath>\netbeans_projects\electricity\WEB-INF
Libraries Folder = <mypath>\netbeans_projects\electricity\WEB-INF\lib
Finish
I choose to delete the compiled class files as recommended by the
ensuing dialog box. Time passes and then my project is created.
Then I go to the services tab, make sure my MySQL server is registered
in the IDE, create the database connection then right-click the
connection and choose Execute Command... copy the contents of
CreateTables.SQL file to the SQL tab and execute.
Go to Tools > Servers and select the Tomcat 6.0 server. The deployment
tab should have the enable JDBC driver deployment tab checked. Then
select the classes tab. If the driver (mysql-connector-java-5.1.6-
bin.jar) file is not there, it will be automatically added at
deployment. If it does not or you get errors in the output pane when
attempting to deploy then edit META-INF/context.xml to make sure you
have this entry:
<Context antiJARLocking="true" path="/electricity">
<Resource name="jdbc/electricity" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/electricity"/>
</Context>
In the projects tab, right-click the electricity project and select
run from the context menu. A browser will open and display the welcome
page at
http://localhost:8080/electricity/. Click the Edit link and
you should get the Spending page. If not, double check the META-INF/
content.xml as mentioned above.
You should now be ready for Adding a New Feature on
http://www.web4j.com/Tutorial.jsp.
Optional - create a WEB4J library in NetBeans and replace the
web4j.jar with a current library:
At this point I want to make sure I'm using the latest version of the
web4j.jar so I download the latest release from the web site, save it
to some location, create a WE4J library in NetBeans and add the jar
file. Now all I have to do is overwrite the old jar file with the new
one to keep it current. Then I go to the projects pane, expand the
Libraries node, remove web4j.jar, right-click the Libraries node,
select Add Library... then add the WEB4J library from the list of
registered libraries. Right, click the project and select run project
from the context menu. Creating new Libraries in NetBeans is
straightforward enough.
Regards,
Bill