Re: Reading Manifest from DLL

Phil Martin <[email protected]> Tue, 10 Oct 2017 11:34:02 -0400
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CAGwGAj_z=DNFxP4WOeEQkNQ1BSQzZW=AebFWm2WHicD_YLdwpA@mail.gmail.com>
--===============6872628504153103833==
Content-Type: multipart/alternative; boundary="94eb2c05afde703711055b33091c"

--94eb2c05afde703711055b33091c
Content-Type: text/plain; charset="UTF-8"

The JAR and everything it contains is definitely packaged inside the DLL
under a directory called Resources. I validated this using JustDecompile.

And the log output from the application shows that it's looking inside the
DLL for the JAR file contents:

JAR URL =
jar:file:/C:/pmart01/TCPI/Workspaces/VisualStudio/TCPI-Sample-Net/TCPI-Sample-Net/bin/Debug/tcpi.DLL!/

I did try rebuilding with the classloader option you suggested and adding
the programmatic setting of the classpath, and the observed behavior is the
same.

On Oct 6, 2017 5:23 PM, "Paul Chambre" <[email protected]> wrote:

> I don't think resource files are included in the ikvmc dlls - though it's
> not unlikely that I'm wrong.
>
> What you can do for sure is compile your dll with the
> -classloader:ikvm.runtime.ClassPathAssemblyClassLoader option. And then
> set the classpath in your C# app using:
>
> java.lang.System.setProperty("java.class.path",[expanded list of all jar
> files needed for the runtime and any other directories that contain
> resources or java classes, separated by semi-colons]);
>
> You can either use your original jar there, or create a new jar with just
> the resources, or probably have the manifest file somewhere and the path to
> it included here. This classpath is then used by the class loader for code
> running from the ikvmc dll.
>
> Hope this helps,
> Paul
>
> On Fri, Oct 6, 2017 at 2:39 PM, Phil Martin <[email protected]>
> wrote:
>
>>
>> I am new to IKVM, and very pleased with it so far.
>>
>> I am using it to wrap a vendor-supplied Java-only client API. When I run
>> the delivered JAR and class files using ikvm.exe in place of java.exe, the
>> client API and supplied sample client application behave exactly as
>> expected. However, when I use ikvmc to change the client API JAR to a .Net
>> DLL, I have just one issue.
>>
>> The client API reads version information from the MANIFEST.MF file in the
>> JAR to choose the specific version & concrete classes to instantiate at
>> initialization time. This operation works just fine when running from the
>> JAR, but fails when using the DLL in the context of my .Net client
>> application.
>>
>> For reference, here are the contents of the MANIFEST.MF file. I'm not
>> clear on how to check to confirm that it has found its way into my new DLL:
>>
>> Manifest-Version: 1.0
>> Ant-Version: Apache Ant 1.5.3
>> Created-By: Apache Maven
>> Built-By: arao
>> Package: com.fxall
>> Build-Jdk: 1.6.0_35
>> Extension-Name: tcpi
>> Specification-Title:
>> Specification-Vendor: FX Alliance, LLC
>> Implementation-Title: com.fxall
>> Implementation-Vendor: FX Alliance, LLC
>> Implementation-Version: 4.0.0.1
>> Main-Class: com.fxall.tcpi.TCPIVersion
>> Build-Time: 12/12/2012 06:19 PM
>> Build-Number: 49
>> api-version: 3.3
>> release-version: 4.1.0.1
>>
>>
>> The log output from the successful run includes this line, which matches
>> up with the specified value for "release-version:" in MANIFEST.MF:
>> *****
>> INFO: FXall TCPI Version: 4.1.0.1
>> *****
>>
>> While the log output from the failed run includes the following, which
>> seems to indicate that it's not finding the MANIFEST.MF file in the
>> JAR-converted-to-DLL:
>> *****
>> java.util.zip.ZipException: error in opening zip file
>>         at java.util.zip.ZipFile$PartialInputStream.seekEndOfCentralDir
>> ectory(ZipFile.java:629)
>>         at java.util.zip.ZipFile.readEntries(ZipFile.java:243)
>>         at java.util.zip.ZipFile.<init>(ZipFile.java:200)
>>         at java.util.zip.ZipFile.<init>(ZipFile.java:163)
>>         at java.util.jar.JarFile.<init>(JarFile.java:166)
>>         at java.util.jar.JarFile.<init>(JarFile.java:103)
>>         at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:93)
>>         at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.
>> java:69)
>>         at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.
>> java:105)
>>         at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConn
>> ection.java:122)
>>         at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLC
>> onnection.java:89)
>>         at java.net.JarURLConnection.getManifest(JarURLConnection.java:
>> 231)
>>         at com.fxall.tcpi.TCPIVersion.<clinit>(TCPIVersion.java:25)
>>         at com.fxall.tcpi.TCPIVersion.getVersion(TCPIVersion.java)
>>         at com.fxall.provider.CCPInterfaceConnection.<clinit>(CCPInterf
>> aceConnection.java:78)
>>         at com.fxall.provider.AdvancedInterfaceConnection.<clinit>(Adva
>> ncedInterfaceConnection.java:19)
>>         at com.fxall.provider.AdvancedInterfaceConnection.<init>(Advanc
>> edInterfaceConnection.java)
>>         at cli.TCPI_Sample_Net.Program.Main(Program.cs:41)
>>         at cli.System.AppDomain._nExecuteAssembly(Unknown Source)
>>         at cli.System.AppDomain.ExecuteAssembly(Unknown Source)
>>         at cli.Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly(Unknown
>> Source)
>> JAR URL = jar:file:/C:/pmart01/TCPI/Workspaces/VisualStudio/TCPI-Sampl
>> e-Net/TCPI-Sample-Net/bin/Debug/tcpi.DLL!/
>> Default to Version : 3.3 Build : 3.3.2
>> INFO: FXall TCPI Version: 3.3.2
>> *****
>>
>>
>> I have used JustDecompile by Telerik to validate that the original
>> tcpi.jar file and its META-INF/MANIFEST.MF file are saved under a folder
>> called "Resources" in the new tcpi.dll file. Note that I have validated
>> that the file can be found in the location indicated in the JAR URL output
>> above:
>>
>> *****
>> C:\pmart01 >dir C:\pmart01\TCPI\Workspaces\Vis
>> ualStudio\TCPI-Sample-Net\TCPI-Sample-Net\bin\Debug\tcpi.DLL
>>  Volume in drive C has no label.
>>  Volume Serial Number is 54EE-057C
>>
>>  Directory of C:\pmart01\TCPI\Workspaces\Vis
>> ualStudio\TCPI-Sample-Net\TCPI-Sample-Net\bin\Debug
>>
>> 10/06/2017  11:31 AM         3,654,144 tcpi.dll
>>                1 File(s)      3,654,144 bytes
>>                0 Dir(s)  11,206,111,232 bytes free
>> *****
>>
>> This seems like a pretty common use case, so I assume I'm just missing
>> something simple. Any advice or information would be very much appreciated.
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Ikvm-developers mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/ikvm-developers
>>
>>
>
>
> --
> Paul Chambre
>
> Senior Solutions Architect
> (719) 465-6097
>
> Illumon - Big Value From Big Data
>

--94eb2c05afde703711055b33091c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">The JAR and everything it contains is definitely packaged=
 inside the DLL under a directory called Resources. I validated this using =
JustDecompile.<div dir=3D"auto"><br></div><div dir=3D"auto">And the log out=
put from the application shows that it&#39;s looking inside the DLL for the=
 JAR file contents:</div><div dir=3D"auto"><br></div><div dir=3D"auto">JAR =
URL =3D jar:file:/C:/pmart01/TCPI/Workspaces/VisualStudio/TCPI-Sample-Net/T=
CPI-Sample-Net/bin/Debug/tcpi.DLL!/<br></div><div dir=3D"auto"><br></div><d=
iv dir=3D"auto">I did try rebuilding with the classloader option you sugges=
ted and adding the programmatic setting of the classpath, and the observed =
behavior is the same.</div></div><div class=3D"gmail_extra"><br><div class=
=3D"gmail_quote">On Oct 6, 2017 5:23 PM, &quot;Paul Chambre&quot; &lt;<a hr=
ef=3D"mailto:[email protected]">[email protected]</a>&gt; wrote=
:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=3D"margin=
:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">I=
 don&#39;t think resource files are included in the ikvmc dlls - though it&=
#39;s not unlikely that I&#39;m wrong.=C2=A0<div><br></div><div>What you ca=
n do for sure is compile your dll with the=C2=A0<span style=3D"font-family:=
&quot;Courier New&quot;,monospace">-classloader:ikvm.runtime.<wbr>ClassPath=
AssemblyClassLoader=C2=A0</span>o<wbr>ption. And then set the classpath in =
your C# app using:</div><div><br></div><div><span style=3D"font-family:&quo=
t;Courier New&quot;,monospace">java.lang.System.setProperty(&quot;<wbr>java=
.class.path&quot;,[expanded
	list of all jar files needed for the runtime and any other
	directories that contain resources or java classes, separated by
	semi-colons]);</span></div><div><div><font face=3D"Courier New, monospace"=
><br></font></div></div><div>You can either use your original jar there, or=
 create a new jar with just the resources, or probably have the manifest fi=
le somewhere and the path to it included here. This classpath is then used =
by the class loader for code running from the ikvmc dll.<font face=3D"Couri=
er New, monospace"><br></font></div><div><br></div><div>Hope this helps,</d=
iv><div>Paul</div>
=09
=09
=09


</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Oct=
 6, 2017 at 2:39 PM, Phil Martin <span dir=3D"ltr">&lt;<a href=3D"mailto:ph=
[email protected]" target=3D"_blank">[email protected]</a>&gt=
;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div di=
r=3D"auto"><br></div><div dir=3D"auto">I am new to IKVM, and very pleased w=
ith it so far.</div><div dir=3D"auto"><br></div><div dir=3D"auto">I am usin=
g it to wrap a vendor-supplied Java-only client API. When I run the deliver=
ed JAR and class files using ikvm.exe in place of java.exe, the client API =
and supplied sample client application behave exactly as expected. However,=
 when I use ikvmc to change the client API JAR to a .Net DLL, I have just o=
ne issue.</div><div dir=3D"auto"><br></div><div dir=3D"auto">The client API=
 reads version information from the MANIFEST.MF file in the JAR to choose t=
he specific version &amp; concrete classes to instantiate at initialization=
 time. This operation works just fine when running from the JAR, but fails =
when using the DLL in the context of my .Net client application.</div><div =
dir=3D"auto"><br></div><div dir=3D"auto">For reference, here are the conten=
ts of the MANIFEST.MF file. I&#39;m not clear on how to check to confirm th=
at it has found its way into my new DLL:</div><div dir=3D"auto"><br></div><=
div dir=3D"auto">Manifest-Version: 1.0</div><div dir=3D"auto">Ant-Version: =
Apache Ant 1.5.3</div><div dir=3D"auto">Created-By: Apache Maven</div><div =
dir=3D"auto">Built-By: arao</div><div dir=3D"auto">Package: com.fxall</div>=
<div dir=3D"auto">Build-Jdk: 1.6.0_35</div><div dir=3D"auto">Extension-Name=
: tcpi</div><div dir=3D"auto">Specification-Title:</div><div dir=3D"auto">S=
pecification-Vendor: FX Alliance, LLC</div><div dir=3D"auto">Implementation=
-Title: com.fxall</div><div dir=3D"auto">Implementation-Vendor: FX Alliance=
, LLC</div><div dir=3D"auto">Implementation-Version: 4.0.0.1</div><div dir=
=3D"auto">Main-Class: com.fxall.tcpi.TCPIVersion</div><div dir=3D"auto">Bui=
ld-Time: 12/12/2012 06:19 PM</div><div dir=3D"auto">Build-Number: 49</div><=
div dir=3D"auto">api-version: 3.3</div><div dir=3D"auto">release-version: 4=
.1.0.1</div><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div di=
r=3D"auto">The log output from the successful run includes this line, which=
 matches up with the specified value for &quot;release-version:&quot; in MA=
NIFEST.MF:</div><div dir=3D"auto">*****</div><div dir=3D"auto">INFO: FXall =
TCPI Version: 4.1.0.1</div><div dir=3D"auto">*****</div><div dir=3D"auto"><=
br></div><div dir=3D"auto">While the log output from the failed run include=
s the following, which seems to indicate that it&#39;s not finding the MANI=
FEST.MF file in the JAR-converted-to-DLL:</div><div dir=3D"auto">*****</div=
><div dir=3D"auto">java.util.zip.ZipException: error in opening zip file</d=
iv><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.zip.ZipFile$P=
artialI<wbr>nputStream.seekEndOfCentralDir<wbr>ectory(ZipFile.java:629)</di=
v><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.zip.ZipFile.re=
adEntr<wbr>ies(ZipFile.java:243)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 at java.util.zip.ZipFile.&lt;init&gt;(Z<wbr>ipFile.java:200)</di=
v><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.zip.ZipFile.&l=
t;init&gt;(Z<wbr>ipFile.java:163)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 at java.util.jar.JarFile.&lt;init&gt;(J<wbr>arFile.java:166)</di=
v><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.jar.JarFile.&l=
t;init&gt;(J<wbr>arFile.java:103)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 at sun.net.www.protocol.jar.URLJa<wbr>rFile.&lt;init&gt;(URLJarF=
ile.java:<wbr>93)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun=
.net.www.protocol.jar.URLJa<wbr>rFile.getJarFile(URLJarFile.<wbr>java:69)</=
div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protocol.j=
ar.JarFi<wbr>leFactory.get(JarFileFactory.<wbr>java:105)</div><div dir=3D"a=
uto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protocol.jar.JarUR<wbr>LCon=
nection.connect(JarURLConn<wbr>ection.java:122)</div><div dir=3D"auto">=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protocol.jar.JarUR<wbr>LConnection.=
getJarFile(JarURLC<wbr>onnection.java:89)</div><div dir=3D"auto">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 at java.net.JarURLConnection.getM<wbr>anifest(JarURLConne=
ction.java:<wbr>231)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at =
com.fxall.tcpi.TCPIVersion.&lt;cl<wbr>init&gt;(TCPIVersion.java:25)</div><d=
iv dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at com.fxall.tcpi.TCPIVersion.g=
et<wbr>Version(TCPIVersion.java)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 at com.fxall.provider.CCPInterfac<wbr>eConnection.&lt;clinit&gt;=
(CCPInterf<wbr>aceConnection.java:78)</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 at com.fxall.provider.AdvancedInt<wbr>erfaceConnection.&lt;cl=
init&gt;(Adva<wbr>ncedInterfaceConnection.java:<wbr>19)</div><div dir=3D"au=
to">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at com.fxall.provider.AdvancedInt<wbr>erfac=
eConnection.&lt;init&gt;(Advanc<wbr>edInterfaceConnection.java)</div><div d=
ir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at <a href=3D"http://cli.TCPI_Sampl=
e_Net.Program.Ma">cli.TCPI_Sample_Net.Program.Ma</a><wbr>in(Program.cs:41)<=
/div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli.System.AppDomain.=
_nExecute<wbr>Assembly(Unknown Source)</div><div dir=3D"auto">=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 at cli.System.AppDomain.ExecuteAs<wbr>sembly(Unknown Source)=
</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli.Microsoft.Visual=
Studio.Hos<wbr>tingProcess.HostProc.RunUsersA<wbr>ssembly(Unknown Source)</=
div><div dir=3D"auto">JAR URL =3D jar:file:/C:/pmart01/TCPI/Work<wbr>spaces=
/VisualStudio/TCPI-Sampl<wbr>e-Net/TCPI-Sample-Net/bin/<wbr>Debug/tcpi.DLL!=
/</div><div dir=3D"auto">Default to Version : 3.3 Build : 3.3.2</div><div d=
ir=3D"auto">INFO: FXall TCPI Version: 3.3.2</div><div dir=3D"auto">*****</d=
iv><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto=
">I have used JustDecompile by Telerik to validate that the original tcpi.j=
ar file and its META-INF/MANIFEST.MF file are saved under a folder called &=
quot;Resources&quot; in the new tcpi.dll file. Note that I have validated t=
hat the file can be found in the location indicated in the JAR URL output a=
bove:</div><div dir=3D"auto"><br></div><div dir=3D"auto">*****</div><div di=
r=3D"auto">C:\pmart01 &gt;dir C:\pmart01\TCPI\Workspaces\Vis<wbr>ualStudio\=
TCPI-Sample-Net\TCPI<wbr>-Sample-Net\bin\Debug\tcpi.DLL</div><div dir=3D"au=
to">=C2=A0Volume in drive C has no label.</div><div dir=3D"auto">=C2=A0Volu=
me Serial Number is 54EE-057C</div><div dir=3D"auto"><br></div><div dir=3D"=
auto">=C2=A0Directory of C:\pmart01\TCPI\Workspaces\Vis<wbr>ualStudio\TCPI-=
Sample-Net\TCPI<wbr>-Sample-Net\bin\Debug</div><div dir=3D"auto"><br></div>=
<div dir=3D"auto">10/06/2017=C2=A0 11:31 AM=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A03,654,144 tcpi.dll</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A01 File(s)=C2=A0 =C2=A0 =C2=A0 3,654,144 bytes</d=
iv><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A00 Dir(s)=C2=A0 11,206,111,232 bytes free</div><div dir=3D"auto">*****</d=
iv><div dir=3D"auto"><br></div><div dir=3D"auto">This seems like a pretty c=
ommon use case, so I assume I&#39;m just missing something simple. Any advi=
ce or information would be very much appreciated.</div><div dir=3D"auto"><b=
r></div></div>
<br>------------------------------<wbr>------------------------------<wbr>-=
-----------------<br>
Check out the vibrant tech community on one of the world&#39;s most<br>
engaging tech sites, Slashdot.org! <a href=3D"http://sdm.link/slashdot" rel=
=3D"noreferrer" target=3D"_blank">http://sdm.link/slashdot</a><br>_________=
_____________________<wbr>_________________<br>
Ikvm-developers mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">=
[email protected]<wbr>rge.net</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/ikvm-developers" re=
l=3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists=
/listinfo/ikvm-developers</a><br>
<br></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div cla=
ss=3D"m_-4360679054234640802gmail_signature" data-smartmail=3D"gmail_signat=
ure"><div dir=3D"ltr"><div>Paul Chambre</div><div><br></div><div>Senior Sol=
utions Architect</div><div><a href=3D"tel:(719)%20465-6097" value=3D"+17194=
656097" target=3D"_blank">(719) 465-6097</a></div><div><br></div><div>Illum=
on - Big Value From Big Data</div></div></div>
</div>
</blockquote></div></div>

--94eb2c05afde703711055b33091c--


--===============6872628504153103833==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
--===============6872628504153103833==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers

--===============6872628504153103833==--