Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javax.script cannot be resolved

Posted on 2009-06-30
6
Medium Priority
?
1,446 Views
1 Endorsement
Last Modified: 2012-05-07
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
Comment
Question by:xenia27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 6

Assisted Solution

by:jwenting
jwenting earned 800 total points
ID: 24751721
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
 

Author Comment

by:xenia27
ID: 24751743
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
 
LVL 2

Expert Comment

by:guneshraj
ID: 24752538
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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:xenia27
ID: 24752630
I think I have the compiler set to 1.6...Please check the attachement...
compiler.JPG
0
 
LVL 2

Accepted Solution

by:
guneshraj earned 1200 total points
ID: 24752651
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
 

Author Comment

by:xenia27
ID: 24752765
OK...I finally got what you meant and it worked!!  I uninstalled everything and reinstalled JDK 1.6 only...
Thank you!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question