You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GettingStartedOnNetBeans.asciidoc 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ---
  2. title: Getting Started On NetBeans
  3. order: 76
  4. layout: page
  5. ---
  6. [[getting-started-on-netbeans]]
  7. Getting started on NetBeans
  8. ---------------------------
  9. *This page is for old NetBeans version. Take a look at
  10. http://wiki.netbeans.org/VaadinPlugin1.0.0[New plugin in NetBeans wiki]*
  11. [[your-first-project-with-vaadin-in-netbeans-ide-6.7]]
  12. Your First Project with Vaadin in NetBeans IDE 6.7
  13. --------------------------------------------------
  14. Eclipse users have access to the http://vaadin.com/eclipse[Vaadin Eclipse
  15. plugin] which
  16. is probably the easiest way to get started with the Vaadin framework. But
  17. if you preferNetBeans IDE, this is the article for you. And don't worry,
  18. it's almost as easy to get started with NetBeans also.
  19. This tutorial assumes you have downloaded and installed a bundle of
  20. http://www.netbeans.org[NetBeans 6.7] that
  21. includes the Apache Tomcat server (the "Java Web & EE" support) and you
  22. have the latest
  23. http://vaadin.com/download[Vaadin] JAR
  24. package at hand.
  25. [[creating-the-project]]
  26. Creating the Project
  27. ~~~~~~~~~~~~~~~~~~~~
  28. image:img/netbeans_new_project.png[NetBeans new project]
  29. Launch your NetBeans IDE and perform the following steps to create a new
  30. web project.
  31. * Select `File -> New Project` to open the New Project dialog
  32. window.
  33. * Select `Java Web` from the categories and `Web Application`
  34. from the project selection and click `Next` to proceed.
  35. * Type in a name and location for your project (I use `HelloVaadin` as
  36. the name and my default project folder) and click `Next`.
  37. * Select the `Apache Tomcat 6.0.18` server and type in preferred
  38. context path or use the default (the project name). The context path
  39. will define the URL of your application (for example
  40. `http://localhost:8084/HelloVaadin`). Click `Finish` to create the
  41. project.
  42. * You can close and ignore the index.jsp, which is opened to the editor
  43. by default after the project has been created.
  44. [[importing-vaadin-libraries]]
  45. Importing Vaadin Libraries
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. Next you need to import the Vaadin library JAR package to the project
  48. you just created.
  49. * Right-click the `Libraries` node on your project and select `Add
  50. JAR/Folder...`.
  51. * Locate your copy of the Vaadin JAR file in the opening file dialog and
  52. click `Open`.
  53. * Now you should see the JAR file under the Libraries node.
  54. [[writing-the-code]]
  55. Writing the Code
  56. ~~~~~~~~~~~~~~~~
  57. Next we create the application class for our simple example application.
  58. * Select `New -> Java Class` on your project to open the New Java
  59. Class dialog.
  60. * Type in your a name and package for your class (I use a class name of
  61. `HelloVaadin` and a package `com.vaadin.netbeans.tutorial`).
  62. * Select `Finish` to create the Java class.
  63. This class will be the main application class of our Vaadin
  64. application.Therefore it must extend the abstract
  65. `com.vaadin.Application` class and implement the `init()` method.
  66. Type in or copy-paste the following code to the newly created file:
  67. [source,java]
  68. ....
  69. package com.vaadin.netbeans.tutorial;
  70. import com.vaadin.Application;
  71. import com.vaadin.ui.*;
  72. public class HelloVaadin extends Application {
  73. @Override
  74. public void init() {
  75. Window mainWindow = new Window("HelloVaadin");
  76. Label label = new Label("Hello Vaadin user");
  77. mainWindow.addComponent(label);
  78. setMainWindow(mainWindow);
  79. }
  80. }
  81. ....
  82. [[defining-deployment-descriptor]]
  83. Defining Deployment Descriptor
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. To run your application you must define a deployment descriptor for it.
  86. Open `Web Pages -> WEB-INF -> web.xml` file on your project. By
  87. default the file is opened in a graphical editor but you can select the
  88. XML tab to edit the XML file directly. Type in or copy-paste the
  89. following to the contents of the file.
  90. [source,xml]
  91. ....
  92. <?xml version="1.0" encoding="UTF-8"?>
  93. <web-app version="2.5"
  94. xmlns="http://java.sun.com/xml/ns/javaee"
  95. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  96. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  97. <display-name>HelloVaadin</display-name>
  98. <context-param>
  99. <param-name>productionMode</param-name>
  100. <param-value>false</param-value>
  101. <description>Vaadin production mode</description>
  102. </context-param>
  103. <servlet>
  104. <servlet-name>HelloVaadin</servlet-name>
  105. <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
  106. <init-param>
  107. <param-name>application</param-name>
  108. <param-value>com.vaadin.netbeans.tutorial.HelloVaadin</param-value>
  109. <description>Vaadin application class to start</description>
  110. </init-param>
  111. </servlet>
  112. <servlet-mapping>
  113. <servlet-name>HelloVaadin</servlet-name>
  114. <url-pattern>/*</url-pattern>
  115. </servlet-mapping>
  116. </web-app>
  117. ....
  118. [[running-your-application]]
  119. Running Your Application
  120. ~~~~~~~~~~~~~~~~~~~~~~~~
  121. Now we can run (or debug) the application by simply selecting `Run ->
  122. Run Main Project` (or `Run -> Debug Main Project`).This starts the
  123. Apache Tomcat server and opens up your application in your default
  124. browser.
  125. image:img/netbeans_hello_vaadin.png[NetBeans "Hello Vaadin"]
  126. [[what-next]]
  127. What Next?
  128. ~~~~~~~~~~
  129. Now that you have your environment setup, you probably want to explore
  130. more of the features of the Vaadin framework. I would suggest that
  131. you head to the http://vaadin.com/tutorial[Vaadin tutorial].
  132. Have fun with Vaadin!
  133. [[update]]
  134. Update
  135. ~~~~~~
  136. * http://vaadin.com/netbeans[Vaadin Plugin for NetBeans 6.8]