I am new to Lejos and in my first year of experience with Java. I was able to modify the Intelligence Unleashed segoway to use Dexter Industries DIMU. (I learned a lot!). I am now beginning to use the Dexter Industries WIFI sensor. There is a beta library for this device for Lejos from the manufacturer. I am able to communicate via wifi with the NXT. I am looking to implement an HTML5 websocket server on the NXT. In order to avoid writing code for the long handshake, I am trying to embed a Jetty server. I have worked with Jetty on my home Linux box, and can deploy it without difficulty. As a first step with the NXT, I just want to deploy a simple test server that responds when called. I have tried my code on the JRE 7 linux box and it works. When I compile this using eclipse juno and NXT runtime, I get the "indirectly referenced from required .class files." I have researched this forum, stack overflow and google search. I know I need to add the missing .jar file to the classpath, but here I am stumped. I can obtain the source code for the missing class. It is java.io.PrintWriter.java . However, the classes.jar in NXT runtime are already compiled, then jar'd (is that a verb?). I have tried to add the .java file as a referenced library, and have also placed it in the src (default package). These attempts didn't work. I have also added the source code to the classes source files in the NXJ Development Kit Sources and tried to build the classes.jar again using Ant in Eclipse, but it did not compile due to the addition of the new file to the .io folder. Is there any way to integrate this class, which is absent in the classes.jar in its correct location so it can be referenced and interact appropriately with the rest of the java.io package? I am posting the code for the test server below. I have all of the jetty-specific jars in their appropriate locations. Can I replace the entire java.io class in the NXT runtime library? I suspect that would break more than it fixes.
- Code: Select all
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.Writer;
import java.io.IOException;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
public class NXTHello extends AbstractHandler
{
public void handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html;charset=utf-8");
response.setStatus(HttpServletResponse.SC_OK);
baseRequest.setHandled(true);
response.getWriter().println("<h1>You have reached Fredly. I'm not in right now...</h1>");
}
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
server.setHandler(new NXTHello());
server.start();
server.join();
}
}