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?

1
  • not quite sure but you may add the jar as resource
    – chaosr
    Jan 18, 2012 at 10:22

4 Answers 4

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.

0

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

0

Have a look at IVKM.Net.

You can find it here (Scurial's answer)

1
  • What's IKVM.NET got to do with the question?
    – Oded
    Jan 18, 2012 at 10:29
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.