Chapter 6 workaround

  4 posts   Feedicon  
Replies: 3 - Last Post: December 21, 2010 19:06
by: Jan_vdV
showing 1 - 4 of 4
 
Posted: August 29, 2010 21:06 by bbaron

I was having trouble deploying the EJB in chapter 6 because the pom puts a Main-Class declaration in the Manifest. This causes glassfish to reject the jar, but no mention of this is made in the book, that I found.

The workaround is stated in this comment embedded in the Chapter 6 pom.xml:

To avoid multiple modules with Maven, here is what you need to manually do (it's not nice, but it works)

  1. Comment the following section (maven-jar-plugin), package the jar, and deploy to GlassFish
  2. Uncomment the following section, package the jar and run the Main class with app client

There is a simpler way to do this without resorting to commenting/uncommenting. Wrap the maven jar plugin with the main class declaration in a profile. The profile is inactive by default and activated with -Pclient added to the command line.

<profiles>
    <profile>
        <id>client</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${plugin-jar-version}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>org.beginningee6.book.chapter06.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
 
Posted: September 08, 2010 11:17 by m4r35n357
Hi all, sorry to reply to this post but I couldn't find any way to start a new topic - anyway, it is related to chapter 6 so . . .

I have been following the testing examples in the book and got the embedded derby stuff going after MUCH pain with dependencies. However, I have not been able to get the EJB tests to run, as embedded-glassfish is a bit of an exception machine IMO!

As a last resort, I tried the version from the SVN and got EXACTLY the same exception, so at least I don't have to explain my setup!

So, without further ado, here is the output from maven - hope someone can help:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Chapter 06 - EJB
[INFO] task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: /home/ian/Documents/projects/Jee6Book/trunk/chapter06/target (included: [**], excluded: [])
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 5 source files to /home/ian/Documents/projects/Jee6Book/trunk/chapter06/target/classes
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 1 source file to /home/ian/Documents/projects/Jee6Book/trunk/chapter06/target/test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: /home/ian/Documents/projects/Jee6Book/trunk/chapter06/target/surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.beginningee6.book.chapter06.BookEJBTest
08-Sep-2010 12:14:53 org.glassfish.ejb.embedded.EJBContainerProviderImpl getValidFile
SEVERE: ejb.embedded.location_not_exists
08-Sep-2010 12:14:55 com.sun.enterprise.v3.server.AppServerStartup run
INFO: GlassFish Server Open Source Edition 3.0.1 (java_re-private) startup time : Embedded(721ms) startup services(535ms) total(1256ms)
08-Sep-2010 12:14:55 com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
08-Sep-2010 12:14:55 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
INFO: JMXStartupService: JMXConnector system is disabled, skipping.
08-Sep-2010 12:14:55 AppServerStartup run
INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
08-Sep-2010 12:15:24 com.sun.enterprise.security.SecurityLifecycle <init>
INFO: security.secmgroff
08-Sep-2010 12:15:24 com.sun.enterprise.security.SecurityLifecycle onInitialization
INFO: Security startup service called
08-Sep-2010 12:15:24 com.sun.enterprise.security.PolicyLoader loadPolicy
INFO: policy.loading
08-Sep-2010 12:15:25 com.sun.enterprise.security.auth.realm.Realm doInstantiate
INFO: Realm admin-realm of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
08-Sep-2010 12:15:25 com.sun.enterprise.security.auth.realm.Realm doInstantiate
INFO: Realm file of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
08-Sep-2010 12:15:25 com.sun.enterprise.security.auth.realm.Realm doInstantiate
INFO: Realm certificate of classtype com.sun.enterprise.security.auth.realm.certificate.CertificateRealm successfully created.
08-Sep-2010 12:15:25 com.sun.enterprise.security.SecurityLifecycle onInitialization
INFO: Security service(s) started successfully....
08-Sep-2010 12:15:25 org.hibernate.validator.util.Version <clinit>
INFO: Hibernate Validator null
08-Sep-2010 12:15:25 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
08-Sep-2010 12:15:25 org.glassfish.admin.monitor.MonitoringBootstrap handleLevelChange
INFO: enableStatsMonitoring
08-Sep-2010 12:15:25 org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
INFO: [EJBContainerProviderImpl] Cleaning up on failure ...
java.lang.AssertionError
at org.jvnet.hk2.config.Dom.<init>(Dom.java:153)
at org.jvnet.hk2.config.ConfigBean.<init>(ConfigBean.java:81)
at org.glassfish.config.support.GlassFishConfigBean.<init>(GlassFishConfigBean.java:81)
at org.glassfish.kernel.config.DefaultConfigParser$1.make(DefaultConfigParser.java:83)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:186)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:161)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:92)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:109)
at org.glassfish.kernel.config.DefaultConfigParser$2.run(DefaultConfigParser.java:93)
at org.glassfish.kernel.config.DefaultConfigParser.parseContainerConfig(DefaultConfigParser.java:87)
at org.glassfish.scripting.jruby.JRubyContainer.postConstruct(JRubyContainer.java:97)
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
at org.glassfish.internal.data.EngineInfo.getContainer(EngineInfo.java:78)
at org.glassfish.internal.data.EngineInfo.stop(EngineInfo.java:203)
at com.sun.enterprise.v3.server.ApplicationLoaderService.preDestroy(ApplicationLoaderService.java:427)
at com.sun.hk2.component.AbstractWombInhabitantImpl.dispose(AbstractWombInhabitantImpl.java:74)
at com.sun.hk2.component.SingletonInhabitant.release(SingletonInhabitant.java:66)
at com.sun.hk2.component.LazyInhabitant.release(LazyInhabitant.java:112)
at com.sun.enterprise.v3.server.AppServerStartup.stop(AppServerStartup.java:393)
at org.glassfish.api.embedded.Server.stop(Server.java:603)
at org.glassfish.ejb.embedded.EJBContainerImpl.stop(EJBContainerImpl.java:284)
at org.glassfish.ejb.embedded.EJBContainerImpl.forceClose(EJBContainerImpl.java:179)
at org.glassfish.ejb.embedded.EJBContainerImpl.close(EJBContainerImpl.java:165)
at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:128)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:78)
at org.beginningee6.book.chapter06.BookEJBTest.initContainer(BookEJBTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
08-Sep-2010 12:15:25 org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
08-Sep-2010 12:15:25 com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished
08-Sep-2010 12:15:25 AppServerStartup run
INFO: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
08-Sep-2010 12:15:25 org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
SEVERE: ejb.embedded.exception_instantiating
java.lang.AssertionError
at org.jvnet.hk2.config.Dom.<init>(Dom.java:153)
at org.jvnet.hk2.config.ConfigBean.<init>(ConfigBean.java:81)
at org.glassfish.config.support.GlassFishConfigBean.<init>(GlassFishConfigBean.java:81)
at org.glassfish.kernel.config.DefaultConfigParser$1.make(DefaultConfigParser.java:83)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:186)
at org.jvnet.hk2.config.ConfigParser.handleElement(ConfigParser.java:161)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:92)
at org.jvnet.hk2.config.ConfigParser.parse(ConfigParser.java:109)
at org.glassfish.kernel.config.DefaultConfigParser$2.run(DefaultConfigParser.java:93)
at org.glassfish.kernel.config.DefaultConfigParser.parseContainerConfig(DefaultConfigParser.java:87)
at org.glassfish.scripting.jruby.JRubyContainer.postConstruct(JRubyContainer.java:97)
at com.sun.hk2.component.AbstractWombImpl.inject(AbstractWombImpl.java:174)
at com.sun.hk2.component.ConstructorWomb$1.run(ConstructorWomb.java:87)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.hk2.component.ConstructorWomb.initialize(ConstructorWomb.java:84)
at com.sun.hk2.component.AbstractWombImpl.get(AbstractWombImpl.java:77)
at com.sun.hk2.component.SingletonInhabitant.get(SingletonInhabitant.java:58)
at com.sun.hk2.component.LazyInhabitant.get(LazyInhabitant.java:107)
at com.sun.hk2.component.AbstractInhabitantImpl.get(AbstractInhabitantImpl.java:60)
at org.glassfish.internal.data.EngineInfo.getContainer(EngineInfo.java:78)
at com.sun.enterprise.v3.server.ApplicationLifecycle.startContainers(ApplicationLifecycle.java:716)
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:461)
at org.glassfish.javaee.full.deployment.EarDeployer.prepareBundle(EarDeployer.java:264)
at org.glassfish.javaee.full.deployment.EarDeployer.access$200(EarDeployer.java:79)
at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:131)
at org.glassfish.javaee.full.deployment.EarDeployer$1.doBundle(EarDeployer.java:129)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnBundles(EarDeployer.java:197)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllTypedBundles(EarDeployer.java:206)
at org.glassfish.javaee.full.deployment.EarDeployer.doOnAllBundles(EarDeployer.java:232)
at org.glassfish.javaee.full.deployment.EarDeployer.prepare(EarDeployer.java:129)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:644)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:296)
at org.glassfish.kernel.embedded.EmbeddedDeployerImpl.deploy(EmbeddedDeployerImpl.java:214)
at org.glassfish.kernel.embedded.EmbeddedDeployerImpl.deploy(EmbeddedDeployerImpl.java:144)
at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:128)
at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:120)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:78)
at org.beginningee6.book.chapter06.BookEJBTest.initContainer(BookEJBTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 31.705 sec <<< FAILURE!

Results :

Tests in error:
org.beginningee6.book.chapter06.BookEJBTest

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.

Please refer to /home/ian/Documents/projects/Jee6Book/trunk/chapter06/target/surefire-reports for the individual test results.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39 seconds
[INFO] Finished at: Wed Sep 08 12:15:25 BST 2010
[INFO] Final Memory: 25M/129M
[INFO] ------------------------------------------------------------------------
 
Posted: December 21, 2010 19:06 by Jan_vdV
I have been struggling with exactly the same error message. Eventually this code change solved the problem for me:
replace
        ec = EJBContainer.createEJBContainer();

with
    	Map<String, Object> properties = new HashMap<String, Object>();  
    	properties.put(EJBContainer.MODULES, new File("target/classes"));
        ec = EJBContainer.createEJBContainer(properties);

I suppose it tells the embedded container where to look for ejb modules.
 
Posted: September 26, 2010 15:27 by bbaron

The embedded glassfish seems to be broken. EJB 3.1 doesn't quite live up to the claim that they are POJO if you still need a stripped down container to run simple unit tests.

Replies: 3 - Last Post: December 21, 2010 19:06
by: Jan_vdV
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close