vaadin

当我开发Web应用程序时,我希望能够从Eclipse快速启动它们,而不必依赖各种重量级的tomcat或glassfish插件。 因此,我经常要做的就是创建一个可以直接从Eclipse直接运行的基于Java的简单Jetty启动器。 该启动器会在几秒钟内启动,因此使开发工作更加愉快。

但是,有时正确设置所有内容会有些困难。 因此,在本文中,我将向您快速概述如何将Jetty与Weld for CDI和Vaadin一起设置为Web框架。

为了正确设置所有内容,我们需要执行以下步骤:

  1. 为所需的依赖项设置Maven Pom
  2. 创建一个基于Java的Jetty启动器
  3. 设置web.xml
  4. 添加焊接占位符

为所需的依赖项设置Maven Pom

我使用以下pom.xml文件。 如果您不使用自定义组件,则可能不需要所有东西。 但是它应该作为其中应该包含的内容的良好参考。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>group.id</groupId><artifactId>artifact.id</artifactId><packaging>war</packaging><version>1.0</version><name>Vaadin Web Application</name><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><vaadin.version>6.7.1</vaadin.version><gwt.version>2.3.0</gwt.version><gwt.plugin.version>2.2.0</gwt.plugin.version></properties><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.5</source><target>1.5</target></configuration></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>gwt-maven-plugin</artifactId><version>${gwt.plugin.version}</version><configuration><webappDirectory>${project.build.directory}/${project.build.finalName}/VAADIN/widgetsets</webappDirectory><extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs><runTarget>cvgenerator-web</runTarget><hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp><noServer>true</noServer><port>8080</port><compileReport>false</compileReport></configuration><executions><execution><goals><goal>resources</goal><goal>compile</goal></goals></execution></executions><dependencies><dependency><groupId>com.google.gwt</groupId><artifactId>gwt-dev</artifactId><version>${gwt.version}</version></dependency><dependency><groupId>com.google.gwt</groupId><artifactId>gwt-user</artifactId><version>${gwt.version}</version></dependency></dependencies></plugin><plugin><groupId>com.vaadin</groupId><artifactId>vaadin-maven-plugin</artifactId><version>1.0.2</version><executions><execution><configuration></configuration><goals><goal>update-widgetset</goal></goals></execution></executions></plugin></plugins></build><!-- extra repositories for Vaadin extensions --><repositories><repository><id>vaadin-snapshots</id><url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url><releases><enabled>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository><repository><id>vaadin-addons</id><url>http://maven.vaadin.com/vaadin-addons</url></repository></repositories><!-- repositories for the plugins --><pluginRepositories><pluginRepository><id>codehaus-snapshots</id><url>http://nexus.codehaus.org/snapshots</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>false</enabled></releases></pluginRepository><pluginRepository><id>vaadin-snapshots</id><url>http://oss.sonatype.org/content/repositories/vaadin-snapshots/</url><snapshots><enabled>true</enabled></snapshots><releases><enabled>false</enabled></releases></pluginRepository></pluginRepositories><!-- minimal set of dependencies --><dependencies><dependency><groupId>com.vaadin</groupId><artifactId>vaadin</artifactId><version>${vaadin.version}</version></dependency><dependency><groupId>org.vaadin.addons</groupId><artifactId>stepper</artifactId><version>1.1.0</version></dependency><!-- the jetty version we'll use --><dependency><groupId>org.eclipse.jetty.aggregate</groupId><artifactId>jetty-all-server</artifactId><version>8.0.4.v20111024</version><type>jar</type><scope>compile</scope><exclusions><exclusion><artifactId>mail</artifactId><groupId>javax.mail</groupId></exclusion></exclusions></dependency><!-- vaadin custom field addon --><dependency><groupId>org.vaadin.addons</groupId><artifactId>customfield</artifactId><version>0.9.3</version></dependency><!-- with cdi utils plugin you can use Weld --><dependency><groupId>org.vaadin.addons</groupId><artifactId>cdi-utils</artifactId><version>0.8.6</version></dependency><!-- we'll use this version of Weld --><dependency><groupId>org.jboss.weld.servlet</groupId><artifactId>weld-servlet</artifactId><version>1.1.5.Final</version><type>jar</type><scope>compile</scope></dependency><!-- normally following are provided, but not if you run within jetty --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><type>jar</type><scope>provided</scope></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version><type>jar</type><scope>provided</scope></dependency><dependency><artifactId>el-api</artifactId><groupId>javax.el</groupId><version>2.2</version><scope>provided</scope></dependency></dependencies></project>

创建Java启动器

有了这个pom,我们就有了一起运行Jetty,Vaadin和Weld所需的所有依赖项。 让我们看一下Jetty Launcher。

import javax.naming.InitialContext;
import javax.naming.Reference;import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;/*** Simple jetty launcher, which launches the webapplication from the local* resources and reuses the projects classpath.* * @author jos*/
public class Launcher {/** run under root context */private static String contextPath = "/";/** location where resources should be provided from for VAADIN resources */private static String resourceBase = "src/main/webapp";/** port to listen on */private static int httpPort = 8081;private static String[] __dftConfigurationClasses ={"org.eclipse.jetty.webapp.WebInfConfiguration","org.eclipse.jetty.webapp.WebXmlConfiguration","org.eclipse.jetty.webapp.MetaInfConfiguration", "org.eclipse.jetty.webapp.FragmentConfiguration",        "org.eclipse.jetty.plus.webapp.EnvConfiguration","org.eclipse.jetty.webapp.JettyWebXmlConfiguration"} ;/*** Start the server, and keep waiting.*/public static void main(String[] args) throws Exception {System.setProperty("java.naming.factory.url","org.eclipse.jetty.jndi");System.setProperty("java.naming.factory.initial","org.eclipse.jetty.jndi.InitialContextFactory");InitialContext ctx = new InitialContext();ctx.createSubcontext("java:comp");Server server = new Server(httpPort);WebAppContext webapp = new WebAppContext();webapp.setConfigurationClasses(__dftConfigurationClasses);webapp.setDescriptor("src/main/webapp/WEB-INF/web.xml");webapp.setContextPath(contextPath);webapp.setResourceBase(resourceBase);webapp.setClassLoader(Thread.currentThread().getContextClassLoader());server.setHandler(webapp);server.start();new Resource("BeanManager", new Reference("javax.enterprise.inject.spi.BeanMnanager","org.jboss.weld.resources.ManagerObjectFactory", null));server.join();}
}

此代码将启动一个Jetty服务器,该服务器使用项目中的web.xml来启动Vaadin Web应用程序。 请注意,我们明确使用
setConfigurationClasses
操作。 这是确保我们具有可用于注册Weld beanmanager的JNDI上下文所必需的。

设置web.xml

接下来,我们看一下web.xml。 接下来显示我在此示例中使用的一个:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>Vaadin Web Application</display-name><context-param><description>Vaadin production mode</description><param-name>productionMode</param-name><param-value>false</param-value></context-param><servlet><servlet-name>example</servlet-name><servlet-class>ServletSpecifiedByTheCDIVaadinPlugin</servlet-class><init-param><description>Vaadin application class to start</description><param-name>application</param-name><param-value>VaadinApplicationClassName</param-value></init-param><init-param><param-name>widgetset</param-name><param-value>customwidgetsetnameifyouuseit</param-value></init-param></servlet><servlet-mapping><servlet-name>example</servlet-name><url-pattern>/example/*</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file></welcome-file-list><listener><listener-class>org.jboss.weld.environment.servlet.Listener</listener-class></listener><resource-env-ref><description>Object factory for the CDI Bean Manager</description><resource-env-ref-name>BeanManager</resource-env-ref-name><resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type></resource-env-ref>
</web-app>

在web.xml的底部,您可以看到为Weld定义的resource-env以及所需的侦听器,以确保启动Weld并注入了bean。 您还可以看到我们指定了一个不同的servlet名称,而不是普通的Vaadin servlet。 有关此内容的详细信息,请参见CDI插件页面: https : //vaadin.com/directory#addon/cdi-utils

主要步骤是(从该页面获取):

  1. 在WEB-INF目录下将空bean.xml -file(CDI标记文件)添加到您的项目中
  2. 将cdiutils * .jar添加到WEB-INF / lib下的项目中
  3. 通过扩展AbstractCdiApplication创建您的Application类
  4. 扩展AbstractCdiApplicationServlet并使用@WebServlet(urlPatterns =“ / *”)对其进行注释
  5. 部署到与JavaEE / Web配置文件兼容的容器(CDI应用程序也可以在servlet容器等上运行,但需要进行一些进一步的配置)

添加焊接占位符

至此,我们已经拥有所有依赖项,我们创建了可直接从Eclipse使用的启动器,并确保在启动时加载了Weld。 我们还为Vaadin配置了CDI插件。 至此,我们差不多完成了。 我们只需要在想被Weld的bean发现包括的位置添加空bean.xml文件。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

我必须将这些添加到
src / main / java / META-INF
图书馆和 网络信息 Weld的目录以拾取所有带注释的bean。 就是这样。 现在,您可以启动启动器,并且应该看到出现了所有的Weld和Vaadin日志记录。

参考:来自JCG合作伙伴的 Embedded Jetty,Vaadin和Weld   Smart Java博客中的Jos Dirksen。

翻译自: https://www.javacodegeeks.com/2012/02/embedded-jetty-vaadin-and-weld.html

vaadin

vaadin_嵌入式码头,Vaadin和焊接相关推荐

  1. 嵌入式码头,Vaadin和焊接

    当我开发Web应用程序时,我希望能够从Eclipse快速启动它们,而不必依赖各种重量级的tomcat或glassfish插件. 因此,我通常要做的只是创建一个可以直接从Eclipse运行的基于Java ...

  2. apache.camel_使用Apache Camel 2.14的轻松REST端点

    apache.camel Apache Camel 最近发布了一个新版本 , 其中一些新功能由我的同事Claus Ibsen博客发布 . 您确实应该检查他的博客条目并深入研究更多细节,但是我一直希望尝 ...

  3. jersey put 服务_项目学生:带有Jersey的Web服务服务器

    jersey put 服务 这是Project Student的一部分. 其他职位包括带有Jersey的Webservice Client , 业务层和带有Spring Data的持久性 . REST ...

  4. 使用Apache Camel 2.14的轻松REST端点

    Apache Camel 最近发布了一个新版本 , 其中一些新功能由我的同事Claus Ibsen博客发布 . 您确实应该检查他的博客条目并深入研究更多细节,但是我希望尝试的功能之一是新的REST D ...

  5. 项目学生:带有Jersey的Web服务服务器

    这是Project Student的一部分. 其他职位包括带有Jersey的Webservice Client , 业务层和带有Spring Data的持久性 . RESTful Web应用程序洋葱的 ...

  6. gradle maven_Gradle vs Maven

    gradle maven In this post, we are going to discuss gradle vs maven. We will also see how to run grad ...

  7. amd处理器更新zen4服务器芯片,AMD将推出64 核心Zen 4处理器,整体性能提升了40%...

    EETC https://www.eet-china.com 最近几年,AMD发力,新品层出不穷,最近爆出其将推出64核心的Zen 4 EPYC Genoa7004处理器,由96个内核和192个线程组 ...

  8. 使用DFM应该注意的几个事项

    作为PCB设计师,您有各种不同的要求和期望. 有电气,功能和机械方面要考虑.此外,PCB必须以尽可能低的成本尽可能高的质量生产.通过所有这些要求,DFM应运而生,是专门诊断PCB开短路等问题的自动化软 ...

  9. Apache CXF - 快速指南

    Apache CXF - 简介 在当今的环境中,您可以使用多个选项来创建 Web 服务应用程序.您可以使用多种标准和广泛接受的协议中的一种或多种进行通信.例如SOAP.XML/HTTP.RESTful ...

最新文章

  1. STM8S103 解决Rom空间不足 Map文件分析
  2. python高阶函数filter_python 高阶函数之filter
  3. CowNew开源-sql解析引擎和cownewsql阶段成果汇报
  4. kotlin 协程异常处理机制颠覆三观
  5. Jmeter中JDBC链接配置 JDBC Connection Configuration
  6. 深入理解Memory Order
  7. 类欧几里得算法详细推导过程(附带模板)
  8. Linux SPI框架
  9. 第十二章 图形用户界面
  10. bash 的相关配置
  11. shell脚本:批量修改文件名(文件名中添加字符)
  12. c语言五子棋光标,c语言写的鼠标操作的五子棋游戏,欢迎观赏!
  13. bc8android汽车中控屛功能有哪些,安卓大屏功能强大 卡仕达顺车机一机全能
  14. windows下客户端连接上马上会断开连接_zookeeper系列客户端的骚操作amp; Curator使用...
  15. HTML加载图片跨域
  16. 杜静20176395
  17. Acer宏碁暗影骑士3进阶版无法进入系统引导修复
  18. LaTex关于数学公式的使用(5)--- 积分
  19. 操作系统--进程调度实验报告
  20. excel和matlab交互,Excel与Matlab的数据交互(精选5篇)

热门文章

  1. 好玩的Scratch
  2. 2020蓝桥杯省赛---java---C---3( 跑步训练)
  3. IDEA 配置Maven项目
  4. python处理脑电信号_用ICA去除脑电信号中的眼球链接
  5. linux mysql复制一个表结构图_详解Windows和Linux下从数据库导出表结构,以及Linux下如何导入.sql文件到MySQL数据库...
  6. 电脑任务栏跑到右边去了_电脑没有声音怎么解决 电脑没有声音解决方法【详解】...
  7. XML——流机制解析器
  8. apache ignite_Kubernetes集群上的Apache Ignite和Spring第3部分:测试应用程序
  9. system health_可重复使用的MicroProfile Health探针
  10. portlet_平台策略:从Portlet到OpenSocial小工具再到渐进式Web应用程序:最新技术