How do I incorporate Java into a webserver app ?
How to incorporate Java into a webserver app ? Topic is solved
-
- XCore Addict
- Posts: 185
- Joined: Tue Mar 26, 2013 12:10 pm
-
- XCore Addict
- Posts: 185
- Joined: Tue Mar 26, 2013 12:10 pm
Java (.jar) files can be served up in the same way as any other file.
Here are the steps to run a simple Java script :
Create a new workspace and download the Embedded Webserver Demo (SPI Flash) xSOFTip example.
Build the standard example and flash it on your sliceKIT - pay particular attention to the webserver demo quick start instructions.
In your browser, navigate to the IP address of the board and ensure that it is working correctly.
Create a java file (e.g. ExampleProgram.java) :
class ExampleProgram {
public static void main(String[] args){
System.out.println("Java - Hello World !");
}
}
Compile this to a .jar file using the following commands :
javac ExampleProgram.java
jar cvf ExampleProgram.jar ExampleProgram.class
Navigate to the folder : <workspace>\app_webserver_demo_flash\web
Create a folder "applets"
Copy ExampleProgram.jar into the applets folder.
Add the following html into the body of <workspace>\app_webserver_demo_flash\web\index.html
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class ExampleProgram extends Applet { // save as "HelloApplet.java"
public void paint(Graphics g) {
setBackground(Color.CYAN); // set background color
g.setColor(Color.BLACK); // set foreground text color
g.setFont(new Font("Times New Roman", Font.BOLD, 30)); // set font face, bold and size
g.drawString("Hello, world", 20, 80); // draw string with baseline at (20, 80)
}
}
Rebuild the application and flash to the board.
Check that your Java and browser security settings will allow you to execute the java code.
In your browser, navigate to the IP address of the board.
You should now see "Java - Hello World !" in your browser.
References
For building the application, I followed the instructions here :
https://www.xmos.com/published/embedded ... )?secure=1.
The Webserver library programming guide is a very useful resource :
https://www.xmos.com/published/embedded ... 1.0.3rc1.a
https://www.xmos.com/node/16237?page=3
Example code taken from here :
http://www.ntu.edu.sg/home/ehchua/progr ... start.html
Here are the steps to run a simple Java script :
Create a new workspace and download the Embedded Webserver Demo (SPI Flash) xSOFTip example.
Build the standard example and flash it on your sliceKIT - pay particular attention to the webserver demo quick start instructions.
In your browser, navigate to the IP address of the board and ensure that it is working correctly.
Create a java file (e.g. ExampleProgram.java) :
class ExampleProgram {
public static void main(String[] args){
System.out.println("Java - Hello World !");
}
}
Compile this to a .jar file using the following commands :
javac ExampleProgram.java
jar cvf ExampleProgram.jar ExampleProgram.class
Navigate to the folder : <workspace>\app_webserver_demo_flash\web
Create a folder "applets"
Copy ExampleProgram.jar into the applets folder.
Add the following html into the body of <workspace>\app_webserver_demo_flash\web\index.html
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
public class ExampleProgram extends Applet { // save as "HelloApplet.java"
public void paint(Graphics g) {
setBackground(Color.CYAN); // set background color
g.setColor(Color.BLACK); // set foreground text color
g.setFont(new Font("Times New Roman", Font.BOLD, 30)); // set font face, bold and size
g.drawString("Hello, world", 20, 80); // draw string with baseline at (20, 80)
}
}
Rebuild the application and flash to the board.
Check that your Java and browser security settings will allow you to execute the java code.
In your browser, navigate to the IP address of the board.
You should now see "Java - Hello World !" in your browser.
References
For building the application, I followed the instructions here :
https://www.xmos.com/published/embedded ... )?secure=1.
The Webserver library programming guide is a very useful resource :
https://www.xmos.com/published/embedded ... 1.0.3rc1.a
https://www.xmos.com/node/16237?page=3
Example code taken from here :
http://www.ntu.edu.sg/home/ehchua/progr ... start.html