2013-10-07 32 views
0

我想在一個非常簡單的例子,基本上遵循this one焊接工作。但是,我無法得到它的工作。焊接與StartMain不起作用

我使用gradle來建造。這是我的build.gradle:

apply plugin: 'java' 

version='1.0-SNAPSHOT' 

repositories { 
    mavenCentral() 
} 

task wrapper(type: Wrapper) { 
    gradleVersion = '1.8' 
} 

jar { 
    dependsOn configurations.runtime 
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } 
} 

task hello(type: JavaExec) { 
    main = 'org.jboss.weld.environment.se.StartMain' 
    classpath = sourceSets.main.runtimeClasspath 
} 

dependencies { 
    compile 'org.jboss.weld.se:weld-se:2.0.4.Final' 
} 

我有這些文件在src文件夾中。

./src/main/java/weldse/HelloWorld.java 
./src/main/resources/META-INF/beans.xml 

內容如下。

HelloWorld.java

package weldse; 

import org.jboss.weld.environment.se.events.ContainerInitialized; 

import javax.enterprise.event.Observes; 

public class HelloWorld { 

    public void printHello(@Observes ContainerInitialized event) { 
     System.out.println("Hello, World"); 
    } 
} 

的beans.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" 
     version="1.1" bean-discovery-mode="all"> 
</beans> 

當我運行gradle hello,我沒有得到輸出Hello, World但這些消息的BUILD SUCCESSFUL

[main] INFO org.jboss.weld.Version - WELD-000900 2.0.4 (Final) 
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled 

但是,當我直接使用java運行它時,出現異常。這是完整的堆棧跟蹤。

$ java -cp build/libs/weld-se-1.0-SNAPSHOT.jar org.jboss.weld.environment.se.StartMain 
[main] INFO org.jboss.weld.Version - WELD-000900 SNAPSHOT 
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously. 
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.HttpSessionBean because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.HttpServletRequestBean because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.ServletContextBean because of underlying class loading error: Type javax.servlet.ServletContext not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.UserTransactionBean$UserTransactionCallable because of underlying class loading error: Type javax.transaction.UserTransaction not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.RequestBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.LazySessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.EagerSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.AbstractSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.LazyCyclicSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpConversationContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpRequestContextImpl because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpConversationContextImpl because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionDestructionContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionContextImpl because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.event.TransactionalObserverNotifier because of underlying class loading error: Type javax.transaction.Synchronization not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.event.TransactionSynchronizedRunnable because of underlying class loading error: Type javax.transaction.Synchronization not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.injection.spi.JpaInjectionServices because of underlying class loading error: Type javax.persistence.EntityManager not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.injection.spi.helpers.ForwardingJpaInjectionServices because of underlying class loading error: Type javax.persistence.EntityManager not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.SessionHolder because of underlying class loading error: Type javax.servlet.http.HttpSession not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.ConversationFilter because of underlying class loading error: Type javax.servlet.Filter not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldCrossContextFilter because of underlying class loading error: Type javax.servlet.Filter not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.ConversationContextActivator because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldTerminalListener because of underlying class loading error: Type javax.servlet.http.HttpSessionListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.helpers.ForwardingServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldInitialListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.transaction.spi.TransactionServices because of underlying class loading error: Type javax.transaction.Synchronization not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.helpers.AbstractServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.ServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.HttpContextLifecycle because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.validation.spi.ValidationServices because of underlying class loading error: Type javax.validation.ValidatorFactory not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.ext.MDCStrLookup because of underlying class loading error: Type org.apache.commons.lang.text.StrLookup not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.instrumentation.JavassistHelper because of underlying class loading error: Type javassist.CtBehavior not found. If this is unexpected, enable DEBUG logging to see the full error. 
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.instrumentation.LogTransformer because of underlying class loading error: Type javassist.CtBehavior not found. If this is unexpected, enable DEBUG logging to see the full error. 
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled 
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled 
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: Exception List with 4 exceptions: 
Exception 0 : 
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type InstanceManager with qualifiers @Default 
    at injection point [UnbackedAnnotatedParameter] Parameter 1 of [UnbackedAnnotatedConstructor] @Inject protected org.jboss.weld.environment.se.WeldContainer(InstanceManager, BeanManager) 
    at org.jboss.weld.environment.se.WeldContainer.<init>(WeldContainer.java:0) 
    Possible dependencies: 
    - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default], 
    - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default] 

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412) 
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327) 
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178) 
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209) 
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 
Exception 0 : 
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type InstanceManager with qualifiers @Default 
    at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject protected org.jboss.weld.environment.se.WeldContainer(InstanceManager, BeanManager) 
    at org.jboss.weld.environment.se.WeldContainer.<init>(WeldContainer.java:0) 
    Possible dependencies: 
    - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default], 
    - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default] 

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412) 
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327) 
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178) 
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209) 
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 
Exception 0 : 
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type Instance<Object> with qualifiers @Any 
    at injection point [UnbackedAnnotatedField] @Inject @Any org.jboss.weld.environment.se.beans.InstanceManager.instances 
    at org.jboss.weld.environment.se.beans.InstanceManager.instances(InstanceManager.java:0) 
    Possible dependencies: 
    - Managed Bean [class org.jboss.weld.Weld] with qualifiers [@Any @Default], 
    - Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [@Default], 
    - Managed Bean [class org.jboss.weld.servlet.StaticWeldProvider$EnhancedWeld] with qualifiers [@Any @Default] 

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412) 
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327) 
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178) 
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209) 
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 
Exception 0 : 
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type Instance<Object> with qualifiers @Any 
    at injection point [BackedAnnotatedField] @Inject @Any org.jboss.weld.environment.se.beans.InstanceManager.instances 
    at org.jboss.weld.environment.se.beans.InstanceManager.instances(InstanceManager.java:0) 
    Possible dependencies: 
    - Managed Bean [class org.jboss.weld.Weld] with qualifiers [@Any @Default], 
    - Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [@Default], 
    - Managed Bean [class org.jboss.weld.servlet.StaticWeldProvider$EnhancedWeld] with qualifiers [@Any @Default] 

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412) 
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327) 
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178) 
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209) 
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71) 
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60) 
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:724) 

    at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:79) 
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:491) 
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:538) 
    at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.validateBeans(ForwardingBootstrap.java:75) 
    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:144) 
    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41) 
    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52) 

在我看來,有是導致異常的InstanceManager歧義。但是,我不確定。無論如何,你知道如何做這個工作嗎?非常感謝你。

回答

3

看來這是一個焊接問題,並且不會很快被修復。無論如何,我發現了一個workaround,它基本上排除了焊接的豆狀掃描。在情況下,鏈接到解決方法到期在未來,這裏是解決辦法的beans.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" 
    xmlns:weld="http://jboss.org/schema/weld/beans" 
    xsi:schemaLocation=" 
      http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd 
      http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd"> 
    <weld:scan> 
     <weld:exclude name="org.jboss.weld.**" /> 
    </weld:scan> 
</beans> 

基本上,你需要做的是與您當前的beans.xml合併這beans.xml