Trying to import this projects (With Weld) and it can`t
import org.jboss.weld.environment.se
to use Weld class in project.
Trying to import this projects (With Weld) and it can`t
import org.jboss.weld.environment.se
to use Weld class in project.
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();
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>