简体   繁体   中英

Jar file classpath problems

我正在开发一个C#应用程序,该应用程序可以访问控制台以运行java命令并执行特定的jar,但是当我运行该程序时,正在执行的jar文件会在程序输出中生成他的文件,例如日志和配置,但是我想运行问题:我尝试了许多Java参数,但是从jar生成的输出文件每次都从我的visual studio项目转到我的Debug文件夹中。希望有人能理解我,我很困惑和抱歉我的英语是巴西语。谢谢您的支持!

I can only guess, because the lines of code are missing that you use to invoke the java program from within your C# program. It is also unclear what exactly you are trying to achieve. Decide between changing the "current work directory" in the child or in the main process.

child process

I assume you want to execute something like this java -jar path\\to\\some.jar using code similar to this:

using System.Diagnostics;
//...

ProcessStartInfo p = new ProcessStartInfo();
p.Arguments = new string[]{"-jar", "path\to\some.jar"; 
p.FileName = "java.exe";
p.WindowStyle = ProcessWindowStyle.Hidden;
p.CreateNoWindow = true;

using (Process proc = Process.Start(start))
{
     proc.WaitForExit();
}

Adapted from here

Then you can just add this line

p.WorkingDirectory = "path\to";

Adapted from here

to setup your child process covered by the p instance with a specific current work directory. This will set the current work directory for the invocation of your java child process.

main process

To setup the current work directory for the surrounding main process add this line to your program:

System.IO.Directory.SetCurrentDirectory("some\other\path");

MSDN Documentation for SetCurrentDirectory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM