Include Java Files into Coldfusion

2019-04-08 15:11发布

问题:

How can I include jar/java files into my coldfusion project. currently I am using this line into me <cfscript>

Me directory is looks like this

website_name
         |__ Login
             |__ connection
                |__ display.cfm
                |__ twitter
                    |__ com
                        |__ ConfigurationBuilder.java

in my display.cfm file I am calling obj in script like this

<cfscript>
    configBuilder = createObject("java", "twitter.com.ConfigurationBuilder");
</cfscript>

but it gives me error on this line when I run display.com and error is this

An exception occurred while instantiating a Java object. The class must not be 
an interface or an abstract class. Error: ''. 

The error occurred in website_name/login/azam/connection/display.cfm: line 57


57 :            configBuilder = createObject("java", "twitter.com.ConfigurationBuilder");

How can I call my java class and how to call its function so that I can call my twitter function.

回答1:

The easiest way to add class or jar files to your class path is to simply drop them in the lib directory where they are automatically picked up. The directory is located at {cf_installation}/servers/lib. These class files will be available to all servers.

http://blogs.adobe.com/cantrell/archives/2004/07/the_definitive.html



回答2:

If you're using ColdFusion 10 you can use the newly built in feature to dynamically load Java Files:

Specifying custom Java library path in the Application.cfc



回答3:

As surfealokesea said in their answer:

The easiest way to add class or jar files to your class path is to simply drop them in the lib directory where they are automatically picked up. The directory is located at

CF Directory(where CF is installed)
                             |__ servers/lib

These class files will be available to all servers.

You can also make your class files available only to the ColdFusion server by dropping them in

{cf_installation}/servers/default/cfmx/WEB-INF/lib.

(Note that putting them in {cf_installation}/servers/default/cfmx/WEB-INF/cfusion/lib will NOT work.)



回答4:

ColdFusion 9 here:

  1. Put jars into: wwwroot/WEB-INF/lib
  2. Put classes into: wwwroot/WEB-INF/classes (class mypackage.myClass goes into subdirectory mypackage)