glassfish
  1. glassfish
  2. GLASSFISH-18720

appclient fails when space is included in Main-Class of MANIFEST.MF

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 4.0_b34
    • Fix Version/s: None
    • Component/s: standalone_client
    • Labels:
      None
    • Environment:

      Windows 7

      Description

      Problem when using appclient:

      If there are space(s) at the Main-Class entry in MANIFEST.MF of warehouse-client.jar, appclient fails with ClassNotFoundException.

      When the MANIFEST.MF is like this, it works.

      Working
       
      Manifest-Version: 1.0
      Created-By: 1.6.0_13 (Sun Microsystems Inc.)
      Main-Class: warehouse.client.WarehouseClient
      Class-Path: warehouse-ejb.jar
      

      When below MANIFEST.MF is used, appclient fails with ClassNotFoundException. See the space between 'Main-Class:' and 'warehouse'. You could try inserting two space between : and w, or inserting at least one space at the end of the line. In both cases, space character(s) are included in the class name and this fails with ClassNotFound.

      Not working
       
      Manifest-Version: 1.0
      Created-By: 1.6.0_13 (Sun Microsystems Inc.)
      Main-Class:  warehouse.client.WarehouseClient
      Class-Path: warehouse-ejb.jar
      

      Steps to reproduce the problem:

      Sample programs are attached. Please extract the zip files to use them. The only difference between working.zip and notworking.zip are space for Main-Class in MANIFEST.MF
      1.Extract notworking.zip
      2.asadmin deploy --force=true --name warehouse .\warehouse.ear
      3.asadmin get-client-stubs --appname warehouse .\client
      4.appclient -client .\client\warehouseClient.jar
      appclient fails with java.lang.ClassNotFoundException.

      The problem is it is very difficult for a user to find the cause because the space is not a visible character.

      I also tried the same for Class-Path: This worked even when there are space characters.

        Activity

        Hide
        Tim Quinn added a comment -

        The specification of the JAR file format (documented here http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html) explains that each entry in the manifest consists of the name followed immediately by a colon followed immediate by a single space followed by the value.

        This means that if you define the Main-Class entry like this:

        Main-Class:<space><space>x.y

        then you have told Java that the main class name is <space>x.y.

        Naturally, this is not really the name of the main class, so the app client container will not be able to find that class.

        You can run this experiment if you want to:

        java -jar warehouse-client.jar

        Java will fail like this:

        Exception in thread "main" java.lang.NoClassDefFoundError: warehouse/client/WarehouseClient
        Caused by: java.lang.ClassNotFoundException: warehouse.client.WarehouseClient
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

        Note the extra space in the error message. Java is doing exactly what you told it to do. It is trying to find the class <space>warehouse.client.WarehouseClient.

        The ACC is also doing what you told it to do, trying to find the class <space>warehouse.client.WarehouseClient.

        Fix the incorrectly-constructed Main-Class entry in the client JAR and, as you noted, you will solve this problem.

        Show
        Tim Quinn added a comment - The specification of the JAR file format (documented here http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html ) explains that each entry in the manifest consists of the name followed immediately by a colon followed immediate by a single space followed by the value. This means that if you define the Main-Class entry like this: Main-Class:<space><space>x.y then you have told Java that the main class name is <space>x.y. Naturally, this is not really the name of the main class, so the app client container will not be able to find that class. You can run this experiment if you want to: java -jar warehouse-client.jar Java will fail like this: Exception in thread "main" java.lang.NoClassDefFoundError: warehouse/client/WarehouseClient Caused by: java.lang.ClassNotFoundException: warehouse.client.WarehouseClient at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) Note the extra space in the error message. Java is doing exactly what you told it to do. It is trying to find the class <space>warehouse.client.WarehouseClient. The ACC is also doing what you told it to do, trying to find the class <space>warehouse.client.WarehouseClient. Fix the incorrectly-constructed Main-Class entry in the client JAR and, as you noted, you will solve this problem.

          People

          • Assignee:
            Tim Quinn
            Reporter:
            tak09
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: