Solved

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

Posted on 2006-11-16
4
1,179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now