• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile Question/Error

 
DC Gailunas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All-
I am extremly new to java, though I have been programming in VB and Delphi for about 8 years. Now that the disclaimer is out of the way, here is the problem I am having:
When I compile the code below I recieve the following errors,
CODE:
package stPkg;
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ApplicationConfig;
import org.apache.struts.action.ActionServlet;
public class stPlugin implements PlugIn {
public static final String PROPERTIES = "PROPERTIES";
public stPlugin() {
}
public void init(ActionServlet servlet,
ApplicationConfig applicationConfig)
throws javax.servlet.ServletException {
System.err.println("---->The Plugin is starting<----");
Properties properties = new Properties();
try {
File file =
new File("C:/tomcat/webapps/st/WEB-INF/props.txt");
FileInputStream fis =
new FileInputStream(file);
properties.load(fis);
ServletContext context = servlet.getServletContext();
context.setAttribute(PROPERTIES, properties);
Properties rProperties = (Properties)context.getAttribute(PROPERTIES);
System.err.println("---->Prop: LDAP " + rProperties.getProperty("LDAP"));
}
catch (FileNotFoundException fnfe) {
throw new ServletException(fnfe.getMessage());
}
catch (IOException ioe) {
throw new ServletException(ioe.getMessage());
}
}
public void destroy() {
System.err.println("---->The Plugin is stopping<----");
}
}
ERROR:
class stPlugin is public, should be declared in a file named stPlugin.java
public class stPlugin implements PlugIn {
^
package javax.servlet does not exist
import javax.servlet.ServletException;
^
package javax.servlet does not exist
import javax.servlet.ServletContext;
^
package org.apache.struts.action does not exist
import org.apache.struts.action.PlugIn;
^
package org.apache.struts.config does not exist
import org.apache.struts.config.ApplicationConfig;
^
package org.apache.struts.action does not exist
import org.apache.struts.action.ActionServlet;
^
cannot resolve symbol
symbol : class PlugIn
location: class stPkg.stPlugin
public class stPlugin implements PlugIn {
^
cannot resolve symbol
symbol : class ActionServlet
location: class stPkg.stPlugin
public void init(ActionServlet servlet,
^
cannot resolve symbol
symbol : class ApplicationConfig
location: class stPkg.stPlugin
ApplicationConfig applicationConfig)
^
package javax.servlet does not exist
throws javax.servlet.ServletException {
^
cannot resolve symbol
symbol : class ServletContext
location: class stPkg.stPlugin
ServletContext context = servlet.getServletContext();
^
cannot resolve symbol
symbol : class ServletException
location: class stPkg.stPlugin
throw new ServletException(fnfe.getMessage());
^
cannot resolve symbol
symbol : class ServletException
location: class stPkg.stPlugin
throw new ServletException(ioe.getMessage());

This is being used with STRUTS and Tomcat. Any thoughts on how to correct this?
Thanks in advance for any assistance.
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This error should be pretty straightforward:
class stPlugin is public, should be declared in a file named stPlugin.java

Your public class name has to match your file name.
The other problems are classpath related issues. You have to create a classpath environment variable or pass the classpath in to the compiler. The classpath will contain the directory or "JAR" files (zip files with the extention zip or jar) where the stated packages can be found. For example, that javax.servlet package can be found in in <TOMCAT HOME>/common/lib/servlet.jar . Classpath issues are common for new Java programmers. Search the forum and you will find more on them.
[ October 29, 2003: Message edited by: Joe Ess ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Welcome to JavaRanch!
I see three things going on.
One is the first message about the public class: you're only allowed to have one public class per source file. Move each public class to its own file.
Second, you need to have the file "servlet.jar" on your CLASSPATH when you compile your code; it contains the definitions of all the servlet-related classes. This file is in TOMCAT/common/lib/servlet.jar .
Third, you need the Struts jar files on your CLASSPATH, too. As I've never used Struts, I don't know what the file is called.
If you're currently compiling using
javac <something>
then you should say
javac -classpath .;<TOMCAT>/common/lib/servlet.jar;<STRUTS>/<whatever.jar> <something>
That's obviously a lot to type, which is why most people will use a build tool like Jakarta Ant to do their builds.
I'm sure you'll have more questions, because I haven't given all the details here. Ask away!
 
DC Gailunas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All-
Thanks for the assistance, I thought it would be someting simple like that. I will make the modifications mentioned.
Thanks again.
[ October 29, 2003: Message edited by: DC Gailunas ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic