GUIDE: Using Java 8 with SFS2X
GUIDE: Using Java 8 with SFS2X
SmartFoxServer 2.10 (and higher) supports Java 8 but it is still provided with a Java 7 runtime.
For those who are interested in coding server-side Extension in Java 8 you can follow these simple steps to replace the JRE in your SFS2X installation.
1) Download the JRE 8 from Oracle's website:
http://www.oracle.com/technetwork/java/ ... 33155.html
Making sure to match the architecture of your OS (32 vs 64 bit)
2) Uncompress the download and replace the new jre/ folder under the root of your SmartFoxServer 2X installation. This will overwrite the previous JRE.
(This step is not required for MacOS X)
3) One last step is required for the embedded Jetty server:
Open the SFS2X/lib/jetty/modules/npn/ folder and duplicate one of the files in the folder. Example: duplicate file "npn-1.7.0_45.mod" and rename it so that the version number matches the new JRE.
Example if you have downloaded JRE 1.8.0_25 the file will be renames as --> "npn-1.8.0_25.mod"
You're ready to run SFS2X with Java 8
For those who are interested in coding server-side Extension in Java 8 you can follow these simple steps to replace the JRE in your SFS2X installation.
1) Download the JRE 8 from Oracle's website:
http://www.oracle.com/technetwork/java/ ... 33155.html
Making sure to match the architecture of your OS (32 vs 64 bit)
2) Uncompress the download and replace the new jre/ folder under the root of your SmartFoxServer 2X installation. This will overwrite the previous JRE.
(This step is not required for MacOS X)
3) One last step is required for the embedded Jetty server:
Open the SFS2X/lib/jetty/modules/npn/ folder and duplicate one of the files in the folder. Example: duplicate file "npn-1.7.0_45.mod" and rename it so that the version number matches the new JRE.
Example if you have downloaded JRE 1.8.0_25 the file will be renames as --> "npn-1.8.0_25.mod"
You're ready to run SFS2X with Java 8
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: GUIDE: Using Java 8 with SFS2X
I am running SFS on Mac and I can't find a jre folder anywhere...
I had no problem finding it in the Linux installation though.
I had no problem finding it in the Linux installation though.
Re: GUIDE: Using Java 8 with SFS2X
You're right, the Mac is an exception because it's the only OS that comes with a pre-installed JDK.
In order to run SFS2X with Java 8 under OSX you just need to install the JDK8 on your Mac. You can skip step #2.
I've added a note in the main post.
Hope it helps
In order to run SFS2X with Java 8 under OSX you just need to install the JDK8 on your Mac. You can skip step #2.
I've added a note in the main post.
Hope it helps
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: GUIDE: Using Java 8 with SFS2X
Is there a way to check the Java version that SFS is using?
Edit: somehow it fixed itself! Not exactly sure what I did...
Commenting on Java 8 though, the feature I think is the most important is the new Compute method from the lambda calculus addition of Map interface. It allows me to modify ConcurrentHashMap without having to worry about locking the data structure, which is crucial to multithreaded environment like SFS!
Re: GUIDE: Using Java 8 with SFS2X
Actually the ConcurrentHashMap already handles concurrency even without Java 8.
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: GUIDE: Using Java 8 with SFS2X
Yes, but it is only concurrent for read and write operations. I cannot, for example, read a value, increment it and write it back atomically.
However, with Java 8, compute method is guaranteed to run an entire function atomically.
However, with Java 8, compute method is guaranteed to run an entire function atomically.
Re: GUIDE: Using Java 8 with SFS2X
Flying_Banana wrote:Yes, but it is only concurrent for read and write operations. I cannot, for example, read a value, increment it and write it back atomically.
However, with Java 8, compute method is guaranteed to run an entire function atomically.
Ah yes, indeed.
Out of curiosity is it really guaranteed to run atomically? The official doc doesn't seem to say that.
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: GUIDE: Using Java 8 with SFS2X
Yep! It isn't actually stated in the updated interface, but in the compute function under ConcurrentHashMap it says:
The benefit is immense.
Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). The entire method invocation is performed atomically. Some attempted update operations on this map by other threads may be blocked while computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this Map.
The benefit is immense.
- Flying_Banana
- Posts: 42
- Joined: 04 May 2014, 07:03
Re: GUIDE: Using Java 8 with SFS2X
I'm still having some troubles. It seems like occasionally Smart Fox will dislike Java 8 and use Java 7 on restart.
So: working Java 8 extension running...I modify the JAR, replace it, restart server, then found out server didn't start. Check log, it says class loader error: Unsupported major.minor version 52.0. This is the signature error that indicates Java 8 code is being loaded by JRE 7. But I was running on Java 8 extension code before restart!
returns Java 8. This is quite annoying...
(...and now it's working again, after deleting, recompiling, cleaning projects several times)
So: working Java 8 extension running...I modify the JAR, replace it, restart server, then found out server didn't start. Check log, it says class loader error: Unsupported major.minor version 52.0. This is the signature error that indicates Java 8 code is being loaded by JRE 7. But I was running on Java 8 extension code before restart!
Code: Select all
java -version
returns Java 8. This is quite annoying...
(...and now it's working again, after deleting, recompiling, cleaning projects several times)
Re: GUIDE: Using Java 8 with SFS2X
There seem to be some JRE conflict on your system.
If your Extension is compiled for Java8 you will necessarily need to replace the SFS2X embedded JRE with a new JRE8.
Have you done this? If not follow these simple steps:
http://smartfoxserver.com/blog/?p=281
cheers
If your Extension is compiled for Java8 you will necessarily need to replace the SFS2X embedded JRE with a new JRE8.
Have you done this? If not follow these simple steps:
http://smartfoxserver.com/blog/?p=281
cheers
Re: GUIDE: Using Java 8 with SFS2X
I'm experiencing the same thing. "Unsupported major.minor version 52.0". Extension is compiled with 1.8.0_60 and java -version returns:
Plus, returns
So I know the system is running 1.8. I added the .mod file as well, but I can't imagine that's related to this issue.
Any other way to debug this?
Thanks.
Code: Select all
java version "1.8.0_60"
Plus,
Code: Select all
ls -alh /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Code: Select all
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/
So I know the system is running 1.8. I added the .mod file as well, but I can't imagine that's related to this issue.
Any other way to debug this?
Thanks.
Re: GUIDE: Using Java 8 with SFS2X
SmartFoxServer does not run with your system's Java Runtime, it uses its own, which is still Java 7.
What is happening is that you have compiled your server code in Java 8 and you're attempting to run it in JVM 7, thus causing the error.
All you need to do is replace the SFS2X embedded JRE with the latest JRE 8, by following the 3 steps outlined in the opening post of this thread.
Hope it helps
What is happening is that you have compiled your server code in Java 8 and you're attempting to run it in JVM 7, thus causing the error.
All you need to do is replace the SFS2X embedded JRE with the latest JRE 8, by following the 3 steps outlined in the opening post of this thread.
Hope it helps
Re: GUIDE: Using Java 8 with SFS2X
I had followed the instructions, however #2 should be split into 2 steps or re-written for clarity
2) Uncompress the download and replace the jre/ folder under the root of your SmartFoxServer 2X installation, replacing the existing folder. This will overwrite the previous JRE. For MacOSX users the jre/ folder will be new to the directory.
When you say "This step is not required for MacOS X" I logically assumed you were referring to the entire step #2.
Even with this, the SFS2X.app fails to load properly and throws the same error. Running the /sfs2x.sh script loads the new JRE since it looks for it and works, but this method cripples the OSX .app.
EDIT: To get the SFS2X.app working, I right clicked it and selected "Show Package Contents". From there, I opened up /Content/Resources/script and changed the following to replace the jre.bundle with the new JRE placed as instructed above:
Works as expected now.
2) Uncompress the download and replace the jre/ folder under the root of your SmartFoxServer 2X installation, replacing the existing folder. This will overwrite the previous JRE. For MacOSX users the jre/ folder will be new to the directory.
When you say "This step is not required for MacOS X" I logically assumed you were referring to the entire step #2.
Even with this, the SFS2X.app fails to load properly and throws the same error. Running the /sfs2x.sh script loads the new JRE since it looks for it and works, but this method cripples the OSX .app.
EDIT: To get the SFS2X.app working, I right clicked it and selected "Show Package Contents". From there, I opened up /Content/Resources/script and changed the following to replace the jre.bundle with the new JRE placed as instructed above:
Code: Select all
#JRE7="../.install4j/jre.bundle/Contents/Home/jre/bin/java"
JRE8="../jre/bin/java"
${JRE8} -cp "./:lib/*:lib/jetty/lib/*:extensions/__lib__/*" -Dfile.encoding=UTF-8 com.smartfoxserver.v2.Main $1 $2
Works as expected now.
Re: GUIDE: Using Java 8 with SFS2X
Thanks.
Point #2 is indeed to be skipped entirely under Mac OS X, because the Oracle Java installer will perform a global installation, system-wide.
The easiest way to get up and running is simply to install Java 8 and then launch SFS2X via sfs2x.sh script in the terminal. There actually a total of 4 ways to launch SFS2X on the Mac Three of which depend on the embedded JRE and require further hacking into the shell scripts.
We plan to release the next update embedding Java 8 by default, avoiding any other manual changes.
cheers
Point #2 is indeed to be skipped entirely under Mac OS X, because the Oracle Java installer will perform a global installation, system-wide.
The easiest way to get up and running is simply to install Java 8 and then launch SFS2X via sfs2x.sh script in the terminal. There actually a total of 4 ways to launch SFS2X on the Mac Three of which depend on the embedded JRE and require further hacking into the shell scripts.
We plan to release the next update embedding Java 8 by default, avoiding any other manual changes.
cheers
Who is online
Users browsing this forum: No registered users and 104 guests