Class loading and Compile time constants

Hi,
I am not sure if this is the right place for basic questions. I would appreciate any help.
From my understanding, the compile time constants are folded into the byte code during compilation. ( E.g. static final int MAX = 10; ). When I access a compile time constant from a different class, I can see that the class that holds the constant is not loaded at all. ( using -verbose:class option )
Now, my question is, how does JVM access the class that holds the constant without loading it ?! Without the class being loaded, how can the JVM get a binary representation of the same ? What am I missing here ?
thanks,
Soumya.

class A {
  public static final int X = 10;
class B {
  void foo(int n) {
    switch n {
      case A.X:
        yadda();
}The value of X (10) from class A is "folded" into the bytecode of class B.

Similar Messages

  • 1046: Type was not found or was not a compile-time constant: Event.

    I am more than a little frustrated.  I'm using Flash Professional CS5.5, attempting to publish ActionScript 3.0 for FlashPlayer 10.2
    My code begins with:
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    Then much later I have:
    teamFourCar_mc.addEventListener(Event.ENTER_FRAME, trackPosition);
    function trackPosition (event:Event)
    and I keep getting a compiler error:
    Scene 1, Layer 'actions', Frame 1, Line 434
    1046: Type was not found or was not a compile-time constant: Event.
    I have imported the class "Events".  I have successfully used the same construction in other scripts... in fact, virtually the same construction is included in Code Snippets as Fade In and Fade Out.  Adding ":void" after (event:Event) makes no difference.  I have Googled - to no avail - and spent the better part of a day reading through the on-line help files, but the solution is still eluding me.
    It's probably so simple I'm going to smack myself in the forehead and mutter "Duh!" when I find a solution...
    If you can do anything to hasten that event (no pun intended) I (with the possible exception of my forehead) will be very grateful.
    TIA
    Terry

    Sinious:
    The entire code of the main movie clip is at http://pastebin.com/JYfLUhh1
    A sample of one of the four "problem" movie clips is at http://pastebin.com/gQGDyngx
    There is nothing wrong with the "problem" clip.  The problems are in the main movie clip:
    Scene 1, Layer 'actions', Frame 1, Line 427
    1046: Type was not found or was not a compile-time constant: Event.
    Scene 1, Layer 'actions', Frame 1, Line 612
    1046: Type was not found or was not a compile-time constant: Event.
    Scene 1, Layer 'actions', Frame 1, Line 1819
    1046: Type was not found or was not a compile-time constant: Event.
    There are the only three occurrences of a function with (event:Event).  Two are ENTER_FRAME (427 & 1819) The other is COMPLETE from Loader.info
    Auto format reported a syntax error "near 'if(movingCar.currentFrame == (dieRoll * 24) + movingCarPosition)' " but I can't detect what, if anything, is wrong with it.
    I'm not an experienced developer... in fact, the last programming I did before taking up Flash three months ago was with QuickBasic under DOS 6.2... therefore, please try not to roll your eyes too much when you see how inelegant the code is.
    I have a working version, but it's over 7,000 lines and a memory hog.  I'm trying to make it more elegant and more efficient.  BTW, the three (event:Event) functions are in the working version in more or less the same places, with the same calling code.
    I hope you can figure it out.
    Thank you in advance

  • Error 1046: Type was not found or was not a compile-time constant: Component Event.

    Hi Everyone..
    I am getting an Error 1046: Type was not found or was not a compile-time constant: Component Event.
    The ComponentEvent class has been imported,and also the event handling code is there. I am not sure what else is wrong, hope somebody can advise me. Thanks. The code is below, the point where the error occurs as indicated by the compiler has been highlighted.
    package 
    import flash.display.Sprite;
    import flash.media.Camera;
    import flash.media.Microphone;
    import flash.media.Video;
    import fl.controls.TextArea;
    import fl.controls.Button;
    import fl.controls.TextInput;
    import flash.events.SyncEvent;
    import flash.events.MouseEvent;
    import flash.events.FocusEvent;
    import flash.net.SharedObject;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.events.NetStatusEvent;
    import flash.events.FocusEvent;
    import flash.events.ComponentEvent;
    public class VideoChat extends Sprite
      private var button:Button;
      private var text_so:SharedObject; 
      private var textArea:TextArea;
      private var textInput:TextInput;
      private var chatName:TextInput; 
      private var nc:NetConnection;
      private var nsOut:NetStream;
      private var nsIn:NetStream;
      private var rtmpNow:String;
      private var msg:Boolean; 
      private var cam:Camera;
      private var mic:Microphone;
      private var vid:Video;
      public function VideoChat ()
       //Set up UI
       textArea = new TextArea();
       textArea.setSize(500,280);
       textArea.move(20,54);
       addChild(textArea);
       textInput = new TextInput();
       textInput.setSize(500,24);
       textInput.move(20,340);
       textInput.addEventListener(ComponentEvent.ENTER,checkKey);
       addChild(textInput);
       button = new Button();
       button.width=50;
       button.label="Send";
       button.move(20,370);
       button.addEventListener(MouseEvent.CLICK, sendMsg);
       addChild(button);
       chatName = new TextInput;
       chatName.setSize (100,24);
       chatName.move (80,370);
       chatName.text="<Enter Name>";
       chatName.addEventListener (FocusEvent.FOCUS_IN, cleanName);
       addChild(chatName); 
       //Connect
       rtmpNow="rtmp:/VideoChat ";  
       nc=new NetConnection;
       nc.connect (rtmpNow);
       nc.addEventListener(NetStatusEvent.NET_STATUS,doSO);
       cam = Camera.getCamera();
       mic=Microphone.getMicrophone();
       //Camera Settings
       cam.setKeyFrameInterval(15);
       cam.setMode (240, 180, 15, false);
       cam.setMotionLevel(35,3000);
       cam.setQuality(40000 / 8,0);
       //Microphone Settings
       mic.gain = 85;
       mic.rate=11;
       mic.setSilenceLevel (25,1000);
       mic.setUseEchoSuppression (true);
       //Video Setup
       vid=new Video(cam.width, cam.height);
       addChild (vid);
       vid.x=10, vid.y=20;  
       //Attach local video and camera
       vid.attachCamera(cam);  
      private function doSO(e:NetStatusEvent):void
       good=e.info.code == "NetConnection.Connect.Success";
       if(good)
        //Set up shared object
        text_so=SharedObject.getRemote("test", nc.uri, false);
        text_so.connect (nc);
        text_so.addEventListener(SyncEvent.SYNC, checkSO);
      private function checkSO(e:SyncEvent):void
       for (var chung:uint; change<e.changeList.length; chng++)
        switch(e.chageList[chng].code)
         case "clear":
          break;
         case "success":
          break;
         case "change":
          textArea.appendText (text_so.data.msg + "\n");
          break;
      private function cleanName(e:FocusEvent): void
       chatName.text="";
      private function sendMsg(e:MouseEvent):void
       noName=(chatName.text=="<Enter Name>" || chatName.text=="");
       if (noName)
         textArea.appendText("You must enter your name \n");
       else
        text_so.setProperty("msg", chatName.text +": " + textInput.text);
        textArea.appendText (chatName.text +": "+textInput.text +"\n");
        textInput.text="";
      private function checkKey (e:ComponentEvent):void
       noName=(chatName.text=="<Enter Name>" || chatName.text=="");
       if (noName)
         textArea.appendText("You must enter your name \n");
       else
        text_so.setProperty("msg", chatName.text +": " + textInput.text);
        textArea.appendText (chatName.text +": "+textInput.text +"\n");
        textInput.text="";
      //Create NetStream instances
      private function checkConnect  (e:NetStatusEvent):void
       msg=e.info.code == "NetConnection.Connect.Success";
       if(msg)
        nsOut=new NetStream(nc);
        nsIn=new NetStream(nc);
        //NetStream
        nsOut.attachAudio(mic);
        nsOut.attachCamera(cam);
        nsOut.publish("camstream");
        nsIn.play("camstream");

    Hi Guys...
    I have found out what is wrong. I was importing the wrong package the correct one should have been:
    import fl.events.ComponentEvent;
    instead of
    import flash.events.ComponentEvent;
    I hope this is helpful for anyone caught in a simillar situation as me...Thanks..

  • Compile time constants

    Hey i have a doubt regd compile time constants
    byte a =10,b=20;
    byte c= a+b; // compile time error coz a+b may exceed byte limit
    int a=10,b=20;
    int d=a+b; // not showing any error . a+b may exceed int limit
    can anyone clear me int his

    public class Test {
        public static void main(String[] args) {
            byte a = 10, b = 20;
            byte c = a+b;  //syntax error: "possible loss of precision"
            final byte d = 10, e = 20;
            byte f = d+e;  //OK
    }It's not about overflow, but implicit casting: in the expression a+b, bytes a and b
    are widened to int and the addition is 32-bit addition -- the result is an int.
    When you attempt to assign an int to a byte, the top three bytes are discarded,
    hence the syntax error "possible loss of precision". You get the same
    error message when assigning a double to a float.
    Why don't I get the syntax error with my d-e-f example? Variables d and e
    are declared final, so the compiler folds in their values. Thus it know 10+20
    is 30 and that the int value 30 fits into one byte.

  • Trouble adding a web url link to an existing file: 1046: Type was not found or was not a compile-time constant:

    Hi There,
    We're trying to add a simple link to an existing Flash file. There looks to be at least 7 separate .as files and a separate swf that loads the main swf which all seems overly complex for what is essentially a page with six buttons on it.
    However, we need to add a URL to some of the text. So we converted the text to a button, added an instance name of <ssbpurchasetickets_btn> then added the following Actionscript into the actions layer on the frame the text/button appears:
    ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);
    function ssbButtonPurchase(event:MouseEvent):void
    navigateToURL(new URLRequest("http://www.url.com/tickets.html"));
    When we publish the file we get the following error which seems to cascade into a whole bunch more errors:
    Description: 1046: Type was not found or was not a compile-time constant: MouseEvent.
    Source: function ssbButtonPurchase(event:MouseEvent):void
    We added "ssb" onto the button and functions to ensure there were no conflicts but the same thing occurred. If we copy the button into a new file everything works so it must be conflicting with something in the main files.
    Any help would be MUCH appreciated!!!!
    Cheers

    Thanks for the reply Ned,
    The file is set to use AS3 and I'm pretty sure the original should be set to AS3 as the .as files look like AS3 syntax to me - here's a sample:
    protected function handleWwrdButtonClick(e:ButtonEvent):void {
    Browser.open(globalVar.xml.wwrd.item[0].@url, globalVar.xml.wwrd.item[0].@target);
    OmnitureTracker.trackFeaturedContentClick('http://www.url.com/movies/international', 'wwrd_button');
    timer.stop();
    timer.removeEventListener(TimerEvent.TIMER, onTimer);
    I'm wondering if all the Actionscript has be placed into one of the .as files as there isn't any Actionscript in the Flash project - a part from the odd stop()
    Really stuck on this one (I'm not an expert at all) so any help in deciphering the project would be much appreciated.
    Cheers

  • Type was not found or was not a compile-time constant?

    Hi guys,
    I'm going nuts. I've got this movieclip that I made into a
    button with ActionScript. When clicked, it
    should go to a frame in my main timeline labeled "beansbus",
    but whenever I try to test the movie out, Flash
    gives me this error:
    1046: Type was not found or was not a compile-time constant:
    bus.
    I've looked around on the internet and I've been told that
    this error can
    crop up if the instance name is the same as a library object.
    That WAS the
    problem, but I renamed the library object to Cutebus, so that
    should have fixed it, I hope. There was another fix that involved
    something called TextFields in my movieclip, but I don't have
    those...
    My code looks like this, which was copied and pasted from an
    in-class tutorial that DOES work, with no problems.
    Thanks in advance for any light you can shed on this.

    actually the error:
    quote:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference. at
    beans_fla::MainTimeline/frame1()[beans_fla.MainTimeline::frame1:3]
    may not obviously give the line number at first
    glance, but it does! 'frame 1:3' refers to frame 1, line 3. which
    if your code post was accurate to line numbers, refers to:
    quote:
    bus.stop();
    so i'd suggest looking at your bus clip and
    ensuring that you have correctly defined its instance name. Also,
    make sure you have this correctly defined in each keyframe that the
    clip appears.

  • Help! "1046: Type was not found or was not a compile-time constant:TimerEvent."

    I am getting the followiing error in my main document class:
    "1046: Type was not found or was not a compile-time constant:TimerEvent."
    It's showing in line 47 and 54 (in red below). Any help would be appreciated. BTW, this is my first time creating a main document class since graduating to class files!:
    package
        //**************** IMPORT STATMENTS *********************
        import flash.display.MovieClip;
        import com.greensock.TweenLite;
        import flash.utils.Timer;
        public class Main extends MovieClip
            //***************** Variables ***************************
            /*private var appStoreURL:URLRequest = new URLRequest("http://itunes.apple.com/us/artist/quackenworth/id518210161");
            private var facebookURL:URLRequest = new URLRequest("http://www.facebook.com/quackenworth");
            private var twitterURL:URLRequest = new URLRequest("http://www.twitter.com/quackenworth");*/
            private var MainScene:Main = new Main();
            private var PopUp_MoreApps:MoreApps_mc = new MoreApps_mc();
            private var PopUp_About:About_mc = new About_mc();
            //*****SPLASH SCREEN ***
            private var mc_timerSplash:Timer;
            private var splashScreen:mcSplashScreen;
            //*****************CONSTRUCTOR CODE ***********************************************************************************
            public function Main()
                mc_timerSplash = new Timer(3000,1);
                mc_timerSplash.addEventListener(TimerEvent.TIMER,  StartTimer);
                //When timer is finished stop the timer;
                mc_timerSplash.addEventListener(TimerEvent.TIMER_COMPLETE, timerCompleted);
                splashScreen = new mcSplashScreen();
                 addChild(splashScreen);
                splashScreen.x = stage.stageWidth / 2;
                splashScreen.y = stage.stageHeight / 2;
                mc_timerSplash.start();
            //*********** FUNCTIONS *********************************
            private function timerCompleted(e:TimerEvent):void
                    mc_timerSplash.stop();
                    mc_timerSplash = null;
            private function StartTimer(e:TimerEvent):void
                TweenLite.to(splashScreen, 1, {alpha:0, onComplete: SplashScreen});
            private function SplashScreen():void
                removeChild(splashScreen);
                addMainScene();
            private function addMainScene():void
                addChild(MainScene);
                MainScene.x = 489;
                MainScene.y = 350;
                //TweenLite.from(MainScene.wbbIntro_mc, .5, {alpha: 0});
                TweenLite.from(MainScene, 1, {alpha:0});
                TweenLite.to(MainScene.girls_mc, 1, {y:395, delay:.3});
                TweenLite.to(MainScene.boys_mc, .5, {y:396, delay: .6});
                TweenLite.to(MainScene.Joe_mc, .5, {y:339, delay: 1});
                TweenLite.to(MainScene.Paul_mc, .5, {y:322, delay:1.2});
            private function removeMainScene():void
                removeChild(MainScene);
                TweenLite.to(MainScene.girls_mc, .1, {y:690});
                TweenLite.to(MainScene.boys_mc, .1, {y:693});
                TweenLite.to(MainScene.Joe_mc, .1, {y:636});
                TweenLite.to(MainScene.Paul_mc, .1, {y:619});

    Now that the error is solved, when I test nothing happens. I just get a blank screen.
    What is supposed to happen? When the program opens a splash screen should be added for 3 seconds and then fade out. Then some main screen movie clips should be added to the stage.

  • Constants v/s compile time constants.

    Hi to all.
    I got a problem in understanding compile time constants.
    I was reading about switch statement, and found a fact:
    the case constant in switch statement should be compile time constant.
    and example they have given is:
    final int a=1;
    final int b;
    b=2;
    int x=0;
    switch(x)
    case a: //ok.
    case b: //compiler error.
    so is it true, that compile time constants are only those which are final and are initialized at the time of declaration itself.
    then what b will be called, "runtime constant" (sounds odd).

    I once read on a post here (or article) that the
    compiler will replace any variable name you set in
    the switch case with the actual value. That is why
    it
    works on 'a' but not on 'b'. At compile time the
    compiler only knows the value of 'a'.
    That is not why you can use a but not b for the
    switch. The reason is that the compiler knows the
    value of a but not of b.
    What's the difference?

  • Custom class loader and local class accessing local variable

    I have written my own class loader to solve a specific problem. It
    seemed to work very well, but then I started noticing strange errors in
    the log output. Here is an example. Some of the names are in Norwegian,
    but they are not important to this discussion. JavaNotis.Oppstart is the
    name of my class loader class.
    java.lang.ClassFormatError: JavaNotis/SendMeldingDialog$1 (Illegal
    variable name " val$indeks")
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
    at JavaNotis.Oppstart.findClass(Oppstart.java:193)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at JavaNotis.SendMeldingDialog.init(SendMeldingDialog.java:78)
    at JavaNotis.SendMeldingDialog.<init>(SendMeldingDialog.java:54)
    at JavaNotis.Notistavle.sendMelding(Notistavle.java:542)
    at JavaNotis.Notistavle.access$900(Notistavle.java:59)
    at JavaNotis.Notistavle$27.actionPerformed(Notistavle.java:427)
    JavaNotis/SendMeldingDialog$1 is a local class in the method
    JavaNotis.SendMeldingDialog.init, and it's accessing a final local
    variable named indeks. The compiler automatically turns this into a
    variable in the inner class called val$indeks. But look at the error
    message, there is an extra space in front of the variable name.
    This error doesn't occur when I don't use my custom class loader and
    instead load the classes through the default class loader in the JVM.
    Here is my class loading code. Is there something wrong with it?
    Again some Norwegian words, but it should still be understandable I hope.
         protected Class findClass(String name) throws ClassNotFoundException
             byte[] b = loadClassData(name);
             return defineClass(name, b, 0, b.length);
         private byte[] loadClassData(String name) throws ClassNotFoundException
             ByteArrayOutputStream ut = null;
             InputStream inn = null;
             try
                 JarEntry klasse = arkiv.getJarEntry(name.replace('.', '/')
    + ".class");
                 if (klasse == null)
                    throw new ClassNotFoundException("Finner ikke klassen "
    + NOTISKLASSE);
                 inn = arkiv.getInputStream(klasse);
                 ut = new ByteArrayOutputStream(inn.available());
                 byte[] kode = new byte[4096];
                 int antall = inn.read(kode);
                 while (antall > 0)
                     ut.write(kode, 0, antall);
                     antall = inn.read(kode);
                 return ut.toByteArray();
             catch (IOException ioe)
                 throw new RuntimeException(ioe.getMessage());
             finally
                 try
                    if (inn != null)
                       inn.close();
                    if (ut != null)
                       ut.close();
                 catch (IOException ioe)
         }I hope somebody can help. :-)
    Regards,
    Knut St�re

    I'm not quite sure how Java handles local classes defined within a method, but from this example it seems as if the local class isn't loaded until it is actually needed, that is when the method is called, which seems like a good thing to me.
    The parent class is already loaded as you can see. It is the loading of the inner class that fails.
    But maybe there is something I've forgotten in my loading code? I know in the "early days" you had to do a lot more to load a class, but I think all that is taken care of by the superclass of my classloader now. All I have to do is provide the raw data of the class. Isn't it so?

  • Compile time constant

    what is compile time constant
    1. final int a=9;
    2 final int b
    b=9;
    is 2 statement not a compile time constant

    Screen13Name wrote:
    but we cannot change its value then how it is not a constantThe term "compile-time constant" has a very specific meaning and very specific implications in the Java language.
    Just because something isn't a compile-time constant doesn't mean that it can be changed.

  • Dynamic class loading and Casting

    Hi guys,
    spent lots of time trying to figure out how to do one thing with no luck, hope anybody can help me here. Here is what I have:
    I need to create a new object, I have dynamic variable of what kind of an object I need:
    sObjectType = "Article";
    ItemObject oItem = Item.init(1000, 1);           
    oItem.ArticleObjectCall();                      // ERROR is here, method does not exist, ArticleObjectCall is method of the Article classItem is a static Class that inits objects
    public class Item {
         public static ItemObject init(String sObjectType) {
                  ItemObject oClass = Class.forName("com.type." + sObjectType).newInstance();
                  return oClass;
    }Below are the 2 classes Article and ItemObject
    Article
    package com.type;
    public class Article extends ItemObject {     
         public void ArticleObjectCall() {
              System.out.println("Article Hello");
    ItemObject
    public class ItemObject {
         public ItemObject() {          
    }

    Ajaxian wrote:
    This is a method INIT, I am dynamically including class com.type.Article , Article extends ItemObject, I am casting new instance of Article to (ItemObject) to return a proper type but later when I try to call oClass object which is I believe my Article class, I get an error. None of which answers my question, yet it does show that you are thoroughly confused...
    String x = "blub";
    Object y = x;
    System.out.println(y.length); // We both know y is a string, but the compiler does not. => ErrorThe compiler enforces the rules of a static type system, your question is quite explicitly about dynamism, which is not without reason the antonym to statics. If you load classes dynamically, you need to use reflection to invoke their methods.
    With kind regards
    Ben

  • Dynamic Class Loading and Stubs

    How Dynamic Class Loading is used on Java RMI, since stubs are generated on clients using Reflection API?
    I was reading Dynamic code downloading using JavaTM RMI (http://java.sun.com/javase/6/docs/technotes/guides/rmi/codebase.html), it seems to be out of date.
    For example, "The client requests the class definition from the codebase. The codebase the client uses is the URL that was annotated to the stub instance when the stub class was loaded by the registry. Back in step 1, the annotated stub for the exported object was then registered with the Java RMI registry bound to a name."

    "Enhancements in J2SETM 5.0
    Dynamic Generation of Stub Classes
    This release adds support for the dynamic generation of stub classes at runtime, obviating the need to use the Java(tm) Remote Method Invocation (Java RMI) stub compiler, rmic, to pregenerate stub classes for remote objects. *Note that rmic must still be used to pregenerate stub classes for remote objects that need to support clients running on _earlier versions_.*
    When an application exports a remote object (using the constructors or static exportObject methods(1) of the classes java.rmi.server.UnicastRemoteObject or java.rmi.activation.Activatable) and a pregenerated stub class for the remote object's class cannot be loaded, the remote object's stub will be a java.lang.reflect.Proxy instance (whose class is dynamically generated) with a java.rmi.server.RemoteObjectInvocationHandler as its invocation handler.
    An existing application can be deployed to use dynamically generated stub classes unconditionally (that is, whether or not pregenerated stub classes exist) by setting the system property java.rmi.server.ignoreStubClasses to "true". If this property is set to "true", pregenerated stub classes are never used.
    Notes:
    * If a remote object has pre-5.0 clients, that remote object should use a stub class pregenerated with rmic or the client will get an ClassNotFoundException deserializing the remote object's stub. Pre-5.0 clients will not be able to load an instance of a dynamically generated stub class, because such a class contains an instance of RemoteObjectInvocationHandler, which was not available prior to this release.
    * Prior to the J2SE 5.0 release, exporting a remote object would throw a java.rmi.StubNotFoundException if the pregenerated stub class for the remote object's class could not be loaded. With the added support for dynamically generated stub classes, exporting a remote object that has no pregenerated stub class will silently succeed instead. A user deploying a server application to support pre-5.0 clients must still make sure to pregenerate stub classes for the server's remote object classes, even though missing stub classes are no longer reported at export time. Such errors will instead be reported to a pre-5.0 client when it deserializes a dynamically generated stub class.
    (1) The static method UnicastRemoteObject.exportObject(Remote) is declared to return java.rmi.server.RemoteStub and therefore cannot be used to export a remote object to use a dynamically generated stub class for its stub. An instance of a dynamically generated stub class is a java.lang.reflect.Proxy instance which is not assignable to RemoteStub."
    http://java.sun.com/j2se/1.5.0/docs/guide/rmi/relnotes.html

  • [CQ newbie] Possible to load and compile all CQ pages in continuous integration?

    I know very little about CQ.
    I'm trying to figure out how we can implement a continuous integration process which would deploy our build to a test server and automatically compile all of the generated pages, and send reports to "last change" authors if there are failures.
    If this was a plain JSP-based application, I know how to do this, because WebLogic gives me the ability to compile all JSPs at deployment time.
    With CQ, I've been told that JSP pages are assembled with the Vault plugin and stored in the repository.  I've seen sample code that can load pages from the repository, but can I use that mechanism to iterate through all the pages in the repository and force them to be loaded, and also get detailed errors if they fail to compile or load?

    I discovered that someone here wrote a "UrlTreeHelper" class that starts from a root node and uses the ResourceResolver and sees if the primary node is "cq:Page", or if it has child nodes.  If the former, it gets the URL path from the node and adds that to a list to return.  If the latter, it recurses through that list. That results in a final list of urls that we can at least do a GET on and verify we get a 200.  If we don't, we at least know something's wrong with that page, even if we don't know what failed.
    They call this from a JSP page, so they can get the ResourceResolver. Is it possible to get the ResourceResolver in plain Java code, so we could call this from something besides a JSP?

  • Dinamyc class loading and jar files

    I'm new to java. I would like to load some plugins in my application (it's going to be packaged as a jar at the end). I managed to find some dinamyc class loading examples but they search for the classes to load in a directory.
    This is the code:
        public static void main(String[] args) {
            File pluginDirectory = new File("src/pluginsreloaded/plugins");
            if (!pluginDirectory.exists()) {            // the plugin directory does not exist
                System.out.println("The plugins directory does not exist!");           
                return;
            FilenameFilter filter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.endsWith(".class");
            String[] pluginFiles = pluginDirectory.list(filter);
            for (int i = 0; i < pluginFiles.length; i++) {
                if (pluginFiles.indexOf("$") == -1) {
    System.out.println("Loading: " + pluginFiles[i].substring(0, pluginFiles[i].length() - 6));
    IPlugin plugin = pm.loadPlugin(pluginFiles[i].substring(0, pluginFiles[i].length() - 6));
    System.out.println(plugin.description());
    protected static IPlugin loadPlugin(String name) {
            // Query the plugin list for the plugin
            PluginFactory _plugin = (PluginFactory) pluginList.get(name);
            if (_plugin == null) {          // the plugin is not loaded
                try {
                    Class.forName("pluginsReloaded.plugins." + name);
                    // The plugin makes an entry in the plugin list
                    // when loaded
                    _plugin = (PluginFactory) pluginList.get(name);
                    if (_plugin == null) {
                        return null;
                } catch (ClassNotFoundException e) {
                    System.out.println("Plugin " + name + " not found!");
            return _plugin.create();
        }IPlugin is an interface. I am using netbeans 5.0. The error I get is this:
    Exception in thread "main" java.lang.NoClassDefFoundError: pluginsReloaded/plugins/plugin1 (wrong name: pluginsreloaded/plugins/plugin1)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:164)
            at pluginsreloaded.PluginManager.loadPlugin(PluginManager.java:30)
            at pluginsreloaded.Main.main(Main.java:44)
    Java Result: 1As far as I can see it can't find the class. My question is how can I load the class/where can I find it?
    Thanks.

    You can use the java.util.jar.JarFile class to enumerate the contents of a jar. It's not good practice to search for plugins in this way though. A plugin may well involve serveral classes, which don't all have to be internal. Furthermore its wise to avoid any comitment about the mechaism by which class files are to be fetched. You might want to do it remotely, some time, or load them from a database.
    What seesms to be the standard approach is to put a list of plugin classes into the jar as a text file.
    Plugins for a given purpose usually implement some specified interface, or extend some abstract class to which their objects can be cast once loaded (without this they aren't really much use).
    Say your plugins implment org.myorg.WidgetFactory then you put a list of them, one fully qualified name to a line, in a file or jar entry called META-INF/services/org.myorg.WidgetFactory. You framework picks up all such files from the classpath using ClassLoader.getResources() and loads all the classes whose names if finds, hence you can add new sets of plugins just by adding a new jar or class directory to the class path.

  • Dynamic Class Loading and Unloading

    I am trying to create a system where the class name and method name is
    picked up from a meta-data database and executed.
    This was accompanied using Dynamic Class loading. I tried to extend this to
    support versioning of meta-data. Here depending on the version of meta-data
    different libraries can be loaded and different implementations of object
    with the same name can be executed. This does not seem to work with Forte
    3.0.
    When the second Library is loaded the method execution does not work.
    (Even though the unload flag on the LoadLibrary is set)
    If the application is stopped and restarted pointing to the second library
    there is no problem. In a running application a dynamically loaded library
    does not seem to unload and reload a new library for the same class names.
    Has anyone tried sometime similar, is there a workaround for this type of
    problem.
    - Vivek

    I am trying to create a system where the class name and method name is
    picked up from a meta-data database and executed.
    This was accompanied using Dynamic Class loading. I tried to extend this to
    support versioning of meta-data. Here depending on the version of meta-data
    different libraries can be loaded and different implementations of object
    with the same name can be executed. This does not seem to work with Forte
    3.0.
    When the second Library is loaded the method execution does not work.
    (Even though the unload flag on the LoadLibrary is set)
    If the application is stopped and restarted pointing to the second library
    there is no problem. In a running application a dynamically loaded library
    does not seem to unload and reload a new library for the same class names.
    Has anyone tried sometime similar, is there a workaround for this type of
    problem.
    - Vivek

Maybe you are looking for

  • Nokia C3-01 Touch messaging application with qwert...

    It will be good if we can have touch application with qwerty setup for messaging. Also, why angry birds game is not developed for S40 6th edition phone...? Will it be available soon?

  • Items could not be found

    i transferred (or tried) my library to our new PC but when I sync i get a message stating a number of items were not copied to my ipod because they could not be found. Any suggestions on how to correct this?

  • MacBook Pro randomnly freezes/crashes

    I have a client (I'm a local tech just getting crash courses in Macs) who's MacBook Pro randomly freezes/crashes. I have ran a disk repair but the issue still persists. He has sent me quite a few different crash reports which I can't make heads or ta

  • Cache of a File System

    Would appreciate it if someone could validate my thought process: I'm looking to put together a large distributed cache and use the file system (shared by all cluster nodes) as long-term storage. My approach has been to: use a distributed scheme with

  • How to Execute a Model

    I created an abap routine call Get_BPList. It does a very simple select and brings back 3 fields. I tested the function module and it works ok. I just want to execute it in dynpro and fill a dropdown list I created a model and pointed it to the RFC o