Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:34:47+00:00 2026-05-16T04:34:47+00:00

I’ve been trying to set my application up so that I can unit test

  • 0

I’ve been trying to set my application up so that I can unit test it’s EJBs all day but I can’t seem to get past what seems like a really simple problem.

I have a standard Maven web application set up in NetBeans 6.9. I’ve automatically generated a unit test for one of the EJBs but whenever I go to run it I get the error message:

Testcase: initializationError(com.example.ExampleTest): Caused an ERROR
Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/embeddable/EJBContainer
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)

I’ve researched this one to death and I’m pretty sure the problem is that my pom currently points to a jar which contains only the API

<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

Not and implementation that can be used for running the tests. I’m pretty sure the test is failing in the method marked with @BeforeClass when it tries to execute

container = EJBContainer.createEJBContainer();

The standard recommended solution is to add the glassfish-embedded-all artifact as the first project dependency with test scope

<dependency>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>3.0.1</version>
            <scope>test</scope>
        </dependency>

I can find a Maven package for this artifact here: http://download.java.net/maven/glassfish/ but Nexus doesn’t recognize this directory or any of the subdirectories as Maven 2 repositories. I suppose I could download the jar and manually install it into Nexus but that seems to defeat the who point of installing Nexus.

So, is there a Maven repository that Nexus will be able to index to give me the glassfish-embedded-all artifact? A couple of posts I read mentioned that the correct artifact to now be using is javax.ejb but I’ve had no more luck finding this.

As you’ve probably guessed I’m completely new to unit testing and fairly new to JEE6 in general; is this even the correct way to go about unit testing EJBs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:34:48+00:00Added an answer on May 16, 2026 at 4:34 am

    (…) The standard recommended solution is to add the glassfish-embedded-all artifact as the first project dependency with test scope

    Indeed, you need an implementation like glassfish-embedded-all or glassfish-embedded-web if you’re only using the web profile, which seems to be your case (I didn’t know that the web profile was providing EJBContainer by the way).

    And to be precise, this artifact doesn’t have to be the “first” dependency but it must be declared before the javaee-api artifact.

    So, is there a Maven repository that Nexus will be able to index to give me the glassfish-embedded-all artifact?

    I couldn’t reproduce the issue with http://download.java.net/maven/glassfish/ but it appears that JBoss Nexus repository does have it (probably because they use it in Arquillian):

    <repository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Maven Repository Group</name>
      <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
    

    is this even the correct way to go about unit testing EJBs?

    Unit tests are typically done outside-container and in isolation (using a Mocking framework) so I wouldn’t call that unit testing. But for integration/functional testing (in-container), the EJBContainer API is really great and perfectly fine.

    See also

    • TOTD #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
    • Unit Testing EJBs and JPA with Embeddable GlassFish
    • Using the EJBContainer API with or without Maven (but with GlassFish v3)
    • Embedding EJB 3.1 Container Into Your Unit Tests – Boot Time: 5 Seconds
    • Unit Testing EJB 3.1 …When 0.8 Seconds Are Too Long for a unit test example
    • The Arquillian project
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.