Service Desk Practitioners Forum

JSP Coders - easy 10 points

Go to solution
Elias Abboud
Acclaimed Contributor.

JSP Coders - easy 10 points

Hello JSP coders,

I have written a new function into Service Pages JSP code. I want to make that function available to my customers but I don't want them to have the source code.

Currently I have written the code for this directly in the corresponding JSP file of SD service pages interface.

Is there a way I could compile this into some format and still use it from inside the JSP file? Can someone give me step by step instructions? I am a beginner in this field :)

I've heard about making it a jar file, would this be enough and how do I do it?

Thanks in advance
If you can't solve it, post it :)
Gyula Matics_1
Acclaimed Contributor.

Re: JSP Coders - easy 10 points

Well, with java, there is no such thing as hiding the source code. You can create a jar and hide your code in it. But a jar is just a zip file that contains compiled java classes. But java is byte code which means that it is more or less possible to decompile the classes and recreate the source... There are several decompilers out there. There are also obfuscators that make decompiling harder or at least the decompiled source code harder to read.

If you still want to create a jar, first you need to separate parts of your code into standalone java classes, which are put into their own .java files. Then compile the class into .class files, then zip them and rename the zip to jar. Instead of doing it by hand, you can use a Java IDE like Eclipse or NetBeans to automatically create the jars.
Elias Abboud
Acclaimed Contributor.

Re: JSP Coders - easy 10 points

Thanks a lot Gyula,

I still want to create the jar file. I have downloaded and installed eclipse.

Maybe I was not clear in my first post. The steps I need to know are:

1. I have a function that accepts parameters and returns a string value.

2. How should I put that function in a JAR file? In which folder should I put this Jar file?

3. How do I refenrence the jar file from inside the JSP code? and How can I call my function?

Thanks in advance

PS: I will assign 10 points to your answer afterwards
If you can't solve it, post it :)
Gyula Matics_1
Acclaimed Contributor.

Re: JSP Coders - easy 10 points

lets see.

If you have eclipse up and running, first you need to create a project from the file/new/new project. Give it a name.

I guess your function is using web-api calls. Then you have to add web-api.jar to the library path. Project/properties/Java build path. On the libraries tab, choose add external jar, and locate the web-api..jar.

Then create a new class. file/new/other/class
Give it a name (test), and a package name (like com.elias.servicedesk). It will create and a class in its own .java file.

Copy your function into this new class. Save it.

2. To create the jar. File/export/JAR file. Select com.elias.servicedesk from the resource list. Give the jar a name (full path, otherwise who nows where it will end up) , and click finish.

Copy that new jar next to wep-api.jar in the WEB-INF/lib folder.

3. to reference the classes in the jar, you have to add an import statement to the top of your jsp. Just like the others already there.
<%@ page import="com.elias.servicedesk.test" %>

now, to call that function, create a new instance of this class, and call it.
test x = new test();
String y = x.yourfunction()

This was really just an overview.
I think it is worth spending some time to learn about java. There is a book online at Sun:
and there are several other, just search for them.
Elias Abboud
Acclaimed Contributor.

Re: JSP Coders - easy 10 points


I have followed your instructions but it seems that JSP import is failing. It seems that it cannot find the jar file

Something is still missing, here is the error I got:

Generated servlet error:
cannot resolve symbol
symbol : class myclass
location: package sd

Please help
If you can't solve it, post it :)
Gyula Matics_1
Acclaimed Contributor.

Re: JSP Coders - easy 10 points

Ganesha Sridhar
Outstanding Contributor.

Re: JSP Coders - easy 10 points


The class (jar or zip) can be imported from jsp/servlet. The class file should be in the classpath. It can be done :

1. Set the classpath in the "" file of "/opt/OV/sd/servicepages/bin". In Windows box the file name "setclasspath.bat"
# Set standard CLASSPATH

2. The jar or zip files in the /opt/OV/sd/servicepages/webapps/sd-sp45/WEB-INF/lib folders are automatically added into classpath.

We have updated file also copied the same into /opt/OV/sd/servicepages/webapps/sd-sp45/WEB-INF/lib folder.

Ganesha Sridhara