• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 67650
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 56
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks,
    That worked.
     
    eileen keeney
    Ranch Hand
    Posts: 56
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.




    reply
      Bookmark Topic Watch Topic
    • New Topic