Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-16
4
Medium Priority
?
1,203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 1200 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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

604 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