Solved

How to add .JAR files (or API) in JSP?

Posted on 2006-11-16
4
1,182 Views
Last Modified: 2012-06-21
Hi,

So I have a custom java API from a search engine company in the form of .JAR files (e.g. multicolumn.jar, util.jar).  I'm using Windows XP and tomcat 5.5.

The following is my JSP architecture:
1. c:\tomcat\webapps\mysite\index.jsp
2. c:\tomcat\webapps\mysite\WEB-INF\web.xml
3. c:\tomcat\webapps\mysite\WEB-INF\lib\

The example of the API usage is this:

c:\> java -classpath multicolumn.jar;util.jar Example1

Where Example 1 is a separate java file.

My Questions:
1. Where should I put the .JAR in JSP architecture?
2. Is the searchEngine.jar = Java API?
3. How can I call the API in JSP? Example please ...

Thanks!

0
Comment
Question by:SWB-Consulting
  • 2
4 Comments
 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 300 total points
ID: 17958749
My Questions:
1. Where should I put the .JAR in JSP architecture?
Inside \WEB-INF\lib\

2. Is the searchEngine.jar = Java API?
Jar file is a packaged collection of java files. So searchEngine.jar is a collection of java files
Your java files in searchEngine.jar use java API. In other words the java programs were written using java classes and methods (known as java API)

3. How can I call the API in JSP? Example please ...
You would have a front-end user interface. This front-end would call  the java files in the jar.

Go through this:
http://tomcat.apache.org/tomcat-4.1-doc/appdev/deployment.html 

0
 
LVL 15

Accepted Solution

by:
bpmurray earned 200 total points
ID: 17958960
1. Put your jar files into WEB-INF\lib
2. The searchengine.jar file is sortof the same as your API. "jar" = "Java ARchive" - it's a collection of compiled classes and other helper files. It could contain even some extra JSP files or JSP fragments, and graphics or javascripts. It's like a zip file and even uses the same compression techniques, so you can look at a jar file in WinZip.
3. You've shown it as "java -jar whatever" which indicates that it contains a main() method. If the main method is purely to allow it to run as standalone, you can easily call the methods. Let's assume that the classes you're interested in are called something like "com.searchengine.pack.foo", and you're trying to display the contents of a string that's returned by a call to getNameValue(). Your JSP would then contain something like:

   First you need to import the classes. This can be done in a couple of ways, but the easiest is:
        <%@page import="com.searchengine.pack.foo"%>
 
   Next you need to display the value you get back:
        <p>Here is the value I got: <%=getNameValue();%></p>

Since you didn't give much information, this is about as accurate as I can get.
0
 

Author Comment

by:SWB-Consulting
ID: 17959414
I put this at the start of the page:

<%@page import="com.syslore.multicolumn.AliasList"%>

But it generates error message that says:

[error Message]
org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:
Only a type can be imported. com.syslore.multicolumn.AliasList resolves to a package
[/error Message]

Why is this happening?
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17964309
If you look at your jar, you'll see that there are a bunch of classes in the package. You have to import the classes, not the package. If you want to include all the classes, use "*" as in:
    <%@page import="com.syslore.multicolumn.AliasList.*"%>
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the biggest threats facing all high-value targets are APT's.  These threats include sophisticated tactics that "often starts with mapping human organization and collecting intelligence on employees, who are nowadays a weaker link than network…
An article on effective troubleshooting
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question