Re: java extensions

Steven Van Loon <[email protected]> Fri, 21 Aug 2015 13:44:39 +0000
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <HE1PR03MB10178A3A7FBE38CD999DF02699650@HE1PR03MB1017.eurprd03.prod.outlook.com>
Hi Jeroen,

Thanks, that seems to be working:

            Assembly dll = Assembly.Load("icu4j");
            ikvm.runtime.Startup.addBootClassPathAssemby(dll);

            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, new Locale("af", "ZA"));
            Console.WriteLine(df.format(new Date()));

Now prints
21 Augustus 2015

Without addBootClassPathAssembly, I get
August 21, 2015


To be honest and for completeness, I can see now that I said untrue things in my initial email. The code:

            com.ibm.icu.impl.javaspi.text.DateFormatProviderICU dfi = new com.ibm.icu.impl.javaspi.text.DateFormatProviderICU();

            DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, new Locale("af", "ZA"));
            Console.WriteLine(df.format(new Date()));

also prints out 21 augustus 2015. However, my native language is dutch and august in afrikaans and dutch both is Augustus. So I thought it wasn't working while it was. My mistake. 

The addBootClasspathAssembly however is much cleaner I guess, so thanks a lot for the answer.

Best regards,
Steven.


-----Original Message-----
From: Jeroen Frijters [mailto:[email protected]] 
Sent: Friday, August 21, 2015 14:19
To: Steven Van Loon <[email protected]>; [email protected]
Subject: RE: java extensions

Hi,

I haven't tried it (I couldn't download the ICU jars, the site was down or something), but it might work if you add the ICU assemblies to the "boot classpath" using:

ikvm.runtime.Startup.addBootClassPathAssemby(...)

Regards,
Jeroen

> -----Original Message-----
> From: Steven Van Loon [mailto:[email protected]]
> Sent: Thursday, August 20, 2015 17:48
> To: [email protected]
> Subject: [Ikvm-developers] java extensions
> 
> Hi,
> 
> I'm trying to use icu4j (http://site.icu-project.org/) in a .net 
> application using ikvm. What I need to do in java, is to add the icu 
> jars (icu4j-55.1.jar and icu4j-localespi-55_1-20150610.jar) to the 
> lib/ext folder and then the following (java) code will output in 
> Afrikaans (not supported by the standard java platform):
> 
> java.text.DateFormat df =
> java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG, new 
> java.util.Locale("af", "ZA")); System.out.println(df.format(new 
> java.util.Date()));
> 
> icu4j works with the java extension mechanism.
> 
> What I did next, was to convert the icu4j jars to dll's using ikvm and 
> referenced them in my application. However, I can't get the following
> (c#) code to do what it does in java:
> 
> java.text.DateFormat df =
> java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG, new 
> java.util.Locale("af", "ZA")); System.Console.WriteLine(df.format(new
> java.util.Date()));
> 
> I keeps outputting in the default locale.
> 
> Now, is there a known way to get the locale-sensitive services to work 
> in ikvm?
> 
> I'm using ikvm 7.2.4630.5.
> 
> 
> What I already did:
> I discovered that in the search of the DateFormat in 
> DateFormat.getDateInstance(...), eventually, 
> [c#]java.util.ServiceLoader.loadInstalled(typeof(java.text.spi.DateFor
> ma
> tProvider)) is called. When I call this method manually and iterate 
> over it, it returns no results. When I create an instance of 
> com.ibm.icu.impl.javaspi.text.DateFormatProviderICU (the class 
> implementing DateFormat in the icu lib), the iterator does return 
> something.
> 
>             com.ibm.icu.impl.javaspi.text.DateFormatProviderICU dfi = 
> new com.ibm.icu.impl.javaspi.text.DateFormatProviderICU();
> 
>             ServiceLoader ldr =
> java.util.ServiceLoader.loadInstalled(typeof(java.text.spi.DateFormatP
> ro
> vider));
> 
>             Iterator iter = ldr.iterator();
>             while(iter.hasNext())
>             {
>                 java.text.spi.DateFormatProvider dfp = 
> (java.text.spi.DateFormatProvider)iter.next();
>                 Console.WriteLine(dfp.toString());
>             }
> 
> However, the code still won't output the date in Afrikaans. (Also, 
> next message is found on stdout "Exception thrown:
> 'java.util.MissingResourceException' in icu4j.dll". ) I guess I can 
> manually load a bunch of classes and maybe get it to work, however, I 
> would think this is not the way to go.
> 
> Thanks,
> Best regards,
> Steven.
> 
> ----------------------------------------------------------------------
> --
> ------
> _______________________________________________
> Ikvm-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ikvm-developers

------------------------------------------------------------------------------