-3

I was able to compile and run my java code from CMD, however when I try to run the same commands in PS, I am getting error messages. I have read and been told that CMD commands will work in PS, but the CMD commands are not working in PS

Here is the line that I am using to execute my program:

java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP

I am running the command from the directory where my needed JAR files are located. The error message says...

The command stanford-corenlp-3.8.0-models.jar was not found, but does exist 
in the current location. Windows PowerShell does not load commands from the 
current If you trust this command, instead type: ".\stanford-corenlp-3.8.0-
models.jar".

Made the change and the code looks like this now.

java -classpath .\;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP

Still getting the exact same error message. I have also tried going up a directory and no luck. I have looked all over StackOverflow and I have done my research.

Any help would be much appreciated. Thanks.

  • 1
    What package is you class in? – Usagi Miyamoto Jul 14 '17 at 13:26
  • So in your first paragraph you say, that the same command worked in PowerShell, but in the second paragraph you say a) You used **different** commands in CMD, and b) they didn't work either. Get your facts straight. And.. add . to your classpath when you run. That has nothing to do at all with CMD or Powershell: `java -cp .\stanford-corenlp-3.8.0.jar:. TestCoreNLP` – Erwin Bolwidt Jul 14 '17 at 13:29
  • @Usagi Miyamoto my class is in package Test, which is the directory that I am running the commands from. – Forrest Hunter Jul 14 '17 at 13:42
  • You should go a folder up, and run `java -cp .;Test\stanford-corenlp-3.8.0.jar Test.TestCoreNLP` – Usagi Miyamoto Jul 14 '17 at 13:46
  • I ran the command and still nothing, instead I got an error message about the usage of the java command. I played around with the syntax a little so it looked like this...java -cp .\Test\stanford-corenlp-3.8.0.jar TestCoreNLP and I am still getting the error...Could not find or load main class TestCoreNLP (sorry, I am not sure how to make the code and error message stand out) – Forrest Hunter Jul 14 '17 at 13:51
  • Your command prompt path most likely has special environmental variables configured by the Java SDK install. Specifically, you should have one for Java path or something like that. These don't exist in PowerShell. – FoxDeploy Jul 14 '17 at 14:17
  • I made a few changes to my question in order to make it more clear, sorry for the ambiguity prior. – Forrest Hunter Jul 14 '17 at 14:38
  • You can test whether @FoxDeploy is right by opening your `cmd.exe` prompt (where compiling works) and start a PowerShell instance _from_ that `cmd.exe` instance. This will cause the PowerShell instance to inherit the environment variables from the `cmd.exe` instance. – Bill_Stewart Jul 14 '17 at 14:38
  • Try adding the current directory to the `Path` and see if that works; e.g. `$Env:Path = ".;$Env:Path"`. – Bill_Stewart Jul 14 '17 at 14:44
  • I opened a powershell window form CMD and ran my command. Still getting the same error unfortunately. Thank you for your input though! – Forrest Hunter Jul 14 '17 at 14:47
  • From your error, the problem isn't environment variables but rather than PowerShell doesn't execute from the current directory by default. Try adding `.` to the front of your `Path` as I noted in my earlier comment (this is implicit in `cmd.exe`, but not PowerShell). – Bill_Stewart Jul 14 '17 at 15:17
  • Here is the command that I ran `java -cp .\stanford-corenlp-3.8.0.jar .\Test\TestCoreNLP` which is being ran from the directory where the jar is located. `Error: Could not find or load main class .\Test\TestCoreNLP` – Forrest Hunter Jul 14 '17 at 15:26

2 Answers2

0

Using .\ would work for one file, but since you have a number of files, you should reference the current directory in each one of those files.

java -classpath .\stanford-corenlp-3.8.0.jar;.\stanford-corenlp-3.8.0-javadoc.jar;.\stanford-corenlp-3.8.0-models.jar;.\stanford-corenlp-3.8.0-models.jar .\Test.TestCoreNLP

Java 6 also supports wildcards, as this answer indicates, so you might try simply this.

java -cp ".\*" .\Test.TestCoreNLP
FoxDeploy
  • 9,619
  • 2
  • 26
  • 41
  • Hey @FoxDeploy. I tried both the first and second suggestion, although I did have somewhat better luck with the second suggestion. Regardless, still seems that it doesn't like that code. I am still getting an error. `java: Error: Could not find or load main class Test.TestCoreNLP` Any other last thoughts on what might be the cause? I feel like it is something really simple, although it seems I have tried everything. – Forrest Hunter Jul 18 '17 at 14:25
  • Oh wow, you might need to specify the path of `.\Test.TestCoreNLP`. Try by update – FoxDeploy Jul 18 '17 at 15:16
0

I came here with similar trouble, and what I found is that when running like this:

java -cp .\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar com.ethoca.app.myapp

I would get help info. My discovery is that I need to double-quote my list of classpath, like:

java -cp ".\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar" com.ethoca.app.myapp
Adam Cox
  • 2,423
  • 1
  • 22
  • 33