Bom dia,
Acabei de fazer um exercicio, com o objetivo de, trabalhar com argumentos passados via linha de comando. Dentro do NetBeans, passando o argumento, está funcionando. Segue abaixo a saida:
run:
0 X 7 = 0
1 X 7 = 7
2 X 7 = 14
3 X 7 = 21
4 X 7 = 28
5 X 7 = 35
6 X 7 = 42
7 X 7 = 49
8 X 7 = 56
9 X 7 = 63
10 X 7 = 70
CONSTRUÍDO COM SUCESSO (tempo total: 0 segundos)
Porém executando no terminal, é exibido o seguinte erro:
E:\Projeto\Java\Tabuada\dist>java Tabuada.jar 7
Exception in thread "main" java.lang.NoClassDefFoundError: Tabuada/jar
Caused by: java.lang.ClassNotFoundException: Tabuada.jar
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Tabuada.jar. Program will exit.
E:\Projeto\Java\Tabuada\dist>
Pelo que entendi, do erro, não foi encontrado uma classe ou algo do tipo. Abaixo segue o código, utilizado:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package tabuada;
/**
*
* @author Kaos
*/
public class Tabuada {
public static void main(String args[]) {
for(int i = 0; i <= 10; i++) {
int valor = Integer.parseInt(args[0]);
System.out.println(i + " X " + args[0] + " = " + valor * i);
}
}
}
[]s