Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

Add an external folder to CLASSPATH for jsp compilation

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
kanishkpanwar
Asked:
kanishkpanwar
  • 7
  • 5
1 Solution
 
rrzCommented:
>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
 
kanishkpanwarAuthor Commented:
1)  I have the library in classpath.

2) yes, I do use import statement.
0
 
kanishkpanwarAuthor Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rrzCommented:
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
 
kanishkpanwarAuthor Commented:
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
 
rrzCommented:
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
 
rrzCommented:
If the above doesn't work, then try moving both packages into Tomcat, just for a test ?
0
 
rrzCommented:
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
 
rrzCommented:
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
 
kanishkpanwarAuthor Commented:
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
 
rrzCommented:
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
 
evnafetsCommented:
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
 
kanishkpanwarAuthor Commented:
THANK A TON MAN!! It worked. :) *heterosexual hug* :D
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now