Re: Reading Manifest from DLL

Paul Chambre <[email protected]> Fri, 6 Oct 2017 15:23:04 -0600
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CAJwVo5FyoK3Fbqffc6-iB=0zYLvGCHjwb2ZOa3DNXXycGatj-A@mail.gmail.com>
--===============3854038600945238461==
Content-Type: multipart/alternative; boundary="001a113f77ba4b0c71055ae7721d"

--001a113f77ba4b0c71055ae7721d
Content-Type: text/plain; charset="UTF-8"

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.
> seekEndOfCentralDirectory(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(
> JarURLConnection.java:122)
>         at sun.net.www.protocol.jar.JarURLConnection.getJarFile(
> JarURLConnection.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>(
> CCPInterfaceConnection.java:78)
>         at com.fxall.provider.AdvancedInterfaceConnection.<clinit>(
> AdvancedInterfaceConnection.java:19)
>         at com.fxall.provider.AdvancedInterfaceConnection.<init>(
> AdvancedInterfaceConnection.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-
> Sample-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\VisualStudio\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\VisualStudio\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

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

<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></di=
v><div>What you can do for sure is compile your dll with the=C2=A0<span sty=
le=3D"font-family:&quot;Courier New&quot;,monospace">-classloader:ikvm.runt=
ime.ClassPathAssemblyClassLoader=C2=A0</span>option. And then set the class=
path in your C# app using:</div><div><br></div><div><span style=3D"font-fam=
ily:&quot;Courier New&quot;,monospace">java.lang.System.setProperty(&quot;j=
ava.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$<=
wbr>PartialInputStream.<wbr>seekEndOfCentralDirectory(<wbr>ZipFile.java:629=
)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.zip.ZipFi=
le.<wbr>readEntries(ZipFile.java:243)</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 at java.util.zip.ZipFile.&lt;init&gt;(<wbr>ZipFile.java:200)<=
/div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.zip.ZipFile=
.&lt;init&gt;(<wbr>ZipFile.java:163)</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 at java.util.jar.JarFile.&lt;init&gt;(<wbr>JarFile.java:166)<=
/div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at java.util.jar.JarFile=
.&lt;init&gt;(<wbr>JarFile.java:103)</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 at sun.net.www.protocol.jar.<wbr>URLJarFile.&lt;init&gt;(URLJ=
arFile.<wbr>java:93)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at =
sun.net.www.protocol.jar.<wbr>URLJarFile.getJarFile(<wbr>URLJarFile.java:69=
)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protoco=
l.jar.<wbr>JarFileFactory.get(<wbr>JarFileFactory.java:105)</div><div dir=
=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protocol.jar.<wbr>JarU=
RLConnection.connect(<wbr>JarURLConnection.java:122)</div><div dir=3D"auto"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 at sun.net.www.protocol.jar.<wbr>JarURLConnect=
ion.getJarFile(<wbr>JarURLConnection.java:89)</div><div dir=3D"auto">=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 at java.net.JarURLConnection.<wbr>getManifest(JarURLC=
onnection.<wbr>java:231)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 at com.fxall.tcpi.TCPIVersion.&lt;<wbr>clinit&gt;(TCPIVersion.java:25)</di=
v><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at com.fxall.tcpi.TCPIVersi=
on.<wbr>getVersion(TCPIVersion.java)</div><div dir=3D"auto">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 at com.fxall.provider.<wbr>CCPInterfaceConnection.&lt;<wbr>cl=
init&gt;(<wbr>CCPInterfaceConnection.java:<wbr>78)</div><div dir=3D"auto">=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 at com.fxall.provider.<wbr>AdvancedInterfaceCon=
nection.&lt;<wbr>clinit&gt;(<wbr>AdvancedInterfaceConnection.<wbr>java:19)<=
/div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at com.fxall.provider.<w=
br>AdvancedInterfaceConnection.&lt;<wbr>init&gt;(<wbr>AdvancedInterfaceConn=
ection.<wbr>java)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli=
.TCPI_Sample_Net.Program.<wbr>Main(Program.cs:41)</div><div dir=3D"auto">=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli.System.AppDomain._<wbr>nExecuteAssembly(=
Unknown Source)</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli.S=
ystem.AppDomain.<wbr>ExecuteAssembly(Unknown Source)</div><div dir=3D"auto"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 at cli.Microsoft.VisualStudio.<wbr>HostingProc=
ess.HostProc.<wbr>RunUsersAssembly(Unknown Source)</div><div dir=3D"auto">J=
AR URL =3D jar:file:/C:/pmart01/TCPI/<wbr>Workspaces/VisualStudio/TCPI-<wbr=
>Sample-Net/TCPI-Sample-Net/<wbr>bin/Debug/tcpi.DLL!/</div><div dir=3D"auto=
">Default to Version : 3.3 Build : 3.3.2</div><div dir=3D"auto">INFO: FXall=
 TCPI Version: 3.3.2</div><div dir=3D"auto">*****</div><div dir=3D"auto"><b=
r></div><div dir=3D"auto"><br></div><div dir=3D"auto">I have used JustDecom=
pile by Telerik to validate that the original tcpi.jar file and its META-IN=
F/MANIFEST.MF file are saved under a folder called &quot;Resources&quot; in=
 the new tcpi.dll file. Note that I have validated that the file can be fou=
nd in the location indicated in the JAR URL output above:</div><div dir=3D"=
auto"><br></div><div dir=3D"auto">*****</div><div dir=3D"auto">C:\pmart01 &=
gt;dir C:\pmart01\TCPI\Workspaces\<wbr>VisualStudio\TCPI-Sample-Net\<wbr>TC=
PI-Sample-Net\bin\Debug\<wbr>tcpi.DLL</div><div dir=3D"auto">=C2=A0Volume i=
n drive C has no label.</div><div dir=3D"auto">=C2=A0Volume Serial Number i=
s 54EE-057C</div><div dir=3D"auto"><br></div><div dir=3D"auto">=C2=A0Direct=
ory of C:\pmart01\TCPI\Workspaces\<wbr>VisualStudio\TCPI-Sample-Net\<wbr>TC=
PI-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.d=
ll</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</div><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,20=
6,111,232 bytes free</div><div dir=3D"auto">*****</div><div dir=3D"auto"><b=
r></div><div dir=3D"auto">This seems like a pretty common use case, so I as=
sume I&#39;m just missing something simple. Any advice or information would=
 be very much appreciated.</div><div dir=3D"auto"><br></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]">Ikvm-developers@li=
sts.<wbr>sourceforge.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"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr">=
<div>Paul Chambre</div><div><br></div><div>Senior Solutions Architect</div>=
<div>(719) 465-6097</div><div><br></div><div>Illumon - Big Value From Big D=
ata</div></div></div>
</div>

--001a113f77ba4b0c71055ae7721d--


--===============3854038600945238461==
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
--===============3854038600945238461==
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

--===============3854038600945238461==--