Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GettingStartedOnNetBeans.asciidoc 5.3KB

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