1

I Got the following exception while trying to run JAVA SE executable jar from command line:

Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: java.lang.Internand
    at org.jboss.weld.executor.AbstractExecutorServices.checkForExceptions(AbstractExec
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions()
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions()
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer.addClasses(ConcurrentBeanDeploye
    at org.jboss.weld.bootstrap.BeanDeployment.createClasses(BeanDeployment.java:203)
    at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:374)
    at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76
    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:556)
    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:44)
    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:53)
Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.InternalError: Enclo at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2197) at com.google.common.cache.LocalCache.get(LocalCache.java:3932) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806) at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java at org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils. at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransforme at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransforme at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoad at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoad at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97) at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer. at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer. at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFac at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFac at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.InternalError: Enclosing method not found at java.lang.Class.getEnclosingMethod(Class.java:1065) at sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50) at sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:78 at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:96) at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:96) at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:96) at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:96) at sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflecti at sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165 at sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.jav at sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository. at java.lang.reflect.Method.getGenericReturnType(Method.java:255) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.(BackedAnnotate at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.of(BackedAnnotatedMet at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods..java:195) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods..java:188) at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:35) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyVdType.java:156) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.188) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.188) at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.(BackedAnnotatedT at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType. at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.lo at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.lo at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.j at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2315) at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2278) at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2193) ... 18 more

However I'am able to run the program sucessfully in eclipse but once packaged into jar I always end up with this error.

Here is my maven package plugin:

     <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
 <!-- Build an executable JAR -->
    <plugin>
      <!-- Build an executable JAR -->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>org.jboss.weld.environment.se.StartMain</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
    </plugins>

and here is how I bootstrap Weld:

public  static void main(String[] args) {
    //Start CDI container
    WeldContainer weldContainer = WeldFactory.INSTANCE.getWeldContainer();

    try {
        MainThread mainExecutor = weldContainer.instance().select(MainThread.class).get(); 
        mainExecutor.run();
    } catch (Exception e) {
        LOG.error("Fatal error",e);
    }finally {
        //Shutdwon CDI container
        weldContainer.shutdown();   
    }

}

//  @Inject
//  MainThread mainExecutor;
//  
//    public void main(@Observes ContainerInitialized event){
//      try {
//          //MainThread mainExecutor = weldContainer.instance().select(MainThread.class).get(); 
//          mainExecutor.run();
//      } catch (Exception e) {
//          LOG.error("Fatal error",e);
//      }finally {
//          //Shutdwon CDI container
//          //weldContainer.shutdown(); 
//      }
//
//    }

(I've tried both commented and uncommented code but still getting the same error). Any help will be great, I've really tried all things.

Géraud Willing B-S
  • 273
  • 1
  • 2
  • 17
  • This looks like dependency issue, which eclipse may be supplying, but is missing when you package the app. Check if you have some dependencies declared as provided or optional etc – maress Jan 12 '17 at 18:23
  • Thanks for your reply, I think my main issue is : 'weld.environment.se.StartMain 2017-01-12 21:34:43 INFO Version:155 - WELD-000900: 2.4.1 (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:722) at org.jboss.weld.environment.se.Weld.initialize(Weld.java:592) at org.jboss.weld.environment.se.StartMain.go(StartMain.java:44) at org.jboss.weld.environment.se.StartMain.main(StartMain.java:53)' – Géraud Willing B-S Jan 12 '17 at 20:39
  • I've also check my dependencies and all seems correct ' org.jboss.weld.se weld-se-core 2.4.1.Final org.jboss.weld.se weld-se 2.3.3.Final ' – Géraud Willing B-S Jan 12 '17 at 20:43
  • 1
    Two things coming to mind, not sure which is the cause. Firstly, make sure your JAR contains `beans.xml` (that could be the "no beans archive found" exception). Secondly, why do you have two Weld dependencies and both and different versions?! Furthermore, you don't need both, you should use only [`org.jboss.weld.se:weld-se`](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.jboss.weld.se%22%20AND%20a%3A%22weld-se%22) which is a shaded version of `weld-se-core`. – Siliarus Jan 13 '17 at 07:40
  • 1
    You were rigth, the probleme came from my bean.xml file. My jar didn't contains my bean.xml file so I added one in the jar with ` bean-discovery-mode="annotated" ` and I'm now able to run my jar successfully. Here came another problem: My program don't run at all, I see in console outputs that weld successfully start and shutdown just after without executing my mainThread.run(). Here is console output ` INFO WELD STATIC_INSTANCE initialized INFO Bootstrap:245 - WELD-ENV-002001: Weld SE container STATIC_INSTANCE shut down Weld SE container STATIC_INSTANCE shut down by shutdown hook – Géraud Willing B-S Jan 13 '17 at 12:08
  • @GéraudWillingB-S that's another problem, IMHO you should update your question so it contains the new details. Because keeping it in the comments is not very readable. – G. Demecki Jan 25 '17 at 08:23

1 Answers1

1

User Siliarus has helped you, kudos for him.

Now you have encountered another problem. App shutdowns immediately.
It's not strange - that's happens because you don't make use of the ContainerInitialized event. If you are using the built-in org.jboss.weld.environment.se.StartMain class, then you should have a simple bean which observes the ContainerInitialized event.

Alternatively, you can make use of the Main class, which content you've pasted above. To do this, instruct a maven-jar-plugin to use your shiny class with a main method with something like this:

<mainClass>com.your.own.class.with.main.method</mainClass>

In case of another problems, I encourage you to take a look at the working examples of Weld's usage: https://github.com/weld/core/tree/master/examples.

Hope it helps.

G. Demecki
  • 10,145
  • 3
  • 58
  • 58