Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

20 Experts available now in Live!

Get 1:1 Help Now