I was trying to execute the following code in java:
import java.awt.*;
import javax.swing.*;
import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;
public class TextEditorDemo extends JFrame {
private static final long serialVersionUID = 1L;
public TextEditorDemo() {
JPanel cp = new JPanel(new BorderLayout());
RSyntaxTextArea textArea = new RSyntaxTextArea();
textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
RTextScrollPane sp = new RTextScrollPane(textArea);
cp.add(sp);
setContentPane(cp);
setTitle("RSyntaxTextArea 1.4 - Example 1 - Text Editor Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setLocationRelativeTo(null);
}
public static void main(String[] args) {
// Start all Swing applications on the EDT.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new TextEditorDemo().setVisible(true);
}
});
}
}
Since I'm using RSyntaxTextArea file i have to give the classpath of it while I'm running the code. Assume that my RSyntaxTextArea.jar file is in Anto(i.e. my Home directory in Ubuntu 10.10) and whe开发者_如何学Pythonn I run the above code:
javac -classpath \Anto\RSyntaxTextArea.jar TextEditorDemo.java
Still I'm getting the error as RTextScrollPane
could not be found kind of errors. I guess i have been giving my classpath wrongly; What to do?
Thanks for the answer.
Did you download it from the sourceforge site? It is a zip file containing the sources. Create a folder for containing the sources and unzip it. Run ant in the folder - it will create a rsyntaxtextarea.jar in the dist folder. Add this to the class path.
Assuming that /Anto is really your home directory, try this:
javac -classpath ~/RSyntaxTextArea.jar TextEditorDemo.java
Otherwise, just point to a relative path to the jar file. For one thing, you were trying to use \, where in Linux you should be using /. You can reference the current directory with . So, if the jar is in your current working directory, you can just do this:
javac -classpath RSyntaxTextArea.jar TextEditorDemo.java
Or this:
javac -classpath ./RSyntaxTextArea.jar TextEditorDemo.java
If the Anto directory is under the current directory, use this:
javac -classpath ./Anto/RSyntaxTextArea.jar TextEditorDemo.java
Because that's not the path to your home directory, nor the correct slash to use.
javac -classpath /home/Anto/RSyntaxTextArea.jar TextEditorDemo.java
Also note Java 6 allows you to use a wildcard (*
) for the path to search for jar files.
精彩评论