官术网_书友最值得收藏!

  • Vaadin 7 Cookbook
  • Jaroslav Holaň Ond?ej Kvasnovsk?
  • 501字
  • 2021-07-23 14:19:32

Generating a Vaadin project in Maven archetype

Maven makes the build process really easy. Let's see how easy it is to make a new Vaadin project using Maven. We will use the latest version, Maven 3, which can be downloaded from http://maven.apache.org/download.html.

We are going to use the command line in this recipe. We will make the project in the command prompt and then we can import the Maven project into whatever IDE that supports Maven (Eclipse, IntelliJ IDEA, and so on).

Using Maven archetypes is quite handy and a quick way to create a new project. Let's try to make a new Vaadin project using the vaadin-archetype-application archetype.

For those who are new to Maven, please learn the basics from the following web page:

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

How to do it...

Carry out the following steps in order to create a new project in Maven:

  1. Open the command prompt and check whether Maven is installed properly. The version of Maven should be displayed. If not, then search the Web for how to install Maven 3 on your operating system.
    $ mvn --version
    Apache Maven 3.0.4
    Maven home: /usr/share/maven
    
  2. Decide where to put your project and run the following command. It will create a new folder called vaadin-in-maven-arch with a sample Vaadin project using the Maven file structure.
    mvn archetype:generate \
     -DarchetypeGroupId=com.vaadin \
     -DarchetypeArtifactId=vaadin-archetype-application \
     -DarchetypeVersion=LATEST \
     -Dpackaging=war \
     -DgroupId=app \
     -DartifactId=vaadin-in-maven-arch \
     -Dversion=1.0 
    
  3. Maven asks for confirmation of whether to create the project. Type y into the console. Maven will show its BUILD SUCCESS message after the project is created.
    Confirm properties configuration:
    groupId: app
    artifactId: vaadin-in-maven-arch
    version: 1.0
    package: app
     Y: : y
    
  4. Run the package Maven target in order to pack the application as a WAR file and compile the widget set. Run the following command in the root of the project.
    mvn package
    
  5. We are done and we can run our new web application. Go to the root of the project where pom.xml file is located and run the following command.
    mvn jetty:start
    

    The application will be running on http://localhost:8080.

Tip

We are using Jetty, which is open source and a commercially usable web server. Jetty is great for development because it starts really fast.

How it works...

We have made a new Vaadin application from the Maven archetype and all the content needed for running the application was generated fr us.

Let's have a look at the folder structure in the project.

Maven archetype could be described as a project template. We can create our own archetypes by running the following command inside the Maven project:

mvn archetype:generate

There's more...

We can configure auto-redeploys in Jetty. The scanning interval can be set to, for example, 2 seconds. After we recompile the code, Jetty redeploys the application so we don't have to stop and start the application server after each change in the code. The following change needs to be made in the pom.xml file:

<scanIntervalSeconds>2</scanIntervalSeconds>

More about the Jetty plugin can be found on the following link:

http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

主站蜘蛛池模板: 苍梧县| 定襄县| 吴江市| 桐庐县| 漯河市| 武邑县| 鱼台县| 邹平县| 太谷县| 垣曲县| 辽阳县| 长阳| 明星| 墨江| 宜都市| 玉龙| 封丘县| 普宁市| 临潭县| 海南省| 泾阳县| 蒙阴县| 巩义市| 抚州市| 金阳县| 安达市| 赞皇县| 忻州市| 嘉黎县| 奉贤区| 温宿县| 泾源县| 和林格尔县| 威信县| 太仆寺旗| 瓮安县| 天台县| 朔州市| 乐至县| 清水县| 屏边|