LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 09-06-2006, 08:49 PM   #1
kofibull
LQ Newbie
 
Registered: Jun 2006
Posts: 13

Rep: Reputation: 0
Javax classpath question


I am trying to complile this program

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag extends TagSupport{
private String name = "World";

public void setName(String name){
this.name = name;
}

public int doEndTag(){
try{
pageContent.getOut().println("Hello " + name);
}
catch(IOException e){}//Ignore it
return EVAL_PAGE;
}
}

and I hav 5 errors to include below;
I can complile other java programs but this will not work.
HelloTag.java:3: package javax.servlet.jsp does not exist
import javax.servlet.jsp.*;
^
HelloTag.java:4: package javax.servlet.jsp.tagext does not exist
import javax.servlet.jsp.tagext.*;

What is the problem?
 
Old 09-06-2006, 08:55 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
It looks like the jar files containing your classes for import aren't on your classpath. Once you add them to your classpath that particular error should go away.

Also, please don't mark posts as urgent.
 
Old 09-06-2006, 11:07 PM   #3
kofibull
LQ Newbie
 
Registered: Jun 2006
Posts: 13

Original Poster
Rep: Reputation: 0
How do I get to my classpath? and what files do I need to add?

Last edited by kofibull; 09-06-2006 at 11:09 PM.
 
Old 09-06-2006, 11:55 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
I can only guess what files you'll need to add, but it looks like jsp-api.jar from the tomcat distribution. You can run javac with something like this - I'm not at my box at the moment, so this may need tweaking:
Code:
javac -classpath .:/path/to/jsp-api.jar yourfile.java
That runs the java compiler with a classpath made up of the current directory and the path (which you'll need to change for your system) to the jsp-api.jar. Have a look for jsp-api.jar in your tomcat installation directory under common/lib.
 
Old 09-07-2006, 12:09 AM   #5
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by kofibull
How do I get to my classpath?
Type echo $CLASSPATH at the shell to see what it is.
 
Old 09-07-2006, 11:31 AM   #6
kofibull
LQ Newbie
 
Registered: Jun 2006
Posts: 13

Original Poster
Rep: Reputation: 0
First thanks all for your help,
I typed echo $CLASSPATH and it did not do anything but print blank, and I tried the javac -classpath .: path/to/jar-api.jar .java but that still did not work.

I am able to compile my other java file but can if it contains javax.
 
Old 09-07-2006, 03:46 PM   #7
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Try the following code (please note I use pageContext not pageContent):
Code:
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag extends TagSupport {
  private String name = "World";

  public void setName(String name){
    this.name = name;
  }

  public int doEndTag(){
  try{
    pageContext.getOut().println("Hello " + name);
  }
  catch(IOException e)
  {}//Ignore it
  return EVAL_PAGE;
  }
}
The command line I used to compile it follows. Note that you will have to change the path to jsp-api.jar to whatever it is on your system:
Code:
javac -cp .:/usr/local/apache-tomcat/common/lib/jsp-api.jar HelloTag.java
 
Old 09-07-2006, 04:20 PM   #8
kofibull
LQ Newbie
 
Registered: Jun 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Hot digi-di, Steve u did it!!!
Thanks it works. I would like to clean it up were I could just type javac HelloTag.java. Could this be possible???

And also, do u know anything about custom tags, how to set it up.

<% taglib prefix="ora" uri="orataglib"" %>
I dont understand the uri, how it reference to the TLD file.
 
Old 09-07-2006, 11:55 PM   #9
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Sure - if you're using bash as your shell, add the following to .bash_profile in your home directory:
Code:
export CLASSPATH="${CLASSPATH}:.:/usr/local/apache-tomcat/common/lib/jsp-api.jar"
The uri value orataglib needs to match the one used in <taglib-uri> in the web.xml file. There's some info at http://jakarta.apache.org/taglibs/tutorial.html which may help. Also, have a look at http://java.sun.com/developer/techni...rss_utilities/ and http://www.orionserver.com/docs/tuto...taglibs/1.html - they may also be useful.
 
Old 09-08-2006, 12:03 PM   #10
kofibull
LQ Newbie
 
Registered: Jun 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks alot folks. Its done, classpath set and javac works so far.
But I have another problem, running graphics on my linux box.
From a remote PC if I try to run a graphics program I get this error
Exception in thread "main" java.lang.InternalError:
Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.Window.init(Window.java:231)
at java.awt.Window.<init>(Window.java:275)
at java.awt.Frame.<init>(Frame.java:401)
at javax.swing.JFrame.<init>(JFrame.java:198)
at FrameDemo.<init>(FrameDemo.java:6)
at ShowFrames.main(ShowFrames.java:5)

Any help with this issue??

Thanks.

Last edited by kofibull; 09-08-2006 at 02:51 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is import javax.swing.*; Dutchman Programming 4 06-16-2005 11:12 AM
getting javax.swing.* to appear student04 Programming 8 10-05-2004 11:06 AM
javax.swing doesn't work israel Programming 4 02-20-2004 12:59 AM
javax comm for suse linux kingshrimp Linux - Newbie 4 11-26-2003 10:19 AM


All times are GMT -5. The time now is 07:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration