• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

importing custom class/method into servlet; servlet and finding classpath?

 
eileen keeney
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a custom class.
I put the class in a package.
I put the path to the package in my CLASSPATH

The code was able to locate the package on compile. (Or at least it does not error).

However, if did error (on compile) if I used the actual classname, and not just the package name, in the import statement.

import packageName.*
worked (well at least it compiled without error, but the class could not be found at runtime)

import packageName.className.*
did not work

There is one class (className) and one method below the class.

Command is constructed
returnValue = className.methodName(arg1, arg2);


I believe my package is created correctly (but since this is the first time I have created a package, maybe I did this incorrectly).
I used
javac -d . classfile.java
and it created the directory for my package (based on the package name I used in the .java file), and put the compiled className.class file within it.

Does the servlet also need to know the classpath, even if it was known at compile time, when the class was compiled?
Is there a way to avoid this need?

How do I get the process, that is running the servlet, to know the classpath.
Even if I start tomcat, as the user that I compile with, it does not execute the .profile, where I have the classpath set.
Is this a configuration somewhere, I can set?

(I am new to java, and servlets)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat knows nothing about the classpath. You must place the class files in the appropriate location within the web application. One of:
  • class files in the hierarchy under WEB-INF/classes
  • a jar file in WEB-INF/lib


  •  
    eileen keeney
    Ranch Hand
    Posts: 51
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks,
    That worked.
     
    eileen keeney
    Ranch Hand
    Posts: 51
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ok, it did work, now I can not get any package to work, even when outside of a servlet call.

    No matter what I do, even taking it down to the bare bones of functionality, I get an error.

    file does not contain class
    Please remove or make sure it appears in the correct subdirectory of the classpath.

    The class is in the file, and even shows up in the directory, that is named for the package.




     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic