0

I have a maven project (folder ev) and I want to run a java class (ChargerLocation.java) from the cmd. I 've tried the link but didn't work. When I run the ChargerLocation.java from Eclipse it works but I want to run it from the cmd. It looks like that I should be able to run by: Run Configurations->Show Command Line and paste that in my cmd, however I get the following error'-classpath' is not recognized as an internal or external command, operable program or batch file.

  1. In order to do the: Run Configurations->Show Command Line-> paste in cmd, in which folder should I be located?

  2. I was wondering whether the command at the cmd should be something like Maven/apache-maven-3.6.3/bin/mvn exec:java -Dexec.mainClass="" since it's a maven project as a whole? Or it doesn't matter?

  3. By simply doing javac ChargerLocation.java I get 45 errors which seem to be like it cannot find the proper libraries to build.

    ChargerLocation.java:14: error: package org.matsim.api.core.v01 does not exist import org.matsim.api.core.v01.Coord; ^ ChargerLocation.java:15: error: package org.matsim.api.core.v01 does not exist import org.matsim.api.core.v01.Id; ^ ChargerLocation.java:16: error: package org.matsim.api.core.v01 does not exist import org.matsim.api.core.v01.Scenario; ^ ChargerLocation.java:17: error: package org.matsim.api.core.v01.network does not exist import org.matsim.api.core.v01.network.Link; ^ ChargerLocation.java:18: error: package org.matsim.api.core.v01.network does not exist import org.matsim.api.core.v01.network.Network; ^ ChargerLocation.java:19: error: package org.matsim.contrib.ev.charging does not exist import org.matsim.contrib.ev.charging.ChargeUpToMaxSocStrategy; ^ ChargerLocation.java:20: error: package org.matsim.contrib.ev.charging does not exist import org.matsim.contrib.ev.charging.ChargingLogic; ^ ChargerLocation.java:21: error: package org.matsim.contrib.ev.charging does not exist import org.matsim.contrib.ev.charging.ChargingWithQueueingLogic; ^ ChargerLocation.java:22: error: package org.matsim.contrib.ev.infrastructure does not exist import org.matsim.contrib.ev.infrastructure.Charger; ^ ChargerLocation.java:23: error: package org.matsim.contrib.ev.infrastructure does not exist import org.matsim.contrib.ev.infrastructure.ChargerImpl; ^ ChargerLocation.java:24: error: package org.matsim.contrib.ev.infrastructure does not exist import org.matsim.contrib.ev.infrastructure.ChargerSpecification; ^ ChargerLocation.java:25: error: package org.matsim.contrib.ev.infrastructure does not exist import org.matsim.contrib.ev.infrastructure.ChargerWriter; ^ ChargerLocation.java:26: error: package org.matsim.contrib.ev.infrastructure does not exist import org.matsim.contrib.ev.infrastructure.ImmutableChargerSpecification; ^ ChargerLocation.java:27: error: package org.matsim.core.config does not exist import org.matsim.core.config.Config;

I also attach a photo of my folders in eclipse.enter image description here

  1. Finally, I want to call this java file from Python, so what I am trying to do here is: open cmd from Python (os.system()) with pre-written command to call java Class (ChargerLocation.java) and finally run the java class.

Thanks in advance

user3474218
  • 51
  • 1
  • 7
  • The mentioned link points to a question for which the [right answer is this one](https://stackoverflow.com/a/58934945/6505250). – howlger Apr 01 '21 at 14:24
  • @howlger The problem is that when copy-paste the command on cmd it doesn't paste the whole command because it seems like cmd doesn't allow to put over 8191 characters. The command that I get from eclipse is almost 10000 characters. Is there any other way I could run that on cmd? – user3474218 Apr 02 '21 at 12:02
  • So you are on Windows (on other OSs there are no such limit). For Java 9 or higher you can use an @argfile (for Java 8 and lower a temporary JAR file can be used as workaround instead): https://www.eclipse.org/eclipse/news/4.18/jdt.php#launch-with-argfile – howlger Apr 02 '21 at 12:16
  • @howlger please see the photo attached below. – user3474218 Apr 02 '21 at 12:25

1 Answers1

0

@howlger here is the command line I get from eclipse. It's not the arguments that increase the number of characters but the different jar libraries that needs to be build first before running my main java file org.matsim.contrib.ev.example.ChargerLocation

As far as I understand the argfile is to write arguments, which in my case there aren't any.

Command Line from eclipse

user3474218
  • 51
  • 1
  • 7
  • [The @argfile is for all java(w).exe arguments, including the classpath or modulepath](https://docs.oracle.com/en/java/javase/15/docs/specs/man/java.html#java-command-line-argument-files) (in your screenshot, for all except the first line). Tick the [checkbox](https://www.eclipse.org/eclipse/news/4.18/jdt.php#launch-with-argfile) to let Eclipse generate the @argfile for you. By the way, in your case (running it on the command line) you probably want to change `javaw.exe` to `java.exe`. – howlger Apr 02 '21 at 12:40
  • @howlger thank you so very much! I am new in eclipse and java and I spend so many hours looking on that. It perfectly works. So, now that I want to take it one step further, I want to be able to call this from some external source, that being Python. I should be able to do: `subprocess.run(["cd C:/Program Files/Java/jdk-11.0.10/bin", "java.exe "@C:\Users\danie\IdeaProjects\EV_example\EV_example\matsim-libs\contribs\ev\.temp-ChargerLocation-args-1617369242656.txt""])` – user3474218 Apr 02 '21 at 13:13