1

I have ColdFusion 9.0.2 and Java 1.6.0_29. I'm trying to use the java loader project to compile java code but I am receiving this error.

package javax.servlet.http does not exist import
javax.servlet.http.HttpServletRequest;

However, the javax.servlet.http package seems to be there already b/c I can execute this code without error:

<cfset obj = createObject("java","javax.servlet.http.HttpServletRequest")>
<cfdump var="#obj#">

I've tried downloading the jar for javax.servlet.http and adding it to CF (paste in C:\ColdFusion9\runtime\lib and restart cf service) but it doesn't make any difference. Is an older version of this package included in a jar that is part of CF or something?

jessieloo
  • 1,759
  • 17
  • 24
  • 1
    Are you getting that error when compiling custom sources or when you run the basic [HelloWorld example](https://github.com/markmandel/JavaLoader/tree/develop/example/compileHelloWorld)? Can you post the full stack trace? *RE: ...the javax.servlet.http package seems to be there already* Yes, ColdFusion is a servlet. So it is included in the main CF class path. However, the JavaLoader does not include the main CF class path path by default. Try setting `loadColdFusionClassPath=true`. – Leigh Sep 30 '16 at 15:58
  • Thanks, Leigh! Adding loadColdFusionClassPath=true fixed it... or at least got me past that dependency error :-) – jessieloo Sep 30 '16 at 16:11
  • *at least got me past that dependency error* Ahh, the joys of resolving dependencies ;-) – Leigh Sep 30 '16 at 17:48

1 Answers1

2

Yep. ColdFusion itself runs as a servlet (essentially). So the javax.servlet library is already included in the main CF class path, which is why the createObject() call works. However, the JavaLoader does not load the CF class path by default.

Parameter: loadColdFusionClassPath

Defaults to: false

Loads the ColdFusion libraries with the loaded libraries. This used to be on by default, however now you must implicitly set it to be true if you wish to access any of the libraries that ColdFusion loads at application start up.

Try setting loadColdFusionClassPath = true. Adding the javax.servlet jar file to the loadPaths array may work as well.

Leigh
  • 28,765
  • 10
  • 55
  • 103