Using normal class file in the servlet

Hello Friends;
Now my problem is ;
I generated a java file ;
import drasys.or.mp.*;
import drasys.or.mp.lp.*;
public class optimize
    public static void main(String[] args)
    try
        int r=1;
        int s=0;
.This file works perfect. It calls an API and there is no problem. But when I take this code into my servlet, then problem starts. First it says;
"java.lang.NoClassDefFoundError: drasys/or/mp/ScaleException"
but I know it is there. And I mounted the jar file.
Do you think there is a problem with my codes, because it works when it is outside of the servlet.
My servlet code is as follows;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.net.*;
import drasys.or.mp.*;
import drasys.or.mp.lp.*;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
         try
        int r=1;
        int s=0;
        int n = 3;
        int t,w,u,v,f;
        f = 1;
        int z=0;
        int y = 1;
        int l = 1;
        double [][][][] C = new double [1][1][n-1][n];
        double [][][][] D = new double [1][1][n-1][n];
        C[0][0][0][1]=2.5-0.92*r;
        C[0][0][0][2]=1.43-0.37*r;
        C[0][0][1][2]=1.14-0.48*r;
        D[0][0][0][1]=0.65*r+0.94;
        D[0][0][0][2]=0.31*r+0.75;
        D[0][0][1][2]=0.27*r+0.40;
     SizableProblemI prob = new Problem(n*(n-1)+1,n);
        prob.getMetadata().put("lp.isMaximize", "true");
        prob.newVariable("Lambda").setObjectiveCoefficient(1.0);
        for (t=0;t<=(n-1);t++)
            prob.newVariable("W"+t).setObjectiveCoefficient(0);
        final byte LTE = Constraint.LESS;
        final byte EQU = Constraint.EQUAL;
        for (v = 1;v <= n*(n-1);v++)
               prob.newConstraint("constr"+v).setType(LTE).setRightHandSide(y);
            prob.newConstraint("constr"+(n*(n-1)+1)).setType(EQU).setRightHandSide(1);
            // here, we are creating coefficients for lambda.
        for (u = 1; u <= n*(n-1); u++)
                prob.setCoefficientAt("constr"+u,"Lambda",y);
// here, we are creating coefficients for W�s.
        for(t = 0 ; t <= (n-2); t++)
            for (w = 1; w <= (n-1); w++)
                 if (t<w)
                     prob.setCoefficientAt("constr"+l, "W"+t, 1);
                     prob.setCoefficientAt("constr"+l,"W"+w, (-C[s][z][t][w]));
                     l = l + 1;
                     prob.setCoefficientAt("constr"+l, "W"+t, -1.0);
                     prob.setCoefficientAt("constr"+l, "W"+w, D[s][z][t][w]);
                     l = l + 1;
/* here , we are creating coefficients for the last formula which is w1+w2+w3+....Wn = 1 */
            for (f=0; f <= (n-1); f++)
            prob.setCoefficientAt("constr"+(n*(n-1)+1), "W"+f, 1);
/* API finds the solution below.*/
     LinearProgrammingI lp = new DenseSimplex(prob);
        double ans = lp.solve();
        System.out.println("Solution"+r+"="+ans);
        System.out.println(lp.getSolution());
        catch (drasys.or.mp.DuplicateException first)
         first.getMessage();
        catch (drasys.or.mp.NotFoundException second)
        catch (drasys.or.mp.InvalidException third)
        catch (drasys.or.mp.NoSolutionException fourth)
        catch (drasys.or.mp.UnboundedException fifth)
        catch (drasys.or.mp.InfeasibleException sixth)
        catch (drasys.or.mp.ConvergenceException seventh)
        catch (drasys.or.mp.ScaleException eigth)
           eigth.toString();
   

Thanks a lot for the reply.
Forgive me, I have no object oriented background,
even programming. I am just in the learning phase.This is a pretty advanced problem to tackle for your first programming task.
That's why it doesn't follow OO concepts. This part
will be connected to user input part, that I've
completed .Hmmm.
Successful programming depends on one idea: "divide and conquer". You take a big problem and solve it by dividing it into smaller chunks that you CAN handle. You get the solution you want by bringing the smaller chunks together.
In your case I'd recommend that you get the optimization code into a single object that you can test off-line, without Tomcat. It looks like you started to do that with your optimize class, but the mistake you made is to put so much code into the main() method. You can only call that on the command line. Better to encapsulate the rest of it into small methods that will let you instantiate an instance of optimize and call its methods. Once you have that working you can wrap it in a servlet if you want to use it in a Web app.
Separate how your optimizer gets its data from how it processes it. On a desktop app, it might be convenient to read input from a file on disk. A Web app might be better served by an XML stream.
Why I said "I know it is there" because it doesn't
give any other error message than that one, if it
couldn't see the jar file, wouldn't it give me lots
of error messages? Don't assume anything. It only needs one error, which is the one you get when it can't find a class. How many more do you need? The class loader couldn't find that class, so it printed the message and stopped.
"I mounted" the jar file means I'm using Netbeans, I
mounted it to that environment as suggested by
Netbeans, If you don't know Java or programming well, I'm guessing that you also don't know NetBeans. I'd recommend that you figure out how to make all this work without NetBeans before you add another complication to your life.
If you don't use NetBeans, all you have to do is add the JAR to your CLASSPATH using the -classpath option on javac.exe when you compile and java.exe when you execute.
Tomcat assumes that all the JAR files in your Web app's WEB-INF/lib are in the CLASSPATH. If you put it in there, Tomcat will find it.
you're right, I'm using Tomcat 5.0,
everything is working fine, user input servlets,
mysql connection etc. Only this part is causing the
problem now.If you've already got a Web app deployed and connected to MySQL, you're not doing too badly. Kudos to you - that's not too bad for someone who claims to be a programming novice.
I'll put that jar file into lib folder as you suggested thanks.I think that might be all you'll need. Try it and see.
Actually I saw an example it was using "throws
exception" , I couldn't figure out where to put it,
and I decided to get rid of the compiling errors just
putting bunch of catch statements.If you're saying that your code is throwing a lot of checked exceptions, and you added these extra catch blocks to get rid of them, another way to do it would be to simply have a single catch block, like this:
try
    // your code in here
catch (Exception e)
    e.printStackTrace();
}Polymorphism says that this catch block will handle all checked exceptions.
>
Looks like I don't know anything but I'm trying to
handle a big thing :))).Indeed you are. Anyone who can write a Web app and connect it to a relational database on their first try is hardly helpless. We're all ignorant, just about different things. Keep digging - you'll make this work.
But thank you soooo much for your detailed answer, and happy new year.
Shamil.And the same to you, Shamil. Good luck, and let me know how you make out.
%

Similar Messages

  • Tomcat Web-server uses old .class files

    Hi Friends,
    My Tomcat webserver uses old .class files. The problem persists even if I delete old class files. The new ones are formed but then if i again recompile, the new-old ones are used :)
    Am I doing something wrong????
    Please suggest!!

    I have experienced this problem before as well. Tomcat seems to cache compiled class files for better speed. To get Tomcat to reload class files that I've recently recompiled here is what I do:
    1. Go into the Tomcat server administration area (http://localhost/admin)
    2. Choose the context that is using the classes that you want to reload (from Service / Host)
    3. Make sure reloadable is set to true
    3. Click save, and then commit changes
    Hope this helps, but if there is a better way to get Tomcat to use the most recent class files I would love to hear it!

  • Using normal classes in a JSP

    I have written a library of classes for use in a standard application. In a completely separate project I need to use these classes in a JSP page. Under %tomcat/webapps/myproject is the JSP file. Where do I place the "normal" class files and how do I reference them in the JSP page? Do I need to import them or add them to the classpath and should they be pre-compiled ?
    All help most appreciated
    Thanks
    Bob

    Where do I place the "normal" class files and how do
    I reference them in the JSP page?Just like you use any other class in a JSP.
    Do I need to import them or add them to the classpath and should they be pre-compiled ?Yes, yes and yes. The first thing is something you need to do for your stuff to compile (technically, you don't need to do it, but it's better than always using the fully qualified class names in the code). The second is something the servlet container will do for you when you deploy your WAR. The this is something you need to do with classes anyway. You don't need to do it for JSPs because the container will do it later, but that's all the difference there is.

  • Where to put .class file of a servlet to run it on Tomcat 4.0

    where do i put my .class file of my servlet or maybe the .java one too in order to run it using Tomcat 4.0
    thanks in advance

    i got it by accident a while ago.. hehe
    thank you for trying to help thou :)
    ivo

  • How to access a class file outside the package?

    created a two java files Counter.java and TestCounter.java as shown below:
    public class Counter
         public void print()
              System.out.println("counter");
    package foo;
    public class TestCounter
         public static void main(String args[])
              Counter c = new Counter();
              c.print();
    Both these files are stored under "D:\Test". I first compiled Counter.java and got Counter.class which resides in folder "D:\Test"
    when i compile TestCounter.java i got the following error message:
    D:\Test>javac -classpath "d:\Test" -d "d:\Test" TestCounter.java
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    TestCounter.java:6: cannot find symbol
    symbol : class Counter
    location: class foo.TestCounter
    Counter c = new Counter();
    ^
    2 errors
    what could be the problem. Is it possible to access a class file outside the package?

    ya that's fine..if we have two java files where both resides in the same package works fine or two java files which donot have a package statement also works fine. But my doubt is, i have a Counter.class which does not reside in a package and i have a TestCounter.class which resides in a package "foo", in such a scenario, how do i tell to the compiler that "Counter.class resides in such a path, please look at that and give me TestCounter.class". i cannot use import statement to import Counter.class in TestCounter.java because i donot have a package for Counter.java.

  • Error Message When Using a Class Files to Control Navigation

    This is my first attempt at using a class file in a flash project. My intent is to keep all of my navigation elements in class file called "Navigation".  However, I keep getting an error message when I publish.
    I am using a button to go back to the main screen and I gave that button the instance name of "bnt_home". I have also linked that button in the library to the class "Navigation".
    Here is the code:
    package
        import flash.display.SimpleButton;
        public class Navigation extends SimpleButton
            public function Navigation()
                bnt_home.addEventListener(MouseEvent.MOUSE_DOWN, goNavigation);
            private function goNavigation(event:MouseEvent):void
                gotoAndPlay(1,"Main");

    When I changed the code I got error (1046: Type was not found or was not a compile-time constant: MouseEvent).
    package
        import flash.display.SimpleButton;
        public class Navigation extends SimpleButton
            public function Navigation()
                this.addEventListener(MouseEvent.MOUSE_DOWN, goNavigation);
            private function goNavigation(event:MouseEvent):void
                root.gotoAndPlay(1,"Main");

  • URGENT PLEASE:How can I run a a class file on the Apache server?

    Hi Guys and Gurus,
    I am seeking some favor all of experienced gurus, i.e.
    How can I run a a class file on the Apache server? Can I run through an Applet?
    How can I set Environment variables in Windows2000 Professional Environment?
    Actually, I want to extract some records from a MySQL Database running on Apache Server. I wrote a program just to select the columns and show them. It is now a Class file, Now how can I run this class file from the Server???
    The code is here
    import java.sql.*;
    public class RecordShow {
    public static void main(String args[]) {
    String url = "jdbc:mysql://localhost/myhost";
    Connection con;
    String query = "select mytable.column," +
    "from mytable " +
    "where mytable.column = 1";
    Statement stmt;
    try {
    Class.forName("com.mysql.jdbc.Driver");
    } catch(java.lang.ClassNotFoundException e) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    try {
    con = DriverManager.getConnection(url,
    "myuser", "mypassword");
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(query);
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    int rowCount = 1;
    while (rs.next()) {
    System.out.println("Row " + rowCount + ": ");
    for (int i = 1; i <= numberOfColumns; i++) {
    System.out.print(" Column " + i + ": ");
    System.out.println(rs.getString(i));
    System.out.println("");
    rowCount++;
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.print("SQLException: ");
    System.err.println(ex.getMessage());
    Please advise... THANKS
    VJ

    Ehm, I wasn't referring to you at all... read up,
    there's a comment by jschell saying that CGI might be
    easier/better for his purposes.
    Yep.
    I know PHP/Perl/whatever might be easier for some
    purposes, but only if you happen to know them and want
    to/are able to use them. Ok. But you aren't the one asking the question are you. And the person who asked the question seems to have absolutely no familiarity with Apache or applets.
    So whatever they do they are going to have to learn a lot.
    And that does indeed suggest that in all likelyhood they have not investigated the alternatives.
    And for the vast majority of internet applications, especially with smaller projects (obvious this person is not working with a large team), using perl, or something besides java, is going to be the best business solution. It is simpler, and more secure (probably due to the fact that it is simpler.)
    Since this is a Java forum, I
    answer under the assumption that people have made a
    choice one way or another to use a Java solution to
    their problem, so I try to solve it in Java first, and
    only when that fails (very seldom) do I turn to other
    solutions.You approach problems by arbritrarily deciding to try to solve it in java first and only if you fail do you then look to other solutions?
    My first step is to try to figure out which of the various avenues is going to cost less. (And a secondary, but non-trivial concern, is then to convince the customer that just because they have heard of a buzz word like 'enterprise bean' that it doesn't mean that is a cost effective solution.) We must come from different worlds.

  • Creation of class files on the spot

    I have read in an article that a class loader (generally a subclass of the abstract class ClassLoader can load classes from the local disk, fetch them across a net using a protocol, or it can just create the byte code on the spot.
    How can a class loader create files on the spot? Or, better: why would a class loader create a class file on the spot?

    It's rare, here's an admittedly contrived example.
    You have a database table, and you'd like to create a collection of objects that mirrors the collection of rows in the table. So you collect all of the types and names of each column, and create a new Java class with getter/setter methods for these columns, along with the private member variables themselves. If this class followed the JavaBean style, you could manipulate these objects and use them dynamically using bean tools.

  • Running class files from the windows command line...

    Hello Everyone,
    My instructor showed us a way to run class files from the windows command line. However every time I try to run the class file from the command line using a command like: java CruiseHelper.class
    I get an error that states "Exception in thread "main" java.lang.NoClassDefFoundError: CruiseHelper/class"

    Hello Everyone,
    My instructor showed us a way to run class files from
    the windows command line. However every time I try
    to run the class file from the command line using a
    command like: java CruiseHelper.class
    I get an error that states "Exception in thread
    "main" java.lang.NoClassDefFoundError:
    CruiseHelper/class"Classes are not file names. You don't have a class named "CruiseHelper.class", that's a file name. The class name is just CruiseHelper (if you have no package statement in it).
    So,
    java -classpath . CruiseHelper

  • How to find the location of controller class file on the server

    Hi OAF Experts,
    We have a extended controller in which we are making some changes. We have compiled the java file.
    Now we want to deploy the .class file on the server. When we search on the server where we need to deploy the class file, we find two to three paths. Is there a way from which we can decide which path is actually referred ?
    Is there a front end page available from where we will be gettng these details??
    Regards
    Samarth

    Hi,
    You can get the complete path from front end.
    On 'About this Page', there is a section for 'Business Components'. When you expand that, you can see all the controllers used with complete path.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to add class file to the project in netbean

    Hi,
    I am not sure if it is the right place to put the question. I just cannot find the way to add my existing java class file into the project in net bean.
    Anyone can help?
    Thanks a lot

    Look at the "classpath" entry on the Index tab in NB's Help. There are entries there that explain how to add existing classes and libraries to a project.

  • How can I run a a class file on the Apache server?

    Hi Guys and Gurus,
    I am seeking some favor all of experienced gurus, i.e.
    How can I run a a class file on the Apache server?
    Actually, I want to extract some records from a MySQL Database running on Apache Server. I wrote a program just to select the columns and show them. It is now a Class file, Now how can I run this class file from the Server???
    Please advise...
    VJ

    cross posted
    http://forum.java.sun.com/thread.jsp?thread=299137&forum=31&message=1184025

  • After installing latest update Realplayer recording no longer works, I think Mozila is using a library file with the same name

    After installing the latest update to Firefox onto Vista operating system the record part of real player no longer works, I think Mozila and Real are using a library file with the same name and the Mozila update is overwriting a Realplayer library file.

    I was giong to say, "Help me, Adobe Joe Kenobi", but it looks like you're growing a beard waiting for an answer, too.
    The same thing happened to me today. I trusted the "update" message since it was from Adobe, and apprently did so at my own peril. Now I get the "failed to load Core dll" message with a secondary reference to a memory address.
    Just an observation, but what good are these forums when there are no answers? I see this problem as "Caused by Adobe Update", and would expect them to troublshoot and offer up a remedy. Since you've been waiting over two months with no response, I suppose it's time to trek off wasting more of my precious time to fix their problem. If I find the solution, I'll post it back to you.
    May the Force be with you.
    Mark

  • Where to place the class file of the java bean when using the packager

    I am using the activex bridge in j2se 1.5.0_06
    now i have created the jar file for my bean but where do i place the class file?
    i.e the bean..if i keep it in jdk\bin the packager gives me an error..i created a folder in my public jre jre\axbridge\bin and placed the class file there too but even this didnt work
    Kindly tell me what is the fully qualified package bean name if i have placed all my files under jdk\bin..

    D:\Java\jdk1.5.0_06\bin>packager -reg d:\java\jdk1.5.0_06\bin\PersonBean.jar Per
    son
    Processing D:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\\Person.idl
    Person.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\oaidl.idl
    oaidl.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\objidl.idl
    objidl.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\unknwn.idl
    unknwn.idl
    Processing D:\PROGRA~1\MICROS~2\VC98\INCLUDE\wtypes.idl
    wtypes.idl
    Registration failed:
    The packaged JavaBean is not located under the directory <jre_home>\axbridge\bin
    this is the error i get

  • How to use FilePermission class to change the file permission in Linux

    Hi all,
    I'm running in a issue related to changing the file permission under Linux environment. I'm using Suse 10.0 Linux and run jdk 1.5 java runtime.
    I want to create a file during execution time and change the permission of the same. I use File.createNewFile() API to create file. By default it does not have all the 3 permission (read,write,execute) for all the user ( user,owner,group). Through program I have to change the file permission ( equal to execute ,chmod 777 filename).I donot want to use runtime.exec() with chmod as the argument , since it creates a process to change the permission which may impact the performance. I want to try FilePermission class , by giving filename and permission as the argument. But it is not changing the permission . Could any one faced this problem ?
    If any body guides me, how to change the permission of the file under Linux using FilePermission class , it would be helpful.
    Thanks,
    Sankar

    How do I set the Umask prior to starting the program
    ? Could pls explain in steps.I don't think umask can help you. The mode mask prevents permission bits from being set when a file is created, but does not force any bits to be set. So if execute permission is not set explicitly when a file is created, umask will do nothing about it.
    But if you want more information about umask, see the man page for your shell script (sh, csh, etc.) or "man 2 umask".

Maybe you are looking for

  • Unordered list not printing correctly

    I created a heading 3 followed immediately by an unordered list. However, when I print the webpage out, I see the heading 3 fine and then the 1st bullet appears where it should but the text for the first bullet begins several lines down the page. All

  • Outlook sort by name - quicktype / searching by name using keyboard doesn't work right

    I'm not sure how to best explain this. In Outlook first you sort by name, and then you quickly type the first few letters of the person's name.  In Outlook 2010, this would cause it to go to the right person. For example if I type M-A-R it would go t

  • Regexp_like(source,pattern) to find and replace certain set of data

    Hi, Am having oracle 9i DB, and created functions for regexp_replace and regex_like from the following link http://phil-sqltips.blogspot.com/2009/06/regexpreplace-regexplike-for-oracle-9i.html Am having a table CREATE TABLE moto   MCC          NUMBER

  • How to measure the harmonic spectral

    Hey guys, I have a program tha measure the THD = Total Harmonic Distortion I measure the THD for each voltage and current. Now I want to measure the harmonic spectral from each current and voltage. Can you guys, help me with that? Have a VI that meas

  • TEST IMPORT phase error?during importing the patches

    Dear All, i was importing the HR patches SAPKE60023,SAPKE60024, SAPKE60025,SAPKE60026.In between error display PHASE TEST IMPORT ? MESSAGE: Error occourred in TEST_IMPORT. All these 4 SP was in the queue. SAPKE60023:0004RC SAPKE60024:0004RC SAPKE6002