Siema, spotkałem się z ciekawym zapisem, a mianowicie:
java com.my.test.myprog < wej.txt > wyj.txt domyślam się, że program pobiera dane z pliku wej.txt i zapisuje je do pliku wyj.txt. Znalazłem nawet kod, który powinien wykonywać tę operację:
package my.com.test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
public class myprog {
public static void main(String args[]) {
try {
String inputFile = "wej.txt";
String outputFile = "wyj.txt";
// my ProcessBuilder Strings will be different from yours
ProcessBuilder pb = new ProcessBuilder("java", "-cp", ".;bin;",
"my.com.test.myprog");
pb.redirectErrorStream(true);
Process p = pb.start();
final OutputStream pos = p.getOutputStream();
final PrintWriter pw = new PrintWriter(pos);
final InputStream fis = new FileInputStream(inputFile);
final BufferedReader fileBr = new BufferedReader(new InputStreamReader(fis));
InputStreamReader isr = new InputStreamReader(p.getInputStream());
final BufferedReader br = new BufferedReader(isr);
new Thread(new Runnable() {
public void run() {
String lineRead;
try {
while ((lineRead = br.readLine()) != null) {
System.out.println(lineRead);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}).start();
new Thread(new Runnable() {
public void run() {
try {
String lineRead;
while ((lineRead = fileBr.readLine()) != null) {
pw.println(lineRead);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (pw != null) {
pw.close();
}
if (fileBr != null) {
try {
fileBr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}).start();
} catch (IOException e) {
e.printStackTrace();
}
} // end main
}
Po kompilacji i uruchomieniu w ten sposób:
java my.com.test.myprog < wej.txt > wyj.txt
W pliku wyj.txt wyrzuca wyjątki:
Exception in thread "main" java.lang.NoClassDefFoundError: my/com/test/myprog
Caused by: java.lang.ClassNotFoundException: my.com.test.myprog
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: my.com.test.myprog. Program will exit.
Jakiś podpowiedzi ? Myślę, że coś jest może nie tak ze ścieżką, że nie znajduje klasy myprog.