Java – error while trying to run weld se application – weld se container failed to initialize – bean archive not found
I created a simple java se application using weld se
:compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :runmai 17,2016 12:55:55 AM org.jboss.weld.bootstrap.WeldStartup <clinit> INFO: WELD-000900: 2.3.4 (Final) Exception in thread "main" java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found at org.jboss.weld.environment.se.Weld.createDeployment(Weld.java:690) at org.jboss.weld.environment.se.Weld.initialize(Weld.java:570) at br.com.alexpfx.crawler.run.Main.main(Main.java:14) Failed 1 result found for 'bean-discovery-mode'Finding with Options: Case Insensitive y bean-discovery-mode 1 found Find Replace in current buffer Replace Replace All Gradle: runFile 0Project 0No Issuessrc\main\resources\Meta-INF\beans.xml10:1 CRLFUTF-8XML1 update
My understanding is that it can't find beans XML file But it exists in Src / main / resources / meta inf / beans In XML:
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" bean-discovery-mode="all" version="1.1"> </beans>
My main courses are:
package br.com.alexpfx.crawler.run; import org.jboss.weld.environment.se.*; import javax.enterprise.inject.*; import javax.inject.*; import br.com.alexpfx.crawler.*; public class Main { @Inject private @Named("SuperMarket") Crawler crawler; public static void main(String[] args) { Weld weld = new Weld(); WeldContainer container = weld.initialize(); Main main = container.instance().select(Main.class).get(); main.run(); weld.shutdown(); } public void run() { System.out.println (crawler); } }
To build a gradle file:
apply plugin: 'java' apply plugin: 'application' repositories{ mavenCentral() } dependencies{ // http://mvnrepository.com/artifact/org.jsoup/jsoup compile group: 'org.jsoup',name: 'jsoup',version: '1.9.1' // http://mvnrepository.com/artifact/org.jboss.weld.se/weld-se-core compile group: 'org.jboss.weld.se',name: 'weld-se-core',version: '2.3.4.Final' } sourceCompatibility = '1.8' version = '1.0' mainClassName = 'br.com.alexpfx.crawler.run.Main'
Solution
The problem is that gradle run does not build jar files for your application It just compiles the class and runs the main class using the resources directory on the classpath (run gradle – info to see for yourself) Weld needs a bean archive that contains meta inf / beans XML or a jar file containing WEB-INF / classes / meta-inf / beans XML war file beans. XML is not enough just on the classpath
To solve this problem, because you are using the application plug-in, just execute gradle installdist and run the shell script or batch file in build / install / myapp / bin