Page 1 of 1

Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 01 Aug 2014, 15:43
by Lapo
This is a quick guide for those using SFS2X 2.9 using JSP.

The problem
The embedded Jetty 9 http server requires the full JDK to run JSP, because it's a requirement for Jasper, the JSP compiler.
SmartFoxServer 2X comes with an embedded JRE 1.7.x which is missing some of the components of the JDK (which takes 150+MB alone)

The Solution
You can install your own JDK.
If you run MacOSX you should already have installed it. Otherwise you can download the JDK from the Oracle website (Windows) or use the software management tools in your Linux distribution to get it installer.You will need the JDK 7 or higher.

For example if you are running an Ubuntu Linux box you will be able to install the JDK with a few commands in your terminal:

Code: Select all

sudo apt-get update
sudo apt-get install openjdk-7-jdk


Edit a couple of files and you're good to go
1) Take note of the JDK version. Let' say it is 1.7.0_65
- Go to the SFS2X/lib/jetty/modules/npn/
- See if a file called npn-1.7.0_65 exists (or whatever your JDK version is)
- If it doesn't duplicate an existing one an rename it to npn-1.7.0_65 (or whatever your JDK version is)

2) Move back to the SFS2X/ folder
- Edit the sfs2x-service file
- Uncomment the #INSTALL4J_JAVA_HOME_OVERRIDE line by removing the # (hash) sign
- Set it to the path of your installed JDK. In the case of our test machine (Ubuntu 14) it is

Code: Select all

INSTALL4J_JAVA_HOME_OVERRIDE="/usr/lib/jvm/java-7-openjdk-amd64/"

- Save and close

Start and Test
- Start the server
- Point your browser to http://localhost:8080/HelloServlet/

You should see the demo page loading and displaying correctly.

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 14 Aug 2014, 17:04
by AndyMartin458
Can I disable JSP altogether? I'm trying to use Java 8 on Windows. It didn't work when I tried installing the newest version of Jetty on my own.

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 15 Aug 2014, 08:07
by Lapo
I don't understand your question very well.
In this thread we have just said that JSP doesn't work out of the box. So it's not "active". Plus if you don't use JSP pages it will never be used anyways.

It's not clear what the problem could be with Java 8.
If you're compiling Java 8 code then you will need to replace the JRE in SFS2X as it runs by default a JRE 7.

However you can still program with Java 8 and set the "compliance level" to Java 7 without any changes to SFS2X.

Hope it helps

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 03 Jan 2015, 08:05
by brownjay
Please help me, my OS is Windows 7

Sfs2x-service can be modified in linux ,but can't in windows

which file should be modified ?

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 03 Jan 2015, 09:23
by Lapo
Good point, in Windows the sfs2x-service is a binary executable so the process is a bit different.

In your main SmartFoxServer2X/ installation folder you will find a .install4j/ directory.
Inside you will find a file called --> pref_jre.cfg
Edit the file, replace the path to your JDK, and save.

Hope it helps

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 03 Jan 2015, 10:09
by brownjay
Hi Lapo , thank you reply so soon,

but i already edit the file but seem can't open jsp page

thows the same exception.

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 03 Jan 2015, 11:10
by Lapo
Sounds like an entirely different problem.

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 04 Jan 2015, 01:36
by brownjay
Sorry could be not more information say this.

if i use SmartFoxServer_2X\SFS2X\sfs2x.bat

Code: Select all

source :
      @..\jre\bin\java.exe -cp "./;lib/*;lib/jetty/lib/*;extensions/__lib__/*" -Dfile.encoding=UTF-8 com.smartfoxserver.v2.Main %1 %2

change to my real JDB install path like this.

Code: Select all

      @ C:\Progra~1\Java\jdk1.7.0_51\bin\java.exe "./;lib/*;lib/jetty/lib/*;extensions/__lib__/*" -Dfile.encoding=UTF-8 com.smartfoxserver.v2.Main %1 %2

and then execute this sfs2x.bat , it 's can work.

i mean if i alter pre_jre.cfg and then execute \SFS2X\sfs2x-standalone.exe or \SFS2X\sfs2x-service.exe two way to start up smartfox server.

jdk path could use pre_jre.cfg file's path or i must be rebuild execution file ??

Re: Guide: SFS2X 2.9 + JSP/Jasper + JDK

Posted: 05 Jan 2015, 10:12
by Lapo
sfs2x-service.exe is not the executable that you need to run manually.
The executable is used by Windows if you are running SFS2X as a service.

If you are running the server manually, you can use sfs2x-standalone.exe. This will work in conjunction with the JRE path specified in the pre_jre.cfg file that I have mentioned in my previous post.

I tested under Windows 8, using Oracle JDK 8 and it works fine.

Thanks