Link to home
Start Free TrialLog in
Avatar of xenia27
xenia27Flag for Taiwan, Province of China

asked on

javax.script cannot be resolved

I try to call functions in javascript with java program.  I found some information and tried implement it.  However, I got this error message," [ERROR] Line 5: The import javax.script cannot be resolved".  What's wrong with my code?

I am using JRE 1.6.0.13 with eclipse.
package com.xenia.googleproject.server;
 
import javax.script.*;
import com.xenia.googleproject.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 
 
/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {
 
	public String greetServer(String input) {
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return "Hello, " + input + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent;
	}
	
	public String getClientAddr(String latitude, String longitude, String city, String country, String country_code, String region){
		String addr = new String();
		ScriptEngineManager mgr = new ScriptEngineManager();
		ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
		Invocable invEngine = (Invocable)jsEngine;
 
		
		try{
			jsEngine.eval("function getClientLocation(lat, lng, city, country, country_code, region)"
					);
			invEngine.invokeFunction("getClientLocation", latitude, longitude, city, country, country_code, region);
		} catch (ScriptException ex){
			ex.printStackTrace();
		} catch (NoSuchMethodException ex){
			ex.printStackTrace();
		}
		addr = city;
		
		return addr;
	}
}

Open in new window

SOLUTION
Avatar of jwenting
jwenting
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenia27

ASKER

How can I be sure which version Eclipse recognize?  Where should I lookup to?  I try to figure which version Eclipse have from "Project>Properties" but I did not see anything like 1.5...Did I miss something?
Avatar of guneshraj
guneshraj

Its the compiler settings. change it from 1.5 to 1.6
I think there are around 3 sections to change in eclipse.

To make it simple, just remove or uninstall 1.5 & 1.6 & Install 1.6
This should help.


Avatar of xenia27

ASKER

I think I have the compiler set to 1.6...Please check the attachement...
compiler.JPG
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenia27

ASKER

OK...I finally got what you meant and it worked!!  I uninstalled everything and reinstalled JDK 1.6 only...
Thank you!!