question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running programs from the command line

See original GitHub issue

When invoking jMetal programs from the command line I always have use de java command. My development machine is a MacBook, but I also have access to a Linux one and to a virtual machine with Windows 8.1 (with GitBash installed) to make some tests.

In the case of jMetal 5.0, I set first the CLASSPATH environment variable:

export CLASSPATH=jmetal-core/target/classes/:jmetal-exec/target/classes/:jmetal-problem/target/classes/:jmetal-algorithm/target/classes/

and then I write something like this:

java org.uma.jmetal.runner.multiobjective.SMPSORunner org.uma.jmetal.problem.multiobjective.Golinski

However, sometimes I have got runtime errors about missing libraries:

java org.uma.jmetal.qualityIndicator.CommandLineIndicatorRunner ALL jmetal-problem/src/test/resources/pareto_fronts/Kursawe.pf FUN.tsv 

The fronts are NOT NORMALIZED before computing the indicators
EP: 2799.499447785977
HV: 0.0
GD: 381.1994951105707
IGD: 102.76887872890298
IGD+: 3038.206812393222
SPREAD: 0.910670889364176
GSPREAD: 0.9045628203376009
R2: 1464.6004537062856
ER: 1.0
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/tuple/Pair
    at org.uma.jmetal.qualityIndicator.CommandLineIndicatorRunner.calculateAndPrintIndicators(CommandLineIndicatorRunner.java:131)
    at org.uma.jmetal.qualityIndicator.CommandLineIndicatorRunner.main(CommandLineIndicatorRunner.java:48)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.tuple.Pair
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

Any ideas about the reason of these kinds of errors? My concern is why a particular class (Pair) is not found while there are many other dependences.

I’ve tried the alternative of using mvn:

mvn -pl jmetal-exec exec:java -Dexec.mainClass="org.uma.jmetal.qualityIndicator.CommandLineIndicatorRunner" -Dexec.args="ALL jmetal-problem/src/test/resources/pareto_fronts/Kursawe.pf FUN.tsv"

and this works ok, but it is a very cumbersome way of running a program.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
matthieu-vergnecommented, Jul 27, 2015

Hum… taste for using export or -cp, but not for the content of the classpath: you fail in testing the right stuff with your current classpath. The point is that we would like here to ensure that using a single JAR containing everything works. With your classpath, you cannot ensure that, because you include all the JARs, but whether you use the usual JARs or the ones having all the dependencies, it is the same.

Normally, if you have only the exec JAR, it should work, but if you have only the core one, it should not, because you have no algorithm there. This is important to know, and final users should get the right JAR based on their needs: developers of new algorithms need only the core JAR, people wanting to use implemented algorithms need the algorithm JAR, people who want to try jMetal with its own features need the exec JAR, etc. Of course having the most complete one is OK for everyone (and it should be the one to provide on the website), then people have to search for the best one if they want to reduce its size.

Using export is a good idea when you plan to do a lot of commands with the exactly same classpath, but it becomes a trap when you just aggregate everything in your classpath to use many commands which should use different classpaths, because the missing stuff in one is provided by another, so no exception is thrown while it should. For a final user, it should be always the same, but in our case, we have to pay attention to not hide the problems like that. {'^_^}

1reaction
matthieu-vergnecommented, Jul 27, 2015

Thanks. I never touch my classpath, so I used an explicit mention of the JAR:

java -cp jmetal-exec/target/jmetal-exec-5.0-Beta-35-SNAPSHOT-jar-with-dependencies.jar org.uma.jmetal.qualityIndicator.CommandLineIndicatorRunner ALL jmetal-problem/src/test/resources/pareto_fronts/ZDT1.pf jmetal-exec/FUN.tsv 

and it works too:

The fronts are NOT NORMALIZED before computing the indicators
EP: 0.012395707711604587
HV: 0.6596071215396984
GD: 2.5877015814296586E-4
IGD: 1.818754655873446E-4
IGD+: 0.0037047948004080974
SPREAD: 0.3288337056716771
GSPREAD: 0.3455973515141629
R2: 0.13185496556199539
ER: 1.0
SC(refPF, front): 0.92
SC(front, refPF): 0.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I open a program via the command prompt in ...
Using complete path · Open Command Prompt · Type the name of the program you want to run. If its on the PATH...
Read more >
How to Run a Program at the Windows Command Prompt
1. Open the Command Prompt. You can launch the command prompt by pressing the Windows key on your keyboard, typing cmd, and clicking...
Read more >
How to Run an EXE File at the Windows Command Prompt
1. Find the file path of the folder containing your exe program. Open the folder containing your program in a File Explorer window,...
Read more >
How to Run Program from CMD (Command Prompt) Windows ...
At first, you should open Command Prompt application on your Windows 10 computer. You can press Windows + R, type cmd, and press...
Read more >
How do I launch a program from command line without ...
Formatting your command like the above will temporarily open a cmd window that goes away as fast as it comes up so you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found