简体   繁体   English

如何在Linux中使用C ++代码调用java -classpath

[英]how to call java -classpath with C++ code in linux

I've got a question when doing a project. 我在做项目时有一个问题。

I need to call a Java program in a C++ program, and it is in linux; 我需要在C ++程序中调用Java程序,它在Linux中。 and the Java program has a package, so that I have to set the Classpath for it. Java程序有一个包,因此我必须为其设置Classpath。

The problem is, I can't run the java program like this: 问题是,我不能像这样运行Java程序:

java -classpath Server/main/java/ Sever

But I can do this: 但是我可以这样做:

export CLASSPATH=$CLASSPATH:Server/main/java

java Sever

However, the strange thing is that if I try to call the java program in other dir, even export CLASSPATH don't work. 但是,奇怪的是,如果我尝试在其他目录中调用Java程序,那么即使导出CLASSPATH也无效。 (I've changed the CLASSPATH so that it match the current dir) (我更改了CLASSPATH,使其与当前目录匹配)

I don't know why. 我不知道为什么 I have to do system call in C program, so export Classpath won't work,(I don't know why). 我必须在C程序中进行系统调用,因此导出Classpath无法正常工作(我不知道为什么)。

You are setting a relative path into your CLASSPATH that gets interpreted differently, depending on where you launch your program from. 您正在CLASSPATH中设置一个相对路径,该路径的解释方式会有所不同,具体取决于从何处启动程序。 Use fully qualified paths instead. 请改用标准路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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