Lelo Lelo - 1 year ago 79
Java Question

Use class path properly in Java in command line

I'm newbie to Java. I have read all the documentations regarding specifing the classpath. But I'm still confused about my case. I'm trying to use the BuildIndex command that is part of semantic package, specifically this example,

java pitt.search.semanticvectors.BuildIndex -luceneindexpath $INDEX_MADE_ABOVE.

in here

The source of how to use the class is here https://github.com/semanticvectors/semanticvectors/wiki/InstallationInstructions#to-build-and-search-a-model

I'm trying to specify the classpath like:

java cp- {classpath} pitt.search.semanticvectors.BuildIndex -luceneindexpath $INDEX_MADE_ABOVE.
in here

But I'm not sure what the class path should be here. . The command line should have a class path, but thinking it should not be related to my project, it's part of the semantic vectors package. Do I need to clone that? its source code from the package here https://github.com/semanticvectors/semanticvectors/blob/master/src/main/java/pitt/search/semanticvectors/BuildIndex.java..

My trials was using the path of my project as the picture but didn't work. Another trial was using
-jar jarName
,, got the same error:
Could not find or load main class pitt.search.semanticvectors.BuildIndex
. I appreciate the help as I'm confused and new to this.

Answer Source

In Java, classpath is the path pointing to either the directory or the jar file where your compiled java class files are located.

In your project, the class pitt.search.semanticvectors.BuildIndex is located in the jar file C:\Users\A6B0SZZ\Downloads\semanticvectors-5.8.jar. Therefore, the classpath is C:\Users\A6B0SZZ\Downloads\semanticvectors-5.8.jar.

Try something like

java -cp C:\Users\A6B0SZZ\Downloads\semanticvectors-5.8.jar pitt.search.semanticvectors.BuildIndex -luceneindexpath $INDEX_MADE_ABOVE

I think you mistyped cp- instead of -cp.

For more details how to use classpath, please refer to Java SE Documentation

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download