简体   繁体   English

如何将Weld集成到Maven项目中?

[英]How to integrate Weld to the maven project?

Trying to import this projects (With Weld) and it can`t 尝试导入此项目(使用Weld),但无法

import org.jboss.weld.environment.se

to use Weld class in project. 在项目中使用Weld类。

https://github.com/agoncal/agoncal-book-javaee7 https://github.com/agoncal/agoncal-book-javaee7

It really depends on what you are trying to achieve. 这实际上取决于您要实现的目标。 Are you writing a Java EE web application (war/ear) or a standalone app? 您是在编写Java EE Web应用程序(war / ear)还是独立的应用程序? Also: Weld is the reference implementation of CDI and CDI is just a part of Java EE. 另外:Weld是CDI的参考实现,而CDI只是Java EE的一部分。 If you use CDI only (by setting up weld-se), you cannot use EJB/EntityManager/Transactional/... , its "just" CDI. 如果仅使用CDI(通过设置weld-se),则不能使用EJB / EntityManager / Transactional / ...,即其“只是” CDI。

That all being said: using weld-se in a java standalone application can be done by importing 话虽如此:在Java独立应用程序中使用weld-se可以通过导入来完成

<dependency>
  <groupId>org.jboss.weld.se</groupId>
  <artifactId>weld-se</artifactId>
  <version>2.2.6.Final</version>
 </dependency>

Bootstrapping the application "Main.class" is done via 通过以下方式引导应用程序“ Main.class”

    // Initialize Weld
    Weld theWeld = new Weld();
    WeldContainer theContainer = theWeld.initialize();


    // Execute the run method
    theContainer.instance().select(Main.class).get().run();


    // Shutting down Weld again
    theWeld.shutdown();

According this book at first you should install aplication server to run your applications. 首先,根据这本书,您应该安装应用服务器来运行您的应用程序。 In your case it will be Glassfish. 在您的情况下,它将是Glassfish。 The same question were discussed here . 这里讨论了相同的问题。

I have also tried to run a sample from this book without any modifications. 我也尝试过对本书进行采样,而不做任何修改。 The reason it does not work is that non-existing Weld version is specified in the <dependency> block: 它不起作用的原因是在<dependency>块中指定了不存在的Weld版本:

<dependency>
  <groupId>org.jboss.weld.se</groupId>
  <artifactId>weld-se</artifactId>
  <version>2.0.0</version>
 </dependency>

Just compare with the list of available versions and ensure the version 2.0.0 is not present here: http://repo1.maven.org/maven2/org/jboss/weld/se/weld-se/ 只需与可用版本列表进行比较,并确保此处不存在版本2.0.0http : //repo1.maven.org/maven2/org/jboss/weld/se/weld-se/

You can use any other version, for example 您可以使用任何其他版本,例如

<dependency>
  <groupId>org.jboss.weld.se</groupId>
  <artifactId>weld-se</artifactId>
  <version>2.0.0.Final</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM