4 Replies Latest reply on Aug 23, 2002 7:04 AM by mipe

    Where to place constants?

    pavel_c

      Hello,

      Where is the appropriate place to put my constants, related to a CMP Entity EJB? I want to use symbolic names for the values for certain integer fields. I could put those in my remote interface as public static final fields, but my remote interface is autogenerated using XDoclet. It has got the option to make the generated remote interface extend another interface that I specify, but the whole point of using XDoclet is that I only maintain a single source file per bean.

      Any suggestions?

      Pavel

        • 1. Re: Where to place constants?
          hezekiel

          in ejb-jar.xml: <env-entry> (environment entry) look for ejb-jar.xml examples or documentation from the net.

          • 2. Re: Where to place constants?
            pavel_c

            This is inefficient, because you have to look them up from JNDI. Besides, these are internal application constants, not deployment-specific parameters, for which the env-entry mechanism is designed.

            • 3. Re: Where to place constants?
              ppetit

              I use to put them in an interface that I implement in the class that needs the constants...

              It's just the way I do this, I don't arg it is "THE WAY"!

              You can also put them in a public class with a private constructor to avoid any instanciation and use static final variables.

              Philippe

              • 4. Re: Where to place constants?

                I suggest you to download the petstore example for j2ee from java.sun.com if you hadn't done it.
                They placed JNDI and other (database related) constants into a util package at the same level to the ejb package.
                For example if you have

                com.company.product.comp.ejb package, your constants can be put into the
                com.company.product.comp.util package where you place files like JNDINames.java or DatabaseNames.java