Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1473
  • Last Modified:

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

1
xenia27
Asked:
xenia27
  • 3
  • 2
2 Solutions
 
jwentingCommented:
Most likely you have Eclipse set to 1.5 compiler settings rather than 1.6, causing it to not recognise any of the 1.6 specific packages.
Just because you have a 1.6 JVM installed on your system doesn't mean your IDE will use that (especially if it's Eclipse).
0
 
xenia27Author Commented:
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?
0
 
guneshrajCommented:
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.


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
xenia27Author Commented:
I think I have the compiler set to 1.6...Please check the attachement...
compiler.JPG
0
 
guneshrajCommented:
What I meant was the 'Compiler' The executable & the runtime classes.
Somehow eclipse got that mixed up, & Im very sure you have 2 JDK's running.

I had this problem in MacOSX 10.5 before, the strange thing is that if I compile the Code from command line, it works well.
If you cant compile from command line, theres more than the eclipse configs.
Perhaps your Environment settings is not correct?

It a simple problem thats hard to detect, I strongly suggest to remove & reinstall the JDK 1.6

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now