jEdit Community - Resources for users of the jEdit Text Editor
Starting a java jar from a Beanshell and vice versa
Submitted by bigmoun10 on Friday, 23 January, 2009 - 15:29
Hi

First, I'm new to all this java and beanshell stuff. Please be patient with me.

In general
* all beanshell files are stored on "C:\Program Files\jEdit\macros\xyMacros" and
* all jar files are stored on "C:\Program Files\jEdit\jars".

First problem:
==============
I want to extend jEdit with a beanshell macro, which calls xy.class in xy.jar file. The class in the class file is defined as "public class xy extends JDialog" and the main method is defined the following way:

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() ...

The jar file also contains other source files like icons and additional class files.

Now, the question is: how can I call the java code from the beanshell macro and what is needed to make it work (e.g. classpath, imports, ...)?

Second problem:
===============
Once the java code is executed and the dialog pops up I would like to execute a beanshell script, let's say myScript.bsh, when a certain button is pushed. The beanshell script then manipulates the textarea of the actual view in jEdit.
Questions here: How can I call beanshell scripts from the java code? Is there anything I need to do regarding the actual view, e.g. storing it in the java class and then give it to the beanshell script as an argument, or is this working right away?

If somebody could answer and give code examples, this would be great!
Thanks in advance!
Comment viewing options
Select your preferred way to display the comments and click 'Save settings' to activate your changes.
As you've mentioned: First,
by elberry on Sun, 25/01/2009 - 10:20
As you've mentioned:
First, create your macro under ~/.jedit/macros/[your_dir]. Then add your your jar to ~/.jedit/jars/[your_jar].

Now, either open up Plugin Manager and make sure your jar has been loaded, if not put a check next to it.

Hopefully you're macro can now just import the content in your jar.

If it doesn't work directly as an import statement. If not, look into using the jar! url pattern. You should be able to find it in the jedit help documents.

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
 
JAR is loaded, calling method gives error
by bigmoun10 on Mon, 26/01/2009 - 10:21
Hi elberry

First, a big thank you for being so active in this forum!

Yes, the JAR is loaded (need to tick off "Hide Libraries"). Then the calling script looks as following:

//import the class xy.class in xy.jar
import xy;
//call the main method in xy.class
xy();

This throws an error saying it can't find the command xy in the macros' directory. Then I tried it with prepending the class name ( ==> xy.xy() ) and now it looks into the class, but without success. The error is: "Error in method invocation: Static method xy() not found in class'xy'.

Is this the point to look into using the jar! url pattern or do I need to change the calling command? If url is needed, can you give me more details about the command (I haven't found something usefull in jEdit's manual)?

Cheers
 
Hmm. Ok. The jar! url pattern
by elberry on Mon, 26/01/2009 - 17:46
Hmm. Ok. The jar! url pattern won't work with calling straight java. It's used more for finding the icons and other resources.

To make use of your class from a macro, you probably need to work a bit with the JARClassloader.

Here's an example of someone trying to make use of a JDBC driver from a macro.

http://community.jedit.org/?q=node/view/3812#7128

Hopefully that works for you.

Learn from the past. Live in the present. Plan for the future.
11101000
Blog
User login
Browse archives
« April 2024  
MoTuWeThFrSaSu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
Poll
Are you interested in language packs for jEdit?
Yes, and I could help maintain translations
26%
Yes, I'd like to have translations
32%
Indifferent
35%
No, that'd be bad (please comment)
7%
Total votes: 1093
Syndication
file   ver   dls
German Localization light   4.4.2.1   82348
Context Free Art (*.cfdg)   0.31   46055
JBuilder scheme   .001   18495
BBEdit scheme   1.0   18116
ColdFusion scheme   1.0   18024
R Edit Mode - extensive version   0.1   17473
Advanced HTML edit mode   1.0   16206
Matlab Edit Mode   1.0   16068
jEdit XP icons   1.0   15229
XP icons for jEdit   1.1   14293