• package

    By Jamie Haynes 2 decades ago

    I am using your OpenLog error handling in my java agent. When I package a class, I get an 'OpenLogItem not found' error. I am fairly new to java. Any idea on how to get around this?



    thks,

    jamie

    • Are you using it outside of a Notes agent?

      By Julian Robichaux 2 decades ago

      Jamie -



      Just to clarify, when you say "package in a class", are you trying to write and compile a Java class outside of the Notes environment, and include the OpenLog classes in that? If that's the case, you'll just need to take the source code for the OpenLog Java class and include it in your package somehow (there are a few ways to do this – I won't go into the details, but if you're not sure how to do that please ask my friend Google). Also, you'll need to make sure that the Notes JAR files are available on your Classpath if you do this.



      If you just mean that you're writing a Java agent that's referencing OpenLog and you're getting that error, I think the likely reason is that you're not referencing the OpenLog script library in the agent itself. There are some reasonably good instructions in the OpenLog database itself (Help – Using This Database, and then the "Modifying your existing Java code to use the logging functions" section).



      Hope that helps! Please tell me if I misunderstood the issue.


      • Julian
      • By Jamie Haynes 2 decades ago

        Julian,



        Yes, I am creating a notes java agent. I'll give an example…… more comments after below code…..



        import lotus.domino.*;



        public class JavaAgent extends AgentBase {


        public void NotesMain() {<br/>
        


            try {<br/>
                Session session = getSession();<br/>
                AgentContext agentContext = session.getAgentContext();<br/>
        


               // (Your code goes here) <br/>
        


            } catch(Exception e) {<br/>
                e.printStackTrace();<br/>
            }<br/>
        }<br/>
        

        }// end of javaagent…



        // start of new class…………

        package mypackage.utils;// COMMENT THIS OUT AND ERROR GOES AWAY…..



        import java.sql.;



        /
        *

        • @author haynesj

          *
        • TODO To change the template for this generated type comment go to
        • Window - Preferences - Java - Code Style - Code Templates

          */

          public class JDBCCloser {

          private static OpenLogItem soli = new OpenLogItem();// ERROR OCCURS ON THIS LINE!!!



          public static void close(PreparedStatement ppstmt) {
          if (ppstmt != null) {<br/>
              try {<br/>
                  ppstmt.close();<br/>
                  ppstmt = null;<br/>
              } catch (SQLException sqle) {<br/>
                  sqle.printStackTrace();<br/>
                  System.out.println( soli.logError(sqle) ); // log and display the error<br/>
              }<br/>
          }<br/>
          
          }



          public static void close(Statement pstmt) {
          if (pstmt != null) {<br/>
              try  {<br/>
                  pstmt.close();<br/>
                  pstmt = null;<br/>
              } catch (SQLException sqle) {<br/>
                  sqle.printStackTrace();<br/>
                  System.out.println( soli.logError(sqle) ); // log and display the error<br/>
              }<br/>
          }<br/>
          
          }



          public static void close(ResultSet prez) {
          if (prez != null) {<br/>
              try  {<br/>
                  prez.close();<br/>
                  prez = null;<br/>
              } catch (SQLException sqle) {<br/>
                  sqle.printStackTrace();<br/>
                  System.out.println( soli.logError(sqle) ); // log and display the error<br/>
              }<br/>
          }<br/>
          
          }



          public static void close(Connection pcnxn) {
          if (pcnxn != null) {<br/>
              try  {<br/>
                  pcnxn.close();<br/>
                  pcnxn = null;<br/>
              } catch (SQLException sqle) {<br/>
                  sqle.printStackTrace();<br/>
                  System.out.println( soli.logError(sqle) ); // log and display the error<br/>
              }<br/>
          }<br/>
          
          }

          }//end JDBCCloser







          Ok, I have clicked 'Edit Project' and browsed to 'Shared Java Libraries' where I do see the 'OpenLogClass' and I click 'Add/Replace File/s'. Next, I see the '(Library) OpenLogClass' on the right side of dialog box and I click 'OK' to save changes. When I click save using above code, I get an Errors 'mypackage\utils\JDBCCloser.java: 12: Class mypackage.utils.OpenLogitem not found.' error. If I simply comment out the package declaration line of code ( see above ), then it compiles and saves just fine. I would like to use packages.



          Again, I am fairly new to java so this could be something rather simple. Any advice is appreciated. Thanks for your response.


        • jamie

          haynesj@amerch.com



          Note: I am using the OpenLog class java sl. version 20041111a. I believe this is fairly recent. Also, your instructions in your db are really good - thanks for putting forth effort in that area. It is appreciated.
        • Ah, that helps!

          By Julian Robichaux 2 decades ago

          Jamie -



          Ah! That helps a lot. Thanks for posting the code.



          Here's what's going on: think of the "package" statement like you're telling Java what directory your program is in. With no package statement, all the Java code in your agent (along with included script libraries) are in the same directory – let's pretend it's the c:\notesstuff directory.



          When you add a package statement to your class, you're telling Java that this particular class lives in a different directory than everything else – let's say c:\jamiestuff. Since the OpenLog code is in the c:\notesstuff directory, and your new class is in the c:\jamiestuff directory, the code in c:\jamiestuff can't see the code in c:\notesstuff unless it's on the classpath. In your case it's not, so you get a class not found error.



          The best way to resolve the problem is to comment out the "package" line, as you mention in your code comments. You don't need packages in Notes agents or script libraries, and they'll probably only cause problems. If all this was stand-alone code, that package statement has merit because classes in the same package have special access to each other, but in an agent it's not necessary. You can access all the classes you need by including them in the agent, in a script library, or on the classpath of the machine the agent is running on.



          Hope that helps.


          • Julian