1 2 Previous Next 26 Replies Latest reply on Nov 20, 2010 6:35 AM by kabirkhan Go to original post
      • 15. Re: Embedded AS
        brian.stansberry

        A couple other comments:

         

        There's a split package; i.e. org.jboss.modules appears in embedded-modular-bootstrap. Split packages are verbotten, so we can't push this upstream until that's fixed. Hopefully there's no reason ModuleXmlParser can't be made public.

         

        ModularEmbeddedServer.start(String... dependencies) throws an NPE if you pass in null dependencies.

         

        The need to pass in those dependencies indicates StandaloneServer has a problem that needs fixing. Embedded users should be able to get a simple notification when the server is "started", which I'd define as the point where we log the "JBoss AS %s \"%s\" started in %dms" message.

        • 16. Re: Embedded AS
          kabirkhan

          I don't think you can change the classpath of an already running java program, I tried this

           

          projectA has class A

          projectB has class B and Main

          None of the projects import each other

           

          public class Main {

              public static void main(String[] args) throws Exception {

                  System.out.println(Main.class.getResource("/"));

                  System.setProperty("java.class.path", "/Users/kabir/sourcecontrol/jboss-as7/eclipse/projectA/bin/");

           

                  System.out.println(Class.forName("B"));

           

                  System.out.println("Test");

           

                  Class.forName("A");

              }

          }

           

          This shows this output:

           

          file:/Users/kabir/sourcecontrol/jboss-as7/eclipse/projectB/bin/

          class B

          Test

          Exception in thread "main" java.lang.ClassNotFoundException: A

          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:307)

          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

          at java.lang.Class.forName0(Native Method)

          at java.lang.Class.forName(Class.java:169)

          at Main.main(Main.java:37)

           

          So the write to java.class.path has no effect, the system classloader probably only reads that once on startup.

           

          If we want to only have one test project for this and control the app classpath I see the following options:

          1) Have the test runner start another process with the minimal classpath and modules, I guess this would be something similar to what ant/maven does when running forked tests

          2) jboss-modules makes it possible to configure the default ModuleLoader so we can do something more clever there such as specifying which packages should never be loaded from the system classpath even if they exit in both system and modules.

           

          I prefer 2) which is needed for the flat embedded case anyway, but daren't start changing that on a whim :-) I can play with 1) for now and see if that gets me anywhere

          • 17. Re: Embedded AS
            kabirkhan

            There's a split package; i.e. org.jboss.modules appears in embedded-modular-bootstrap. Split packages are verbotten, so we can't push this upstream until that's fixed. Hopefully there's no reason ModuleXmlParser can't be made public.

            ModuleXmlParser either needs to be made public, or it needs to be copied into this (yuck)

            ModularEmbeddedServer.start(String... dependencies) throws an NPE if you pass in null dependencies.

             

            The need to pass in those dependencies indicates StandaloneServer has a problem that needs fixing. Embedded users should be able to get a simple notification when the server is "started", which I'd define as the point where we log the "JBoss AS %s \"%s\" started in %dms" message.

            Yeah some callback for then the server has been started is the way forward

            • 18. Re: Embedded AS
              brian.stansberry

              Kabir Khan wrote:

               

              I don't think you can change the classpath of an already running java program

              No you can't. What that class was doing was an attempt to get the jboss-modules SystemLocalLoader to not load undesired classes. It reads the java.class.path property when determining what jars/directories to load from. That part actually seems to work.

               

              The problem is the static intializer block in java.util.logging.LogManager tries to use ClassLoader.getSystemClassLoader() to load the class. And that classloader's unaffected by my change of the system property.

               

              And that problem would affect your #2 solution as well. The true system classloader is not controlled by jboss-modules, so any time some code uses it, it will see the original classpath.

               

              Do you know how the Arquillian guys are dealing with this problem?

              • 19. Re: Embedded AS
                kabirkhan

                Ah, that makes sense now. I'll take another look at your solution and see if I can find a way around the problem you describe.

                 

                I played with #1 yesterday, and was able to get a test runner to start another test runner in another process and communicate the results back, and am halfway through porting my stuff to work doing that. I'm confident that will work, but it has some other problems like making debugging slightly more tricky to set up.

                • 20. Re: Embedded AS
                  kabirkhan

                  I got past the logmanager problem by excluding org.jboss.logmanager:jboss-logmanager, org.jboss.logmanager:jboss-logmanager-log4j and org.jboss.slf4j:slf4j-jboss-logmanager in the poms. The server still does not boot fully but at least it is a start.

                  • 21. Re: Embedded AS
                    kabirkhan
                    • 22. Re: Embedded AS
                      kabirkhan

                      Kabir Khan wrote:

                      The server still does not boot fully but at least it is a start.

                       

                      I lied. It boots :-)

                      • 23. Re: Embedded AS
                        alesj
                        Do you know how the Arquillian guys are dealing with this problem?

                        They are not, yet. :-)

                        * http://community.jboss.org/thread/159049

                        • 24. Re: Embedded AS
                          kabirkhan

                          I have made the jars exposed on the system classloader configurable, like this

                           

                          @TestSetup(

                           

                          ...

                                  classpathFilter=@ClasspathFilter(

                                          classes = {Blah.class},

                                          maven= {

                                             @MavenFilter(groupId="org.jboss.shrinkwrap", artifactId="shrinkwrap-api"),

                                             @MavenFilter(groupId="org.jboss.shrinkwrap", artifactId="shrinkwrap-impl-base")})

                          )

                          @RunWith(ModularJunitTestRunner.class)

                          public class DemosTestCase  {

                           

                          One issue that occurred to me after doing this is that the the SystemLocalLoader only gets initialized once per jvm, so the first test to set this wins. Maybe this should happen at a higher level for the whole project? Maybe in a /system-classpath.properties or a package annotation for test's root package?


                          • 25. Re: Embedded AS
                            kabirkhan

                            Kabir Khan wrote:

                             

                            There's a split package; i.e. org.jboss.modules appears in embedded-modular-bootstrap. Split packages are verbotten, so we can't push this upstream until that's fixed. Hopefully there's no reason ModuleXmlParser can't be made public.

                            ModuleXmlParser either needs to be made public, or it needs to be copied into this (yuck)

                            For now I have copied it into embedded-modular-bootstrap, and opened https://jira.jboss.org/browse/MODULES-60

                            • 26. Re: Embedded AS
                              kabirkhan

                              One issue that occurred to me after doing this is that the the SystemLocalLoader only gets initialized once per jvm, so the first test to set this wins. Maybe this should happen at a higher level for the whole project? Maybe in a /system-classpath.properties or a package annotation for test's root package?


                              This is now initialized in a package-info in a parent package in the project containing the tests:

                              @ClasspathFilter(maven= {

                                              @MavenFilter(groupId="org.jboss.shrinkwrap", artifactId="shrinkwrap-api"),

                                              @MavenFilter(groupId="org.jboss.shrinkwrap", artifactId="shrinkwrap-impl-base")})

                              package org.jboss.test.as.modular;

                              import org.jboss.as.embedded.modular.bootstrap.ClasspathFilter;

                              import org.jboss.as.embedded.modular.bootstrap.MavenFilter;

                              1 2 Previous Next