0

I want use execvp to invoke java to execute a function, like the code below :

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    char* const argv[]= {
                        "-mx300m","-cp","\'stanford-postagger.jar:/root/NLP/postagger/:.\'",
                        "edu.stanford.nlp.tagger.maxent.MaxentTagger",
                        " -model","/root/NLP/postagger/models/english-bidirectional-distsim.tagger",
                        "-textFile","/root/NLP/postagger/sample-input.txt",
                        NULL
                    };

    execvp("java",argv);

    return 0;
}

but an error occurs:

Exception in thread "main" java.lang.NoClassDefFoundError: edu/stanford/nlp/tagger/maxent/MaxentTagger
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.tagger.maxent.MaxentTagger
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: edu.stanford.nlp.tagger.maxent.MaxentTagger. Program will exit.

Could anyone help me with this? Thanks very much :)

eddie
  • 1,252
  • 3
  • 15
  • 20
greatsea
  • 87
  • 1
  • 9
  • Looks like something is wrong with your class path. Have you checked that you have compiled the java classes / the classes are in your path? – TonioElGringo Nov 30 '12 at 05:59
  • Not really related to your error, but you need to put `"java"` as the first string in your `argv` array. The first element is the executable name, the arguments follow. – Xymostech Nov 30 '12 at 06:17

1 Answers1

0

remove excessive quotes \' in the -cp argument. It was needed when launched from shell script, and that script eventually stripped them.

Alexei Kaigorodov
  • 13,189
  • 1
  • 21
  • 38