0 Replies Latest reply on Nov 1, 2013 7:48 AM by pramanish

    Getting ClassNotFoundException while creating FileObject of the Package

    pramanish

      Hi All,

       

      I have written Arquillian test, this is actually one sort of setup program to set up my application database.

       

      I am using reflection APIs to get method names, data type, annotations and so on for which I am reading set of classes from the given package to populate an array of Class object.

      But while getting path of package directory, I found that its not referring path of the deployed test.war but my arquillian test folder path and there that package doesn't exist so its complaining that directory doesn't exist. I am wondering how can I get path of package residing under jboss content folder (deployment folder for arquillian). Help will be greatly appreciated.

       

      for (String packageName : packageNames) {

                  try {

                      ClassLoader cld = Thread.currentThread().getContextClassLoader();

                      if (cld == null) {

                          throw new ClassNotFoundException("Can't get class loader.");

                      }

                      String path = packageName.replace('.', '/');

                      URL resource = cld.getResource(path);

                      if (resource == null) {

                          throw new ClassNotFoundException("No resource for " + path);

                      }

                      directory = new File(resource.getFile());

                  } catch (NullPointerException x) {

                      throw new ClassNotFoundException(packageName + " (" + directory + ") does not appear to be a valid package");

                  }

                  System.out.println("**** Directory is --> "+directory.getAbsolutePath());

                  if (directory.exists()) {

                               s.o.p("Directory exist");

                     }else{

      System.out.println("Directory doesn't exist");

      }

       

      Thanks,

      Manish