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.
1. 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()
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 "setclasspath.sh" file of "/opt/OV/sd/servicepages/bin". In Windows box the file name "setclasspath.bat" Example: # Set standard CLASSPATH CLASSPATH="$JAVA_HOME"/lib/tools.jar:"$JDBC_HOME"/lib/jdbc/classes12.jar
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 setclasspath.sh file also copied the same into /opt/OV/sd/servicepages/webapps/sd-sp45/WEB-INF/lib folder.