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
Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unit test DAO layer 1 139
Best practices to work on a spring MVC project 1 126
JSONSerializer.toJSON in JSP generating error 8 81
countXY challenge 28 160
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
Read about why it is more lucrative for an IT company to participate in government projects.
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 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