javax.script cannot be resolved

Posted on 2009-06-30
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 with eclipse.
package com.xenia.googleproject.server;

import javax.script.*;

import com.xenia.googleproject.client.GreetingService;



 * The server side implementation of the RPC service.



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;



			jsEngine.eval("function getClientLocation(lat, lng, city, country, country_code, region)"


			invEngine.invokeFunction("getClientLocation", latitude, longitude, city, country, country_code, region);

		} catch (ScriptException ex){


		} catch (NoSuchMethodException ex){



		addr = city;


		return addr;



Open in new window

Question by:xenia27
  • 3
  • 2

Assisted Solution

jwenting earned 200 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).

Author Comment

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?

Expert Comment

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.

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.


Author Comment

ID: 24752630
I think I have the compiler set to 1.6...Please check the attachement...

Accepted Solution

guneshraj earned 300 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


Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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)

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now