0

Trying to import this projects (With Weld) and it can`t

import org.jboss.weld.environment.se

to use Weld class in project.

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

Piarix
  • 107
  • 3
  • 11

3 Answers3

3

It really depends on what you are trying to achieve. Are you writing a Java EE web application (war/ear) or a standalone app? Also: Weld is the reference implementation of CDI and CDI is just a part of Java EE. If you use CDI only (by setting up weld-se), you cannot use EJB/EntityManager/Transactional/... , its "just" CDI.

That all being said: using weld-se in a java standalone application can be done by importing

<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

    // 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();
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
0

According this book at first you should install aplication server to run your applications. In your case it will be Glassfish. The same question were discussed here.

Community
  • 1
  • 1
njjnex
  • 1,490
  • 13
  • 23
0

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>
  <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/

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>