glassfish
  1. glassfish
  2. GLASSFISH-7561

Check for existence of libraries files when deploying with --libraries

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: v2.1
    • Fix Version/s: 4.1
    • Component/s: deployment
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      When deploying with --libraries, the deployment process does not check if the specified files actually
      exist on disk.

      For users (like me) not reading the documentation which states that "relative paths are relative to
      instance-root/lib/applibs", the deployment is said to have completed successfully but the libraries cannot
      be located at runtime (which could lead people to think this is some sort of class-loader issue).

      I would suggest that the deployment should :

      • echo the absolute name of the library
      • fail when the library file(s) don't exist on disk at deploy-time

        Activity

        Hide
        Jeremy_Lv added a comment -

        Ok, Here's changes as follows:

        Index: main/java/org/glassfish/deployment/common/DeploymentContextImpl.java
        ===================================================================
        --- main/java/org/glassfish/deployment/common/DeploymentContextImpl.java	(revision 61484)
        +++ main/java/org/glassfish/deployment/common/DeploymentContextImpl.java	(working copy)
        @@ -66,6 +66,8 @@
         import java.net.URLClassLoader;
         
         import org.glassfish.hk2.api.PreDestroy;
        +
        +import com.sun.enterprise.util.LocalStringManagerImpl;
         import com.sun.enterprise.util.io.FileUtils;
         import org.glassfish.hk2.classmodel.reflect.Parser;
         import org.glassfish.hk2.classmodel.reflect.Types;
        @@ -89,6 +91,8 @@
             public static final Logger deplLogger =
                 Logger.getLogger(DEPLOYMENT_LOGGER, SHARED_LOGMESSAGE_RESOURCE);
         
        +    final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(DeploymentContextImpl.class);
        +
             private static final String INTERNAL_DIR_NAME = "__internal";
             private static final String APP_TENANTS_SUBDIR_NAME = "__app-tenants";
         
        @@ -444,7 +448,14 @@
                         ASClassLoaderUtil.getDeployParamLibrariesAsURLs(
                             parameters.libraries(), env);
                     for (URL url : urls) {
        -                libURIs.add(url.toURI());
        +                File file = new File(url.getFile());
        +                deplLogger.log(Level.FINE, "Specified library jar: "+file.getAbsolutePath());
        +                if (file.exists()){
        +                    libURIs.add(url.toURI());
        +                } else {
        +                    throw new IllegalArgumentException(localStrings.getLocalString("enterprise.deployment.nonexist.libraries", "Specified library jar {0} does not exist: {1}", file.getName(), file.getAbsolutePath()));
        +                }
        +
                     }
                 }
         
        Index: main/resources/org/glassfish/deployment/common/LocalStrings.properties
        ===================================================================
        --- main/resources/org/glassfish/deployment/common/LocalStrings.properties	(revision 61484)
        +++ main/resources/org/glassfish/deployment/common/LocalStrings.properties	(working copy)
        @@ -248,3 +248,7 @@
         enterprise.deployment.backend.get_descriptor_failed=Failed to load deployment descriptor for application ${0}.
         illegal_char_in_name=Illegal character [{0}] in the name [{1}].
         enterprise.deployment.remoteDirPathUnusable=The directory deployment path {0} is not a directory or is inaccessible
        +
        +
        +#DeploymentContextImpl.java
        +enterprise.deployment.nonexist.libraries=Specified library jar {0} does not exist: {1}
        
        
        Show
        Jeremy_Lv added a comment - Ok, Here's changes as follows: Index: main/java/org/glassfish/deployment/common/DeploymentContextImpl.java =================================================================== --- main/java/org/glassfish/deployment/common/DeploymentContextImpl.java (revision 61484) +++ main/java/org/glassfish/deployment/common/DeploymentContextImpl.java (working copy) @@ -66,6 +66,8 @@ import java.net.URLClassLoader; import org.glassfish.hk2.api.PreDestroy; + + import com.sun.enterprise.util.LocalStringManagerImpl; import com.sun.enterprise.util.io.FileUtils; import org.glassfish.hk2.classmodel.reflect.Parser; import org.glassfish.hk2.classmodel.reflect.Types; @@ -89,6 +91,8 @@ public static final Logger deplLogger = Logger.getLogger(DEPLOYMENT_LOGGER, SHARED_LOGMESSAGE_RESOURCE); + final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(DeploymentContextImpl.class); + private static final String INTERNAL_DIR_NAME = "__internal" ; private static final String APP_TENANTS_SUBDIR_NAME = "__app-tenants" ; @@ -444,7 +448,14 @@ ASClassLoaderUtil.getDeployParamLibrariesAsURLs( parameters.libraries(), env); for (URL url : urls) { - libURIs.add(url.toURI()); + File file = new File(url.getFile()); + deplLogger.log(Level.FINE, "Specified library jar: " +file.getAbsolutePath()); + if (file.exists()){ + libURIs.add(url.toURI()); + } else { + throw new IllegalArgumentException(localStrings.getLocalString( "enterprise.deployment.nonexist.libraries" , "Specified library jar {0} does not exist: {1}" , file.getName(), file.getAbsolutePath())); + } + } } Index: main/resources/org/glassfish/deployment/common/LocalStrings.properties =================================================================== --- main/resources/org/glassfish/deployment/common/LocalStrings.properties (revision 61484) +++ main/resources/org/glassfish/deployment/common/LocalStrings.properties (working copy) @@ -248,3 +248,7 @@ enterprise.deployment.backend.get_descriptor_failed=Failed to load deployment descriptor for application ${0}. illegal_char_in_name=Illegal character [{0}] in the name [{1}]. enterprise.deployment.remoteDirPathUnusable=The directory deployment path {0} is not a directory or is inaccessible + + +#DeploymentContextImpl.java +enterprise.deployment.nonexist.libraries=Specified library jar {0} does not exist: {1}
        Hide
        Hong Zhang added a comment -

        The updated changes look good, please hold on to this set of the change and we can check in once the branch is created. Thanks.

        Show
        Hong Zhang added a comment - The updated changes look good, please hold on to this set of the change and we can check in once the branch is created. Thanks.
        Hide
        Jeremy_Lv added a comment -

        Sending deployment/common/src/main/java/org/glassfish/deployment/common/DeployContextImpl.java

        Sending deployment/common/src/main/resource/org/glassfish/deployment/common/LocalStrings.properties

        Transmitting file data .
        Committed revision 61834.

        Show
        Jeremy_Lv added a comment - Sending deployment/common/src/main/java/org/glassfish/deployment/common/DeployContextImpl.java Sending deployment/common/src/main/resource/org/glassfish/deployment/common/LocalStrings.properties Transmitting file data . Committed revision 61834.
        Hide
        Jeremy_Lv added a comment -

        Revert the changes as the changes cause the ejb dev tests failed.

        Show
        Jeremy_Lv added a comment - Revert the changes as the changes cause the ejb dev tests failed.
        Hide
        Jeremy_Lv added a comment -

        Sending deployment/common/src/main/java/org/glassfish/deployment/common/DeployContextImpl.java

        Sending deployment/common/src/main/resource/org/glassfish/deployment/common/LocalStrings.properties

        Transmitting file data .
        Committed revision 62003.

        Show
        Jeremy_Lv added a comment - Sending deployment/common/src/main/java/org/glassfish/deployment/common/DeployContextImpl.java Sending deployment/common/src/main/resource/org/glassfish/deployment/common/LocalStrings.properties Transmitting file data . Committed revision 62003.

          People

          • Assignee:
            Hong Zhang
            Reporter:
            Alexis MP
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: