Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem with embedded Tomcat and JSP compilation.

Reply
Thread Tools

Problem with embedded Tomcat and JSP compilation.

 
 
bcassand
Guest
Posts: n/a
 
      01-07-2004
Hi,

I wrote an application running an embedded Tomcat, based on the sample
code of the onJava site (an org.apache.catalina.startup.Embedded class
with manual configuration of things usually found in server.xml). I
use Tomcat 4.1.27 and Java 1.3.1.
Tomcat starts well, but is not able to compile JSP page. It displays
the following error:

<code>
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 4 in the jsp file: /index.jsp

Generated servlet error:
[javac] Compiling 1 source file


C:\test\tomcat\work\_\localhost\_\index_jsp.java:3 : package
javax.servlet does not exist
import javax.servlet.*;
^
....
</code>

and so on for all import statements. It looks like a classpath
problem, but I set the classpath with all the jar files in
tomcat/common/lib, in tomcat/server/lib, in tomcat/common/endorsed,
bootstrap.jar, the tools.jar of java. I set it in the environment
CLASSPATH variable and in the classpath of the jar of my application.
And the classpath is set, because if not, Tomcat cannot be launched.

So I probably missed something, but what?


Below you can see the code of my class and the code of the main
function:

<code of class EmbeddedTomcat>
import org.apache.catalina.Connector;
import org.apache.catalina.Context;
import org.apache.catalina.Deployer;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.logger.SystemOutLogger;
import org.apache.catalina.startup.Embedded;
import org.apache.catalina.Container;

public class EmbeddedTomcat
{
private String path = null;
private Embedded embedded = null;
private Host host = null;

public EmbeddedTomcat()
{
}

public void setPath( String path)
{
this.path = path;
}

public String getPath()
{
return( path);
}

public void startTomcat() throws Exception
{
Engine engine = null;
Context context = null;

System.setProperty( "catalina.home", getPath());
System.setProperty( "catalina.base", getPath());

embedded = new Embedded();
embedded.setDebug( 0);
embedded.setLogger( new SystemOutLogger());

engine = embedded.createEngine();
engine.setDefaultHost( "localhost");

host = embedded.createHost( "localhost", "webapps");
engine.addChild( host);

context = embedded.createContext( "", "c:/test/root");
host.addChild( context);

embedded.addEngine( engine);

Connector connector = embedded.createConnector( null, 8080,
false);
embedded.addConnector( connector);

embedded.start();
}

public void stopTomcat() throws Exception
{
embedded.stop();
}
}
</code>

<code in main function of my application>
EmbeddedTomcat tomcat = new EmbeddedTomcat();
tomcat.setPath( m_config.getString( "tomcat.home"));
try
{
tomcat.startTomcat();
}
catch( Exception error)
{
logger.fatal( "Unable to start tomcat.", error);
return;
}
</code>
 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      01-08-2004
Don't cross-post.

It's probably a javac/tools.jar problem.

Tomcat/Jasper uses javac.exe, which simply calls some classes in tools.jar.
Internally, Jasper uses the Ant <javac> task to invoke javac. If fork=true,
which it is by default, then it actually spins off another process, calls
javac.exe, and gets to tools.jar that way. If fork=false, then it can access
the classes directly.

Two solutions: add the directory that contains javac to your path, or set
fork=false in one of the xml config files (server.xml?).


"bcassand" <> wrote in message
news: om...
> Hi,
>
> I wrote an application running an embedded Tomcat, based on the sample
> code of the onJava site (an org.apache.catalina.startup.Embedded class
> with manual configuration of things usually found in server.xml). I
> use Tomcat 4.1.27 and Java 1.3.1.
> Tomcat starts well, but is not able to compile JSP page. It displays
> the following error:
>
> <code>
> org.apache.jasper.JasperException: Unable to compile class for JSP
>
> An error occurred at line: 4 in the jsp file: /index.jsp
>
> Generated servlet error:
> [javac] Compiling 1 source file
>
>
> C:\test\tomcat\work\_\localhost\_\index_jsp.java:3 : package
> javax.servlet does not exist
> import javax.servlet.*;
> ^
> ...
> </code>
>
> and so on for all import statements. It looks like a classpath
> problem, but I set the classpath with all the jar files in
> tomcat/common/lib, in tomcat/server/lib, in tomcat/common/endorsed,
> bootstrap.jar, the tools.jar of java. I set it in the environment
> CLASSPATH variable and in the classpath of the jar of my application.
> And the classpath is set, because if not, Tomcat cannot be launched.
>
> So I probably missed something, but what?
>
>
> Below you can see the code of my class and the code of the main
> function:
>
> <code of class EmbeddedTomcat>
> import org.apache.catalina.Connector;
> import org.apache.catalina.Context;
> import org.apache.catalina.Deployer;
> import org.apache.catalina.Engine;
> import org.apache.catalina.Host;
> import org.apache.catalina.logger.SystemOutLogger;
> import org.apache.catalina.startup.Embedded;
> import org.apache.catalina.Container;
>
> public class EmbeddedTomcat
> {
> private String path = null;
> private Embedded embedded = null;
> private Host host = null;
>
> public EmbeddedTomcat()
> {
> }
>
> public void setPath( String path)
> {
> this.path = path;
> }
>
> public String getPath()
> {
> return( path);
> }
>
> public void startTomcat() throws Exception
> {
> Engine engine = null;
> Context context = null;
>
> System.setProperty( "catalina.home", getPath());
> System.setProperty( "catalina.base", getPath());
>
> embedded = new Embedded();
> embedded.setDebug( 0);
> embedded.setLogger( new SystemOutLogger());
>
> engine = embedded.createEngine();
> engine.setDefaultHost( "localhost");
>
> host = embedded.createHost( "localhost", "webapps");
> engine.addChild( host);
>
> context = embedded.createContext( "", "c:/test/root");
> host.addChild( context);
>
> embedded.addEngine( engine);
>
> Connector connector = embedded.createConnector( null, 8080,
> false);
> embedded.addConnector( connector);
>
> embedded.start();
> }
>
> public void stopTomcat() throws Exception
> {
> embedded.stop();
> }
> }
> </code>
>
> <code in main function of my application>
> EmbeddedTomcat tomcat = new EmbeddedTomcat();
> tomcat.setPath( m_config.getString( "tomcat.home"));
> try
> {
> tomcat.startTomcat();
> }
> catch( Exception error)
> {
> logger.fatal( "Unable to start tomcat.", error);
> return;
> }
> </code>



 
Reply With Quote
 
 
 
 
bcassand
Guest
Posts: n/a
 
      01-08-2004
"Chris" <> wrote in message news:<3ffcc93a$0$6771$>...
> Don't cross-post.


Sorry for the cross-posting.

>
> It's probably a javac/tools.jar problem.
>
> Tomcat/Jasper uses javac.exe, which simply calls some classes in tools.jar.
> Internally, Jasper uses the Ant <javac> task to invoke javac. If fork=true,
> which it is by default, then it actually spins off another process, calls
> javac.exe, and gets to tools.jar that way. If fork=false, then it can access
> the classes directly.
>
> Two solutions: add the directory that contains javac to your path, or set
> fork=false in one of the xml config files (server.xml?).


fork=false was already set in the web.xml file of the tomcat/conf
directory, for the servlet "jsp". Adding the directory of javac in the
path changes nothing
Setting the fork to true only changes the display of the message, but
the error is the same.

>
>
> "bcassand" <> wrote in message
> news: om...
> > Hi,
> >
> > I wrote an application running an embedded Tomcat, based on the sample
> > code of the onJava site (an org.apache.catalina.startup.Embedded class
> > with manual configuration of things usually found in server.xml). I
> > use Tomcat 4.1.27 and Java 1.3.1.
> > Tomcat starts well, but is not able to compile JSP page. It displays
> > the following error:
> >
> > <code>
> > org.apache.jasper.JasperException: Unable to compile class for JSP
> >
> > An error occurred at line: 4 in the jsp file: /index.jsp
> >
> > Generated servlet error:
> > [javac] Compiling 1 source file
> >
> >
> > C:\test\tomcat\work\_\localhost\_\index_jsp.java:3 : package
> > javax.servlet does not exist
> > import javax.servlet.*;
> > ^
> > ...
> > </code>
> >
> > and so on for all import statements. It looks like a classpath
> > problem, but I set the classpath with all the jar files in
> > tomcat/common/lib, in tomcat/server/lib, in tomcat/common/endorsed,
> > bootstrap.jar, the tools.jar of java. I set it in the environment
> > CLASSPATH variable and in the classpath of the jar of my application.
> > And the classpath is set, because if not, Tomcat cannot be launched.
> >
> > So I probably missed something, but what?
> >
> >
> > Below you can see the code of my class and the code of the main
> > function:
> >
> > <code of class EmbeddedTomcat>
> > import org.apache.catalina.Connector;
> > import org.apache.catalina.Context;
> > import org.apache.catalina.Deployer;
> > import org.apache.catalina.Engine;
> > import org.apache.catalina.Host;
> > import org.apache.catalina.logger.SystemOutLogger;
> > import org.apache.catalina.startup.Embedded;
> > import org.apache.catalina.Container;
> >
> > public class EmbeddedTomcat
> > {
> > private String path = null;
> > private Embedded embedded = null;
> > private Host host = null;
> >
> > public EmbeddedTomcat()
> > {
> > }
> >
> > public void setPath( String path)
> > {
> > this.path = path;
> > }
> >
> > public String getPath()
> > {
> > return( path);
> > }
> >
> > public void startTomcat() throws Exception
> > {
> > Engine engine = null;
> > Context context = null;
> >
> > System.setProperty( "catalina.home", getPath());
> > System.setProperty( "catalina.base", getPath());
> >
> > embedded = new Embedded();
> > embedded.setDebug( 0);
> > embedded.setLogger( new SystemOutLogger());
> >
> > engine = embedded.createEngine();
> > engine.setDefaultHost( "localhost");
> >
> > host = embedded.createHost( "localhost", "webapps");
> > engine.addChild( host);
> >
> > context = embedded.createContext( "", "c:/test/root");
> > host.addChild( context);
> >
> > embedded.addEngine( engine);
> >
> > Connector connector = embedded.createConnector( null, 8080,
> > false);
> > embedded.addConnector( connector);
> >
> > embedded.start();
> > }
> >
> > public void stopTomcat() throws Exception
> > {
> > embedded.stop();
> > }
> > }
> > </code>
> >
> > <code in main function of my application>
> > EmbeddedTomcat tomcat = new EmbeddedTomcat();
> > tomcat.setPath( m_config.getString( "tomcat.home"));
> > try
> > {
> > tomcat.startTomcat();
> > }
> > catch( Exception error)
> > {
> > logger.fatal( "Unable to start tomcat.", error);
> > return;
> > }
> > </code>

 
Reply With Quote
 
bcassand
Guest
Posts: n/a
 
      01-08-2004
"Chris" <> wrote in message news:<3ffcc93a$0$6771$>...
> Don't cross-post.


Sorry for the cross-posting.

>
> It's probably a javac/tools.jar problem.
>
> Tomcat/Jasper uses javac.exe, which simply calls some classes in tools.jar.
> Internally, Jasper uses the Ant <javac> task to invoke javac. If fork=true,
> which it is by default, then it actually spins off another process, calls
> javac.exe, and gets to tools.jar that way. If fork=false, then it can access
> the classes directly.
>
> Two solutions: add the directory that contains javac to your path, or set
> fork=false in one of the xml config files (server.xml?).


fork=false was already set in the web.xml file of the tomcat/conf
directory, for the servlet "jsp". Adding the directory of javac in the
path changes nothing
Setting the fork to true only changes the display of the message, but
the error is the same.

>
>
> "bcassand" <> wrote in message
> news: om...
> > Hi,
> >
> > I wrote an application running an embedded Tomcat, based on the sample
> > code of the onJava site (an org.apache.catalina.startup.Embedded class
> > with manual configuration of things usually found in server.xml). I
> > use Tomcat 4.1.27 and Java 1.3.1.
> > Tomcat starts well, but is not able to compile JSP page. It displays
> > the following error:
> >
> > <code>
> > org.apache.jasper.JasperException: Unable to compile class for JSP
> >
> > An error occurred at line: 4 in the jsp file: /index.jsp
> >
> > Generated servlet error:
> > [javac] Compiling 1 source file
> >
> >
> > C:\test\tomcat\work\_\localhost\_\index_jsp.java:3 : package
> > javax.servlet does not exist
> > import javax.servlet.*;
> > ^
> > ...
> > </code>
> >
> > and so on for all import statements. It looks like a classpath
> > problem, but I set the classpath with all the jar files in
> > tomcat/common/lib, in tomcat/server/lib, in tomcat/common/endorsed,
> > bootstrap.jar, the tools.jar of java. I set it in the environment
> > CLASSPATH variable and in the classpath of the jar of my application.
> > And the classpath is set, because if not, Tomcat cannot be launched.
> >
> > So I probably missed something, but what?
> >
> >
> > Below you can see the code of my class and the code of the main
> > function:
> >
> > <code of class EmbeddedTomcat>
> > import org.apache.catalina.Connector;
> > import org.apache.catalina.Context;
> > import org.apache.catalina.Deployer;
> > import org.apache.catalina.Engine;
> > import org.apache.catalina.Host;
> > import org.apache.catalina.logger.SystemOutLogger;
> > import org.apache.catalina.startup.Embedded;
> > import org.apache.catalina.Container;
> >
> > public class EmbeddedTomcat
> > {
> > private String path = null;
> > private Embedded embedded = null;
> > private Host host = null;
> >
> > public EmbeddedTomcat()
> > {
> > }
> >
> > public void setPath( String path)
> > {
> > this.path = path;
> > }
> >
> > public String getPath()
> > {
> > return( path);
> > }
> >
> > public void startTomcat() throws Exception
> > {
> > Engine engine = null;
> > Context context = null;
> >
> > System.setProperty( "catalina.home", getPath());
> > System.setProperty( "catalina.base", getPath());
> >
> > embedded = new Embedded();
> > embedded.setDebug( 0);
> > embedded.setLogger( new SystemOutLogger());
> >
> > engine = embedded.createEngine();
> > engine.setDefaultHost( "localhost");
> >
> > host = embedded.createHost( "localhost", "webapps");
> > engine.addChild( host);
> >
> > context = embedded.createContext( "", "c:/test/root");
> > host.addChild( context);
> >
> > embedded.addEngine( engine);
> >
> > Connector connector = embedded.createConnector( null, 8080,
> > false);
> > embedded.addConnector( connector);
> >
> > embedded.start();
> > }
> >
> > public void stopTomcat() throws Exception
> > {
> > embedded.stop();
> > }
> > }
> > </code>
> >
> > <code in main function of my application>
> > EmbeddedTomcat tomcat = new EmbeddedTomcat();
> > tomcat.setPath( m_config.getString( "tomcat.home"));
> > try
> > {
> > tomcat.startTomcat();
> > }
> > catch( Exception error)
> > {
> > logger.fatal( "Unable to start tomcat.", error);
> > return;
> > }
> > </code>

 
Reply With Quote
 
Martin Moessner
Guest
Posts: n/a
 
      01-12-2004
check if "JDK_TOOLS/lib/tools.jar" is in the CLASSPATH and also
"TOMCAT_HOME/common/lib/servlet.jar"

hope this helps

martin

"bcassand" <> schrieb im Newsbeitrag
news: om...
> Hi,
>
> I wrote an application running an embedded Tomcat, based on the sample
> code of the onJava site (an org.apache.catalina.startup.Embedded class
> with manual configuration of things usually found in server.xml). I
> use Tomcat 4.1.27 and Java 1.3.1.
> Tomcat starts well, but is not able to compile JSP page. It displays
> the following error:
>
> <code>
> org.apache.jasper.JasperException: Unable to compile class for JSP
>
> An error occurred at line: 4 in the jsp file: /index.jsp
>
> Generated servlet error:
> [javac] Compiling 1 source file
>
>
> C:\test\tomcat\work\_\localhost\_\index_jsp.java:3 : package
> javax.servlet does not exist
> import javax.servlet.*;
> ^
> ...
> </code>
>
> and so on for all import statements. It looks like a classpath
> problem, but I set the classpath with all the jar files in
> tomcat/common/lib, in tomcat/server/lib, in tomcat/common/endorsed,
> bootstrap.jar, the tools.jar of java. I set it in the environment
> CLASSPATH variable and in the classpath of the jar of my application.
> And the classpath is set, because if not, Tomcat cannot be launched.
>
> So I probably missed something, but what?
>
>
> Below you can see the code of my class and the code of the main
> function:
>
> <code of class EmbeddedTomcat>
> import org.apache.catalina.Connector;
> import org.apache.catalina.Context;
> import org.apache.catalina.Deployer;
> import org.apache.catalina.Engine;
> import org.apache.catalina.Host;
> import org.apache.catalina.logger.SystemOutLogger;
> import org.apache.catalina.startup.Embedded;
> import org.apache.catalina.Container;
>
> public class EmbeddedTomcat
> {
> private String path = null;
> private Embedded embedded = null;
> private Host host = null;
>
> public EmbeddedTomcat()
> {
> }
>
> public void setPath( String path)
> {
> this.path = path;
> }
>
> public String getPath()
> {
> return( path);
> }
>
> public void startTomcat() throws Exception
> {
> Engine engine = null;
> Context context = null;
>
> System.setProperty( "catalina.home", getPath());
> System.setProperty( "catalina.base", getPath());
>
> embedded = new Embedded();
> embedded.setDebug( 0);
> embedded.setLogger( new SystemOutLogger());
>
> engine = embedded.createEngine();
> engine.setDefaultHost( "localhost");
>
> host = embedded.createHost( "localhost", "webapps");
> engine.addChild( host);
>
> context = embedded.createContext( "", "c:/test/root");
> host.addChild( context);
>
> embedded.addEngine( engine);
>
> Connector connector = embedded.createConnector( null, 8080,
> false);
> embedded.addConnector( connector);
>
> embedded.start();
> }
>
> public void stopTomcat() throws Exception
> {
> embedded.stop();
> }
> }
> </code>
>
> <code in main function of my application>
> EmbeddedTomcat tomcat = new EmbeddedTomcat();
> tomcat.setPath( m_config.getString( "tomcat.home"));
> try
> {
> tomcat.startTomcat();
> }
> catch( Exception error)
> {
> logger.fatal( "Unable to start tomcat.", error);
> return;
> }
> </code>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP precompilation problem with Tomcat 5.0.26 embedded in JBoss 3.2.5 skidvd Java 5 12-12-2008 04:25 PM
Tomcat not updating index.jsp to my jsp file! tiewknvc9 Java 4 05-12-2007 12:03 AM
ClassLoader problem in embedded tomcat sabine Java 0 10-11-2006 07:14 PM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
How to display images embedded in e-mail as embedded, not attachments Jim Firefox 4 12-11-2004 05:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57