title: How do I resolve "Packages is not defined" in WSO2 Carbon 4.0.3 with Application Server Features?
body: <p>I am attempting to upgrade from WSO2 Carbon 3.0.0 to Carbon 4.0.3.  Using Carbon 3.0.0, after installing the necessary features, I'm able to write JavaScript Mashup services that can call external Java libraries--and since WSO2 carbon uses Rhino, I'm able to use importPackage.  I have not been able to get the same functionality working on Carbon 4.0.3.</p>
  
  <p>The procedure I've followed is:</p>
  
  <ol>
  <li>Download and unzip WSO2 Carbon 4.0.3</li>
  <li>Start Carbon</li>
  <li>Navigate to the "Feature Management" page</li>
  <li>Add the 4.0.3 Carbon p2 repository (<a href="http://dist.wso2.org/p2/carbon/releases/4.0.3/" rel="noreferrer">http://dist.wso2.org/p2/carbon/releases/4.0.3/</a>)</li>
  <li>Search for and install the "Application Server" feature</li>
  <li>Restart Carbon</li>
  <li>Deploy my test Mashup service</li>
  <li>Execute the echo operation of my test Mashup service using the "tryit" tool.</li>
  </ol>
  
  <p>My test Mashup service (TestMashup.js):</p>
  
  <pre><code>this.serviceName = "TestMashup";
  
  echo.inputTypes = "#raw";
  echo.outputType = "#raw";
  function echo(parameter) {
      var javaDate = new Packages.java.util.Date();
      var response = "&lt;echo&gt;&lt;value&gt;" + parameter.toXMLString() + "&lt;/value&gt;&lt;timestamp&gt;" + javaDate.getTime() + "&lt;/timestamp&gt;&lt;/echo&gt;";
  
      return new XML(response);
  }
  </code></pre>
  
  <p>I've installed this Mashup service to CARBON_HOME/repository/deployment/server/jsservices/admin/</p>
  
  <p>When I run this operation on Carbon 3.0.0, I get the following response:</p>
  
  <pre><code>&lt;echo&gt;
    &lt;value&gt;
      &lt;r&gt;test&lt;/r&gt;
    &lt;/value&gt;
    &lt;timestamp&gt;1360699125311&lt;/timestamp&gt;
  &lt;/echo&gt;
  </code></pre>
  
  <p>When I attempt to run this operation on Carbon 4.0.3, I get the following stack-trace:</p>
  
  <pre><code>[2013-02-12 14:46:32,511] ERROR {org.jaggeryjs.scriptengine.engine.RhinoEngine} -  org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined.(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
  [2013-02-12 14:46:32,512] ERROR {org.jaggeryjs.scriptengine.engine.RhinoEngine} -  org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
  [2013-02-12 14:46:32,512] ERROR {org.apache.axis2.receivers.AbstractMessageReceiver} -  org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
  org.apache.axis2.AxisFault: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined.(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
          at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
          at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:176)
          at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:208)
          at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptReceiver.invokeBusinessLogic(JavaScriptReceiver.java:185)
          at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
          at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
          at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
          at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
          at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
          at org.wso2.carbon.core.transports.CarbonServlet.doPost(CarbonServlet.java:231)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
          at org.eclipse.equinox.http.helper.FilterServletAdaptor$FilterChainImpl.doFilter(FilterServletAdaptor.java:56)
          at org.wso2.carbon.mashup.jsservices.custom.ui.CustomUIServletFilter.doFilter(CustomUIServletFilter.java:233)
          at org.eclipse.equinox.http.helper.FilterServletAdaptor.service(FilterServletAdaptor.java:37)
          at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
          at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
          at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:67)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
          at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.service(DelegationServlet.java:68)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter.doFilter(CharacterSetFilter.java:61)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
          at org.wso2.carbon.tomcat.ext.valves.CompositeValve.invoke(CompositeValve.java:172)
          at org.wso2.carbon.tomcat.ext.valves.CarbonStuckThreadDetectionValve.invoke(CarbonStuckThreadDetectionValve.java:156)
          at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
          at org.wso2.carbon.tomcat.ext.valves.CarbonContextCreatorValve.invoke(CarbonContextCreatorValve.java:52)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
          at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1653)
          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
          at java.lang.Thread.run(Thread.java:662)
  Caused by: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
          at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:383)
          at org.jaggeryjs.scriptengine.engine.RhinoEngine.call(RhinoEngine.java:251)
          at org.wso2.carbon.mashup.javascript.messagereceiver.JavaScriptEngine.call(JavaScriptEngine.java:169)
          ... 40 more
  Caused by: org.jaggeryjs.scriptengine.exceptions.ScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
          at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:401)
          at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:380)
          ... 42 more
  Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "Packages" is not defined. (//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js#6)
          at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
          at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
          at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
          at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1652)
          at org.jaggeryjs.rhino.c0._c1(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js:6)
          at org.jaggeryjs.rhino.c0.call(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js)
          at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
          at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
          at org.jaggeryjs.rhino.c0.call(//C:\WSO2CA~1\WSO2CA~1.3\bin\..\repository\deployment\server\jsservices\admin\TestMashup.js)
          at org.jaggeryjs.scriptengine.engine.RhinoEngine.execFunc(RhinoEngine.java:398)
          ... 43 more
  </code></pre>
  
  <p>How do I fix this so that I can continue using Java libraries from my JavaScript Mashup services?</p>