简体   繁体   中英

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; and the Java program has a package, so that I have to set the Classpath for it.

The problem is, I can't run the java program like this:

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. (I've changed the CLASSPATH so that it match the current dir)

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).

You are setting a relative path into your CLASSPATH that gets interpreted differently, depending on where you launch your program from. Use fully qualified paths instead.

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