Solved

Add an external folder to CLASSPATH for jsp compilation

Posted on 2006-06-24
13
1,008 Views
Last Modified: 2008-01-09
I have a web application running in c:\app. This folder has all the jsp pages and the WEB-INF folder (obviosly) and other stuff.

I have some java classes (in different packages) in c:\lib\java\ (class name example:- ExternalClass.java

I refer to these "some" java classes in a class named MyClass.java (saved in \app\WEB-INF\classes\)  which is used in a JSP page.

I get a jasper something error saying that it is unable to find the ExternalClass.java

Kindly suggest.

Thanks,
Kanishk.
0
Comment
Question by:kanishkpanwar
  • 7
  • 5
13 Comments
 
LVL 27

Expert Comment

by:rrz
Comment Utility
>I have some java classes (in different packages) in c:\lib\java\  
If  c:\lib\java  is not in your classpath , then you should put it there.  
>I refer to these "some" java classes in a class named MyClass.java    
You should  import those "different packages"  in  MyClass.java.  For example  
import com.package1.*;
import com.package2.someClass;
0
 

Author Comment

by:kanishkpanwar
Comment Utility
1)  I have the library in classpath.

2) yes, I do use import statement.
0
 

Author Comment

by:kanishkpanwar
Comment Utility
I get this
------------------

javax.servlet.ServletException: net/tinyos/message/MessageListener
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.Main_jsp._jspService(Main_jsp.java:148)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      wsn.Main.doPost(Main.java:88)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.NoClassDefFoundError: net/tinyos/message/MessageListener
      java.lang.ClassLoader.defineClass0(Native Method)
      java.lang.ClassLoader.defineClass(ClassLoader.java:539)
      java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1634)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:860)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1307)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
      org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:148)
      org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:69)
      java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
      org.apache.jsp.Main_jsp._jspService(Main_jsp.java:124)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      wsn.Main.doPost(Main.java:88)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
I can't see problem. But someone can help.
>2) yes, I do use import statement.  
Show us that line.
>org.apache.jsp.Main_jsp._jspService(Main_jsp.java:124)  
>org.apache.jsp.Main_jsp._jspService(Main_jsp.java:148  
Show us those lines.  Look in Tomcat's work folder for  Main_jsp.java
0
 

Author Comment

by:kanishkpanwar
Comment Utility
jsp file:
<%@ page language="java" import="java.util.*,wsn.*" pageEncoding="UTF-8"%>

java file:
package wsn;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;


import edu.rit.util.Timer;
import edu.rit.util.TimerTask;
import edu.rit.util.TimerThread;

import net.tinyos.message.Message;
import net.tinyos.message.MessageListener;
import net.tinyos.message.MoteIF;
import net.tinyos.oscope.OscopeMsg;
import net.tinyos.util.PrintStreamMessenger;

/**
 *
 *
 * @author Kanishk Panwar
 *
 */
public class DataReadingLayer implements MessageListener, Runnable {

      private static final int HUMIDITY = 0;

      private static final int TEMPERATURE = 1;

      private static final int TSR = 2;

      private static final int PAR = 3;

      private static final int ITEMP = 4;

      private static final int IVOLT = 5;

      private static final int MOTEID = 6;

      private static final int READING = 7;

      private static final int LAST_READ = 8;

      private static final int[] MONITORED_CHANNELS = { 0, 1, 2, 5 };

      private static boolean monitor = true;

      private static DataReadingLayer INSTANCE = null;

      private HashMap moteList = new HashMap();

      /**
       *
       *
       */
      public DataReadingLayer() {

            // register message listener - serial forwarder must be running
            MoteIF mote = new MoteIF(PrintStreamMessenger.err, -1);
            mote.registerListener(new OscopeMsg(), this);
            System.out.println("Started...");
            startMonitoring();
      }

      /**
       *
       *
       */
      public void run() {

            while (getMonitoringStatus()) {
                  try {
                        this.wait();
                  } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                  }
            }
      }

      /**
       *
       */
      private synchronized static void createInstance() {
            INSTANCE = new DataReadingLayer();
      }

      /**
       *
       * @return
       */
      public static DataReadingLayer getInstance() {

            if (INSTANCE == null)
                  createInstance();

            return INSTANCE;
      }

      /**
       *
       *
       */
      public synchronized static boolean doesInstanceExist() {
            if(INSTANCE==null)
                  return true;
            
            return false;
      }
      
      
      /**
       *
       */
      public synchronized static void releaseInstance() {
            INSTANCE = null;
      }
      
      
      /**
       *
       *
       * @author Kanishk Panwar
       *
       */
      public class Motes implements TimerTask {

            HashMap channelReadings = new HashMap();

            HashMap readingAnomaly = new HashMap();

            HashMap readingTiming = new HashMap();

            private Timer myTimer = null;

            private int id;

            /**
             *
             * @param moteID
             */
            public Motes(int moteID) {
                  id = moteID;
                  if (myTimer == null)
                        myTimer = TimerThread.getDefault().createTimer(this);

                  myTimer.start(10000L);
            }

            /**
             *
             * @param channel
             * @param value
             */
            public void updateReading(int channel, double value, Date current,
                        boolean anomalyStatus) {

                  if (!myTimer.isTriggered())
                        myTimer.stop();

                  if (!channelReadings.containsKey(new Integer(channel)))
                        channelReadings.put(new Integer(channel), new Vector());

                  Vector readings = (Vector) channelReadings
                              .get(new Integer(channel));

                  if (readings.size() == 20)
                        readings.remove(0);

                  readings.add(new Double(value));

                  channelReadings.put(new Integer(channel), readings);

                  // update timings
                  if (!readingTiming.containsKey(new Integer(channel)))
                        readingTiming.put(new Integer(channel), new Vector());

                  Vector timings = (Vector) readingTiming.get(new Integer(channel));

                  if (timings.size() == 20)
                        timings.remove(0);

                  timings.add(WSNUtil.dateTimeFormat.format(current));

                  readingTiming.put(new Integer(channel), timings);

                  // update anomaly
                  if (!readingAnomaly.containsKey(new Integer(channel)))
                        readingAnomaly.put(new Integer(channel), new Vector());

                  Vector anomaly = (Vector) readingAnomaly.get(new Integer(channel));

                  if (anomaly.size() == 20)
                        anomaly.remove(0);

                  anomaly.add(new Boolean(anomalyStatus));

                  readingAnomaly.put(new Integer(channel), anomaly);

                  myTimer.start(10000L);
            }

            /**
             *
             */
            public void action(Timer theTimer) {

                  stopMote(theTimer, id);
            }

            /**
             *
             * @param channel
             * @return
             */
            public String[][] getChannelReadings(int channel) {

                  Vector readings = (Vector) channelReadings
                              .get(new Integer(channel));

                  Vector timings = (Vector) readingTiming.get(new Integer(channel));

                  Vector anomaly = (Vector) readingAnomaly.get(new Integer(channel));

                  if (readings.size() == 0)
                        return null;

                  String[][] current = new String[3][readings.size()];

                  for (int i = 0; i < readings.size(); i++) {

                        current[0][i] = ((Double) readings.get(i)).toString();
                        current[1][i] = (String) timings.get(i);
                        current[2][i] = ((Boolean) anomaly.get(i)).toString();
                  }

                  return current;
            }

            /**
             *
             * @param channel
             * @return
             */
            public String[] getOnlyChannelReadings(int channel) {

                  return getChannelReadings(channel)[0];
            }

            /**
             *
             * @return
             */
            public int getMoteID() {

                  return id;
            }

            /**
             *
             * @return
             */
            public int[] getChannels() {

                  Set set = channelReadings.keySet();
                  int[] retVal = new int[set.size()];
                  int i = 0;

                  Iterator iter = set.iterator();

                  while (iter.hasNext()) {

                        retVal[i] = ((Integer) iter.next()).intValue();
                        i++;
                  }

                  return retVal;
            }

            public Vector[][] getReadingAndAnomaly() {

                  Vector[][] v = new Vector[4][2];

                  v[0][0] = (Vector) channelReadings.get(new Integer(HUMIDITY));
                  v[0][1] = (Vector) channelReadings.get(new Integer(TEMPERATURE));
                  v[0][2] = (Vector) channelReadings.get(new Integer(TSR));
                  v[0][3] = (Vector) channelReadings.get(new Integer(IVOLT));

                  v[1][0] = (Vector) readingAnomaly.get(new Integer(HUMIDITY));
                  v[1][1] = (Vector) readingAnomaly.get(new Integer(TEMPERATURE));
                  v[1][2] = (Vector) readingAnomaly.get(new Integer(TSR));
                  v[1][3] = (Vector) readingAnomaly.get(new Integer(IVOLT));

                  return v;
            }

      } // inner-class

      /**
       *
       *
       * @param theTimer
       */
      public void stopMote(Timer theTimer, int moteId) {

            theTimer.stop();
            moteList.put(new Integer(moteId), null);
            System.out.println("MOTE IS DEAD !!");
      }

      /**
       *
       */
      public synchronized void messageReceived(int to, Message m) {

            System.out.println("Icoming message...");
            double rawReading = 0d;
            double currentReading = 0d;

            Date date = new Date();

            boolean isAnomaly = false;
            boolean doUpdate = false;

            OscopeMsg myMessage = (OscopeMsg) m; // data packet
            int channel = myMessage.get_channel(); // type of data for this packet
            int numElements = myMessage.numElements_data(); // number of samples
            int moteID = myMessage.get_sourceMoteID(); // id# of the sensor this
            // data is from

            // Object of inner helper class.
            Motes myMote = null;

            // check if the data reading mote is in the list
            if (moteList.containsKey(new Integer(moteID))) {

                  myMote = (Motes) moteList.get(new Integer(moteID));

            } else {

                  myMote = new Motes(moteID);
            }

            // mote has been invalidated.
            if (myMote == null)
                  return;

            // get the average value of the new sampled data from the packet
            for (int i = 0; i < numElements; i++) {
                  rawReading = rawReading + myMessage.getElement_data(i);
            }
            rawReading = rawReading / numElements;

            switch (channel) {
            case HUMIDITY:
                  currentReading = -4 + (0.0405 * rawReading) + (-0.0000028)
                              * (rawReading) * (rawReading);

                  doUpdate = true;
                  break;

            case TEMPERATURE:
                  /*
                   * newVal = -39.60 + ( 0.01 * value ); newVal = ((newVal * 9)/5) +
                   * 32; // convert to Fahrenheit // update previous values Double
                   * vals[] = (Double[]) prevTemperature.get(new Integer(moteID)); for
                   * (int i = 9; i > 0; i--) { vals[i] = vals[i-1]; // shift each
                   * value over 1; drop oldest value } vals[0] = new Double(newVal); //
                   * most recent value prevTemperature.remove(new Integer(moteID));
                   * prevTemperature.put(new Integer(moteID), vals);
                   *
                   * try { // high temperature warning if (newVal > HIGH_TEMP) {
                   * String dString = "[" + cal.getTime().toString() + "] " + "***
                   * HIGH TEMPERATURE WARNING *** \n sensor " + moteID + ":
                   * temperature = " + Double.toString(newVal).substring(0,5) + " F"; } //
                   * high temperature warning if (newVal < LOW_TEMP) { String dString =
                   * "[" + cal.getTime().toString() + "] " + "*** LOW TEMPERATURE
                   * WARNING *** \n sensor " + moteID + ": temperature = " +
                   * Double.toString(newVal).substring(0,5) + " F"; } // sudden
                   * temperature change warning if (vals[DELTA_GAP] != null) { double
                   * temp = vals[DELTA_GAP].doubleValue(); if ( (((newVal - temp) /
                   * newVal) >= DELTA_NORM) || (((temp - newVal) / temp) >=
                   * DELTA_NORM) ) { String dString = "[" + cal.getTime().toString() + "] " +
                   * "*** SUDDEN TEMPERATURE CHANGE WARNING *** sensor " + moteID + ":
                   * temperature = " + Double.toString(newVal).substring(0,5) + " F"; } } }
                   *
                   * catch (Exception e) { }
                   */

                  currentReading = -39.60 + (0.01 * rawReading);
                  currentReading = ((currentReading * 9) / 5) + 32;

                  doUpdate = true;
                  break;

            case TSR:
                  currentReading = rawReading;

                  try {
                        // load the serialized neural network
                        // NeuralNetLoader loader = new NeuralNetLoader("light.nn");
                        // NeuralNet lightNN = loader.getNeuralNet();
                        /*
                         * if (lightNN != null) { // attach DirectSynapse at input Layer
                         * input = lightNN.getInputLayer(); input.removeAllInputs();
                         * DirectSynapse memInp = new DirectSynapse();
                         * input.addInputSynapse(memInp); // attach DirectSynapse at
                         * output Layer output = lightNN.getOutputLayer();
                         * output.removeAllOutputs(); DirectSynapse memOut = new
                         * DirectSynapse(); output.addOutputSynapse(memOut); // run the
                         * network lightNN.getMonitor().setLearning(false);
                         * lightNN.start(); double[] temp = new double[1]; temp[0] =
                         * newVal; Pattern iPattern = new Pattern(temp); // Interrogate
                         * the net memInp.fwdPut(iPattern); Pattern pattern =
                         * memOut.fwdGet(); double output1 = pattern.getArray()[0];
                         * double output2 = pattern.getArray()[1]; double output3 =
                         * pattern.getArray()[2];
                         *
                         * if (output1 > 0.8) { String dString = "[" +
                         * cal.getTime().toString() + "] " + "*** LOW LIGHT WARNING***
                         * \n sensor " + moteID + ": intensity = " +
                         * Double.toString(newVal); buf = dString.getBytes();
                         * DatagramPacket packet = new DatagramPacket(buf, buf.length,
                         * group, 1979); socket.send(packet); } else if (output3 > 0.8) {
                         * byte[] buf = new byte[256]; InetAddress group =
                         * InetAddress.getByName("230.0.0.2"); String dString = "[" +
                         * cal.getTime().toString() + "] " + "*** HIGH LIGHT WARNING ***
                         * \n sensor " + moteID + ": intensity = " +
                         * Double.toString(newVal); buf = dString.getBytes();
                         * DatagramPacket packet = new DatagramPacket(buf, buf.length,
                         * group, 1979); socket.send(packet); } Pattern stop = new
                         * Pattern(new double[1]); stop.setCount(-1);
                         * memInp.fwdPut(stop); memOut.fwdGet(); }
                         */
                  }

                  catch (Exception e) {
                  }
                  doUpdate = true;
                  break;

            case PAR:
                  break;

            case ITEMP:
                  break;

            case IVOLT:
                  currentReading = ((rawReading / 4096) * 1.5) * 2;

                  doUpdate = true;
                  break;

            default:
                  break;
            }

            if (doUpdate) {
                  // update mote data and store it in the hashmap

                  DecimalFormat df2 = new DecimalFormat("#,###,###,##0.00");

                  currentReading = new Double(df2.format(currentReading))
                              .doubleValue();

                  myMote.updateReading(channel, currentReading, date, isAnomaly);
                  moteList.put(new Integer(moteID), myMote);

                  // JDBCLayer.storeReadingInDatabase(channel, currentReading, date,
                  // isAnomaly);
                  if (isAnomaly)
                        new Thread(new CreatePDF(myMote, WSNUtil.dateTimeFormat.format(date))).start();

                  // update database.
                  new Thread(new DAOConnection(moteID, channel, currentReading, date,
                              isAnomaly)).start();

            }
      }

      /**
       *
       *
       */
      public void stopMonitoring() {

            monitor = false;
      }

      /**
       *
       *
       */
      public void startMonitoring() {

            monitor = true;
      }

      /**
       *
       * @return
       */
      public boolean getMonitoringStatus() {

            return monitor;
      }

      /**
       *
       * @return
       */
      public int getMoteCount() {

            return moteList.size();
      }

      /**
       *
       * @param moteID
       */
      public synchronized Vector[][] getMoteDetail(int moteID) {

            return ((Motes) moteList.get(new Integer(moteID)))
                        .getReadingAndAnomaly();

      }

      /**
       *
       * @return
       */
      public Vector[] getSystemDetails() {

            Vector[] readings = new Vector[MONITORED_CHANNELS.length];

            for (int i = 0; i < MONITORED_CHANNELS.length; i++) {
                  
                  
            }

            return readings;
      }

      /**
       * for testing only
       * @param abc
       */
      public static void main (String[] abc) {
            
            new Thread(DataReadingLayer.getInstance()).start();
      }
}


--------------------
Line 124:
if(DataReadingLayer.doesInstanceExist()) {
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
I still can't find the problem. But maybe someone will be able to help.
>1)  I have the library in classpath.
 You have the  wsn package and the  net.tinyos.message package.   The wsn package should be in Tomcat's classpath , that is it should in WEB-INF/classes if it not in a jar.  If it is in a jar it should be in WEB-INF/lib.  The package  net.tinyos.message  should be in your compiler's classpath. I guess you better show us your classpath.     rrz
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 27

Expert Comment

by:rrz
Comment Utility
If the above doesn't work, then try moving both packages into Tomcat, just for a test ?
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
You could try moving  your external classes to  $JAVA_HOME/jre/lib/ext    
 Look at  
http://tomcat.apache.org/tomcat-5.0-doc/class-loader-howto.html
0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
I think the problem is that Tomcat has its own classpath that is separate from the system classpath. So you can put your external classes in $JAVA_HOME/jre/lib/ext     or  you can try to edit Tomcat's startup scripts(which is probably a bad idea). I am sorry that I didn't say this at first comment.  Maybe someone else has a solution.
0
 

Author Comment

by:kanishkpanwar
Comment Utility
the problem is that I cannot move my code from that location because it is a part of a sensor network OS called "TinyOS". I won't mind changing my startup scripts. I mean there is some configurtion for jasper2 whivh I don't know how to edit.
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
Comment Utility
I don't have expertise to help. You should ask to have this question deleted. Sorry I misunderstood.
I did google to find  
http://vidyerthy.blogspot.com/2005_05_08_vidyerthy_archive.html  
which describes changing  the setclasspath  script.    Here is excerpt
"Approach #1: Use system class loader
For this to work with Tomcat, you must modify the
TOMCAT_HOME/bin/setclasspath.sh (or .bat on Windows) to
add the JMagick JAR to the system classpath. Look for the
'# Set standard CLASSPATH' followed by
CLASSPATH="$JAVA_HOME"/lib/tools.jar
and add your JMagick JAR to this, for example
CLASSPATH="$JAVA_HOME"/lib/tools.jar:/opt/JMagick/lib/jmagick.jar "  

But I don't know if you should take this approach.    rrz
0
 
LVL 4

Expert Comment

by:evnafets
Comment Utility
Why can't you just copy the jar file into the web-inf/lib directory?
Ok, so it will have two copies of it on your system, but its worth a try.
Or have you already done that?
0
 

Author Comment

by:kanishkpanwar
Comment Utility
THANK A TON MAN!! It worked. :) *heterosexual hug* :D
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
A procedure for exporting installed hotfix details of remote computers using powershell
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now