1

I am trying to run a particularly simple test case using the latest promoted build of Glassfish 4.0. I have tried placing META-INF/beans.xml in all possible permutations including its own jar in WEB-INF/lib

The best I get is the following errors with a layout+sources that are listed after it:

WARNING: Error while trying to load Bean Class WEB-INF.classes.com.example.cdibug.Test : java.lang.ClassNotFoundException: WEB-INF.classes.com.example.cdibug.Test
WARNING: Error while trying to load Bean Class WEB-INF.classes.com.example.cdibug.Foo : java.lang.ClassNotFoundException: WEB-INF.classes.com.example.cdibug.Foo
WARNING: Error while trying to load Bean Class WEB-INF.classes.com.example.cdibug.App : java.lang.ClassNotFoundException: WEB-INF.classes.com.example.cdibug.App
INFO: Registering the Jersey servlet application, named com.example.cdibug.App, at the servlet mapping /rest/*, with the Application class of the same name.
INFO: Loading application [cdibug] at [/cdibug]
INFO: cdibug was successfully deployed in 106 milliseconds.

Layout:

$ jar tvf cdibug.war 
     0 Tue May 07 23:19:48 HST 2013 META-INF/
    68 Tue May 07 23:19:48 HST 2013 META-INF/MANIFEST.MF
     0 Tue May 07 23:14:20 HST 2013 META-INF/beans.xml
     0 Tue May 07 23:19:32 HST 2013 WEB-INF/
     0 Tue May 07 23:18:58 HST 2013 WEB-INF/classes/
     0 Tue May 07 22:51:54 HST 2013 WEB-INF/classes/com/
     0 Tue May 07 22:51:54 HST 2013 WEB-INF/classes/com/example/
     0 Tue May 07 23:09:34 HST 2013 WEB-INF/classes/com/example/cdibug/
   174 Tue May 07 22:54:28 HST 2013 WEB-INF/classes/com/example/cdibug/Test.java
   171 Tue May 07 22:54:04 HST 2013 WEB-INF/classes/com/example/cdibug/App.java
   309 Tue May 07 22:56:30 HST 2013 WEB-INF/classes/com/example/cdibug/Foo.java
   398 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/Test.class
   304 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/App.class
   634 Tue May 07 23:06:00 HST 2013 WEB-INF/classes/com/example/cdibug/Foo.class
$

Source of beans.xml:

$ cat META-INF/beans.xml # EMPTY 0 bytes

Source of App.java:

$ cat WEB-INF/classes/com/example/cdibug/App.java 
package com.example.cdibug;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class App extends Application {
}

Source of Test.java:

$ cat WEB-INF/classes/com/example/cdibug/Test.java 
package com.example.cdibug;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/test")
public class Test {
  @GET
  public String greet () {
    return "hello";
  }
}

Source of Foo.java:

$ cat WEB-INF/classes/com/example/cdibug/Foo.java 
package com.example.cdibug;

import java.util.logging.Logger;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class Foo {
  public Foo () {
    System.out.println("stdout: Foo()");
    System.err.println("stderr: Foo()");
    Logger.getGlobal().info("global_log: Foo()");
  }
}
necromancer
  • 23,916
  • 22
  • 68
  • 115
  • That looks like a bug in Glassfish, unless the packaging is messed up. – LightGuard May 08 '13 at 14:34
  • Have you tried putting beans.xml in WEB-INF ? – John Ament May 08 '13 at 15:16
  • Yes, I did. beans.xml seems to be ignored if it is put in WEB-INF. There are absolutely no messages / signs-of-life from CDI, and none of the three messages in `public Foo() { /* ... */ }` are visible. I also tried it in a more complicated example where I attempted to `@Inject` an application-scoped bean and the injection attempt threw an error when beans.xml was in WEB-INF – necromancer May 08 '13 at 20:51
  • @LightGuard thanks. the packaging details are in the output of the `jar tvf` command in my post and i am pretty sure it is fine. – necromancer May 08 '13 at 20:53
  • Are you using any Java EE 7 features? If not, try Glassfish 3.1.2. Could be that they haven't finished integration of Weld 2 – LightGuard May 09 '13 at 00:32
  • i do not depend on the feature. i am coding a new project on my own schedule and thought it could benefit from CDI. since Java EE 7 is under 3 months away i want to start on it so that my project has a better architecture than otherwise. i have reported it as a bug and hopefully somebody will look at it. thanks for your suggestion! – necromancer May 09 '13 at 00:50
  • @LightGuard it worked fine in 4.0.0-b87, there probably was a bug in the version integrated into eclipse kepler m6 – necromancer May 09 '13 at 07:12

1 Answers1

0

it was a bug in the version bundled with eclipse kepler m6. it works fine under 4.0.0-b87

necromancer
  • 23,916
  • 22
  • 68
  • 115