From: RyanG24 on 4 Feb 2007 21:50 Hi Paul, i just messed it up, i uploaded the new cfcs from the link you gave me in the previous post, but now i get this error again? any ideas what i need to do java init failed: net.sf.javainetlocator.InetAddressLocator Class not found: net.sf.javainetlocator.InetAddressLocator The error occurred in D:\inetpub\vhosts\thesmsengine.com\httpdocs\geoLocator.cfc: line 92 Called from D:\inetpub\vhosts\thesmsengine.com\httpdocs\geoLocator.cfc: line 81 Called from D:\inetpub\vhosts\thesmsengine.com\httpdocs\local.cfm: line 10 90 : <cfobject type="Java" action="Create" class="java.util.Locale" name="variables.javaLocale"> 91 : <cfcatch type="Any"> 92 : <cfthrow message="java init failed: net.sf.javainetlocator.InetAddressLocator" detail="#cfcatch.detail#" errorcode="1001"> 93 : </cfcatch> 94 : </cftry>
From: PaulH **AdobeCommunityExpert** on 4 Feb 2007 22:43 RyanG24 wrote: > Hi Paul, i just messed it up, i uploaded the new cfcs from the link you gave me > in the previous post, but now i get this error again? you only need to upload the jar, the old CFC based on javaLoader is fine. put the new jar in another location & just point the javaloader bits at the new location.
From: RyanG24 on 4 Feb 2007 23:15 ok but how do i point it, what line do i need to change?
From: PaulH **AdobeCommunityExpert** on 5 Feb 2007 00:01 RyanG24 wrote: > ok but how do i point it, what line do i need to change? i don't have the version i made for you in front of me but look in the init method, there should be an argument something like "geoLocatorJarFile" or failing that look for "InetAddressLocator.jar" in the init.
From: RyanG24 on 5 Feb 2007 00:37
Hi Paul, i am getting confused, just want to check that i have the right cfcs below and which line i need to change, i have added both the ***JavaLoader.cfc*** and the ***GeoLocator.cfc*** below thanks ryan ***JavaLoader.cfc*** <cfcomponent name="JavaLoader" hint="Loads External Java Classes, while providing access to ColdFusion classes"> <cfscript> instance = StructNew(); </cfscript> <!------------------------------------------- PUBLIC -------------------------------------------> <cffunction name="init" hint="Constructor" access="public" returntype="JavaLoader" output="false"> <cfargument name="loadPaths" hint="An array of directories of classes, or paths to .jar files to load" type="array" default="#ArrayNew(1)#" required="no"> <cfargument name="loadColdFusionClassPath" hint="Loads the ColdFusion libraries" type="boolean" required="No" default="false"> <cfargument name="loadedClassPathBias" hint="If loading classes on top of a parent classpath, search the loaded classes before searching the parent ClassPath" type="boolean" required="No" default="true"> <cfargument name="parentClassLoader" hint="(Expert use only) The parent java.lang.ClassLoader to set when creating the URLClassLoader" type="any" default="" required="false"> <cfscript> var iterator = arguments.loadPaths.iterator(); var Array = createObject("java", "java.lang.reflect.Array"); var Class = createObject("java", "java.lang.Class"); var URLs = Array.newInstance(Class.forName("java.net.URL"), JavaCast("int", ArrayLen(arguments.loadPaths))); var file = 0; var classLoader = 0; var counter = 0; var javaloader = 0; while(iterator.hasNext()) { file = createObject("java", "InetAddressLocator").init(iterator.next()); if(NOT file.exists()) { throw("PathNotFoundException", "The path you have specified could not be found", file.getAbsolutePath() & " does not exist"); } Array.set(URLs, JavaCast("int", counter), file.toURL()); counter = counter + 1; } if(arguments.loadColdFusionClassPath) { arguments.parentClassLoader = createObject("java", "java.lang.Thread").currentThread().getContextClassLoader(); } if(arguments.loadedClassPathBias) { javaloader = createObject("component", "JavaLoader").init(loadPaths=queryJars(), loadedClassPathBias=false); if(isObject(arguments.parentClassLoader)) { classLoader = javaloader.create("com.compoundtheory.classloader.ChildBiasURLClassLoader").init (URLs, arguments.parentClassLoader); } else { classLoader = javaloader.create("com.compoundtheory.classloader.ChildBiasURLClassLoader").init (URLs); } } else { if(isObject(arguments.parentClassLoader)) { classLoader = createObject("java", "java.net.URLClassLoader").init(URLs, arguments.parentClassLoader); } else { classLoader = createObject("java", "java.net.URLClassLoader").init(URLs); } } //pass in the system loader setURLClassLoader(classLoader); return this; </cfscript> </cffunction> <cffunction name="create" hint="Retrieves a reference to the java class. To create a instance, you must run init() on this object" access="public" returntype="any" output="false"> <cfargument name="className" hint="The name of the class to create" type="string" required="Yes"> <cfscript> var class = getURLClassLoader().loadClass(arguments.className); return createObject("java", "coldfusion.runtime.java.JavaProxy").init(class); </cfscript> </cffunction> <cffunction name="getURLClassLoader" hint="Returns the java.net.URLClassLoader in case you need access to it" access="public" returntype="any" output="false"> <cfreturn instance.ClassLoader /> </cffunction> <cffunction name="getVersion" hint="Retrieves the version of the loader you are using" access="public" returntype="string" output="false"> <cfreturn "0.3"> </cffunction> <!------------------------------------------- PACKAGE -------------------------------------------> <!------------------------------------------- PRIVATE -------------------------------------------> <cffunction name="queryJars" hint="pulls a query of all the jars in the /resources/lib folder" access="private" returntype="array" output="false"> <cfscript> var qJars = 0; //the path to my jar library var path = getDirectoryFromPath(getMetaData(this).path) & "lib/"; var jarList = ""; var aJars = ArrayNew(1); var libName = 0; </cfscript> <cfdirectory action="list" name="qJars" directory="#path#" filter="*.jar" sort="name desc"/> <cfloop query="qJars"> <cfscript> libName = ListGetAt(name, 1, "-"); //let's not use the lib's that have the same name, but a lower datestamp if(NOT ListFind(jarList, libName)) { ArrayAppend(aJars, path & "/" & name); jarList = ListAppend(jarList, libName); } </cfscript> </cfloop> <cfreturn aJars> </cffunction> <cffunction name="setURLClassLoader" access="private" returntype="void" output="false"> <cfargument name="ClassLoader" type="any" required="true"> <cfset instance.ClassLoader = arguments.ClassLoader /> </cffunction> <cffunction name="throw" access="private" hint="Throws an Exception" output="false"> <cfargument name="type" hint="The type of exception" type="string" required="Yes"> <cfargument name="message" hint="The message to accompany the exception" type="string" required="Yes"> <cfargument name="detail" type="string" hint="The detail message for the exception" required="No" default=""> <cfthrow type="#arguments.type#" message="#arguments.message#" detail="#arguments.detail#"> </cffunction> </cfcomponent> ***GeoLocator.cfc*** <cfcomponent displayname="geoLocator" name="geoLocator" hint="returns locale info based on user IP: version 1.8 feb-2005 Paul Hastings (paul(a)sustainbleGIS.com)"> <cfset init()> <cffunction access="public" displayname="init" name="init" output="No" hint="initializes java objects & valid locales"> <cfset var orgLocales=""> <cfset var theseLocales= arrayNew(1)> <cfset var i=1> <cfset var x=""> <cftry> <cfobject type="Java" action="Create" class="net.sf.javainetlocator.InetAddressLocator" name="variables.geoLocator"> <cfobject type="Java" action="Create" class="java.util.Locale" name="variables.javaLocale"> <cfcatch type="Any"> <cfthrow message="java init failed: net.sf.javainetlocator.InetAddressLocator" detail="#cfcatch.detail#" errorcode="1001"> </cfcatch> </cftry> <!--- enumerate available locales ---> <cfset orgLocales = javaLocale.getAvailableLocales()> <cfloop index="i" from="1" to="#arrayLen(orgLocales)#"> <cfif listLen(orgLocales[i],"_") GT 1> <cfset x=arrayAppend(theseLocales,orgLocales[i])> </cfif> </cfloop> <cfset allLocales = arrayToList(theseLocales)> <cfset variables.geoLocatorInit=true> </cffunction> <cffunction name="isValidLocale" access="public" displayname="isValidLocale" hint="determines if passed locale is valid java locale" output="No" returntype="boolean"> <cfargument name="aLocale" required="Yes" type="string"><!--- locale to check ---> <cfset var bLocaleValid=0> <!--- assume bad locale ---> <cfif Listfind(allLocales,arguments.aLocale)> <cfset bLocaleValid=1> </cfif> <cfreturn bLocaleValid> </cffunction> <cffunction name="findLocale" access="public" displayname="findLocale" hint="returns locale from user IP" output="No" returntype="string"> <cfargument name="thisIP" required="Yes" type="string"><!--- this user's IP, cgi.REMOTE_ADDR ---> <cfargument name="thisLanguage" required="Yes" type="string"><!--- CGI.http_accept_Language ---> <cfargument name="fallbackLocale" required="No" type="string" default="en_US"> <cfset var thisHost=""> <cfset var aLocale=""> <cfset var thisLocale=""> <cfset var testLocale=""> <cfset var aLanguage=""> <cfset var mixedLocale=0> <cfset aLocale=geoLocator.getLocale(arguments.thisIP)> <cfif aLocale EQ "**"> <!--- localhost, IP not in db, etc. ---> <cfset aLocale=arguments.fallbackLocale> <!--- fall back locale ---> </cfif> <cfset thisLocale=aLocale> <!--- lets clean up CFML easter egg locales, considering who might be using this cfc ---> <cfset aLanguage=replaceNoCase(arguments.thisLanguage,"CFML,","","ALL")> <cfset aLanguage=replaceNoCase(aLanguage,",CFML","","ALL")> <cfset aLanguage=replaceNoCase(aLanguage,",CFML,","","ALL")> <!--- just grab the first language/locale in the list ---> <cfset aLanguage=listFirst(replaceNoCase(aLanguage,"-","_","ALL"),",")> <!--- try to make this a proper Locale ---> <cfset aLanguage=left(aLanguage,2) & "_" & uCase(right(aLanguage,2))> <!--- easy stuff 1st, http_accept_language not the same as geoLocator locale or its not empty---> <cfif (aLanguage NEQ thisLocale) AND (trim(len(aLanguage)))><!--- this gets tricky and a bit arbitrary ---> <!--- lets mix & match language & country to see if we come up w/a valid locale ---> <cfset testLocale=left(aLanguage,2) & "_" & right(aLocale,2)> <cfif isValidLocale(testLocale)> <cfset mixedLocale=1> <cfset thisLocale=testLocale> </cfif> <!--- did mixed locale work and could the http_accept_language be a vlaid Locale, ie en_US, th_TH, etc ---> <cfif NOT mixedLocale AND trim(len(aLanguage)) is 5> <cfif isValidLocale(aLanguage)> <cfset thisLocale=aLanguage> </cfif> </cfif> </cfif> <cfreturn thisLocale> </cffunction> <cffunction name="findCountry" access="public" displayname="findCountry" hint="returns country from user IP" output="No" returntype="string"> <cfargument name="thisIP" required="Yes" type="string"><!--- this user's IP, cgi.REMOTE_ADDR ---> <cfargument name="fallbackCountry" required="No" type="string" default="US"> <cfset var thisHost=""> <cfset var thisCountry=""> <cfset thisCountry=right(geoLocator.getLocale(arguments.thisIP |