2

I have a C# class library that is running a jarFile

string args="java -jar jar.jar...";
ProcessStartInfo startInfo = new ProcessStartInfo("java.exe", args);
Process runProc = Process.Start(startInfo);

But when using the dll from application I found that I must place the jar file in the application's working directory or to specify full path.

I don't like both of the option- absulote path is bad, and asking user to copy a jar file to his working directory in order to use the dll is not comfortable.

Is there is some alternative, some way of embedding the jar file to the class library?

sara
  • 3,824
  • 9
  • 43
  • 71

4 Answers4

6

You can add the jar file to your project and in the file properties set it to content and Copy if newer.

This will copy it to the output folder during compilation and ensure it is distributed with the application.

An alternative is to embed the file as a resource - this makes it part of the application executable and let you access it within the application. In order to execute it separately, however, you will need to extract it and save to a file.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

If I was in this situation I would try to add *.jar file like Resouce. Cheers.

ikirachen
  • 77
  • 7
0

Have a look at IVKM.Net.

You can find it here (Scurial's answer)

Community
  • 1
  • 1
chaosr
  • 494
  • 2
  • 6
  • 17
0

you could embed the jar in the class library as an embedded resource.

then when you need the jar, read it out and write it to a local file.

see this other stackoverflow question on reading an embedded resource out and writing to file

Community
  • 1
  • 1
Steve Casey
  • 9,966
  • 1
  • 20
  • 24