5 Replies Latest reply on Nov 29, 2005 3:55 AM by Peter Salomonsen

    using jar file ref in persistence.xml

    Peter Salomonsen Newbie

      I've installed EJB3.0RC1 and the release notes states that now all persistence.xml features are implemented. So I went on trying to use the jar file referencing.

      Unfortunately I found that during deployment the only place being searched for this jar file was in JBOSS_HOME/bin. I tried with absolute paths and relative - but it kept hangin on to the bin folder - probably the working folder for jboss launcher.

      My jar is bundled with my ear - where should it really be to get the jar reference workin? I think the bin folder is not a proper place....

      Peter

        • 1. Re: using jar file ref in persistence.xml
          Jakub Herkel Newbie

          I have a same problem with <jar-file> in persistence.xml. I also tried to add this jar file to lib directory but I got same error output.

          jakub

          • 2. Re: using jar file ref in persistence.xml
            Emmanuel Bernard Master

            open a JIRA issue if none has been so far.

            • 4. Re: using jar file ref in persistence.xml
              Venkata Hari Newbie

              Hi, any update on this issue? I am still getting the error with 4.0.3 SP1.
              I tried giving the following line in persistence.xml
              <jar-file>DomainClasses.jar</jar-file>
              but it didn't work.

              Do you guys have any idea?

              • 5. Re: using jar file ref in persistence.xml
                Peter Salomonsen Newbie

                Doesn't seem like anything has happened here. I've ended up referencing each indiviudal entity-class, though it's a little more work.

                However if you have lot's of entity beans, and you need an efficient way to find them and create the xml-references for persitence.xml - try this little piece of code:

                import java.io.File;
                import java.lang.annotation.Annotation;
                
                /**
                 * Tool to scan for all entity beans in a package and generate persistence.xml class entries
                 * @author peter
                 *
                 */
                public class GenPersistArchives {
                 String basePath;
                 String persistClasses = "";
                
                 public GenPersistArchives(String basePath)
                 {
                 this.basePath = basePath;
                 File dir = new File(ClassLoader.getSystemResource(basePath).getPath());
                 scan(dir);
                 System.out.println(persistClasses);
                 }
                
                 static final String translateToJavaPath(String uri)
                 {
                 // Translate into classname, and also handle subclasses
                 String className = uri.replace(".class","");
                 if(className.indexOf("$1")>0)
                 className = className.substring(0,className.indexOf("$1"));
                 className = className.replace("/",".");
                 return className;
                 }
                 private void scan(File dir)
                 {
                 for(File file : dir.listFiles())
                 {
                 if(file.isDirectory())
                 scan(file);
                 else
                 {
                 String relativePath = file.getPath();
                 relativePath = relativePath.substring(relativePath.indexOf(basePath));
                 String className = translateToJavaPath(relativePath);
                 try
                 {
                 Class cls = Class.forName(className);
                 for(Annotation ann : cls.getAnnotations())
                 {
                 if(ann.annotationType().getName().equals(javax.persistence.Entity.class.getName()))
                 {
                 persistClasses+="<class>"+className+"</class>\n";
                 }
                 }
                
                 } catch(Exception e)
                 {
                 e.printStackTrace();
                 }
                
                 }
                 }
                 }
                 /**
                 * @param args
                 */
                 public static void main(String[] args) {
                 // Package to scan
                 new GenPersistArchives("com/lightminds/cms/ejb3");
                
                 }
                }
                


                Good luck,

                Peter