cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Configuring java samples

ptc-953343
1-Visitor

Configuring java samples

I'm trying to use Java with Arbortext rather than my more typical ACL use.
So I'm trying to get the java samples compiled and running before I start
anything new.

So I've copied the java source files to my custom/classes folder and have
compiled them there with the aom.jar file. i try to run the Hello world
example as instructed in the readme file and it fails. So the instructions
say to use

eval java_static('Hello','sayHello')

I get an empty window and the message line indicates that it

"Cannot load class Hello because a dependent class was not found"

When I look at the javaclasspath setting I see this:

C:\work\custom\classes;C:\Program
Files\Arbortext\Editor53\custom\classes;C:\Program
Files\Arbortext\Editor53\adapters\com.ptc.prowt.arbortext\classes;C:\Program
Files\Arbortext\Editor53\adapters\com.ptc.prowt.arbortext\classes\wnc2ati.jar;C:\Program
Files\Arbortext\Editor53\adapters\com.ptc.prowt.arbortext\classes\atimport.jar;C:\Program
Files\Arbortext\Editor53\adapters\com.ptc.prowt.arbortext\classes\ape_wc.jar;C:\Program
Files\Inmedius\Horizon\classes\Horizon.jar;C:\Program
Files\Inmedius\Horizon\classes\Utils.jar;C:\Program
Files\Inmedius\Horizon\classes\commons-codec-1.3.jar;C:\Program
Files\Inmedius\Horizon\classes\commons-httpclient-3.1-beta1.jar

So I have placed my class files in both of these locations with no
difference: C:\work\custom\classes;C:\Program
Files\Arbortext\Editor53\custom\classes

I don't have a clean Arbortext only environment as you can see the
Inmedius files on the path, is there some standard Arbortext entry missing
for the AOM.jar or something else?

I've been trying to modify the path and I see that
append_javaclass_path("C:\work\custom\classes2") is supposed to add new
locations to the end of the class path, but when I run this and then check
the results I'm not seeing the javaclasspath value changing.

The Hello program is just this:

public class Hello {
/**
* Return "Hello!".
* @return The string "Hello!"
*/
public static String sayHello() {
return "Hello!";
}
}

I've been trying all this at the editor commend line without a document open.

Any ideas?

..dan
13 REPLIES 13

Hi Dan--

I'm not sure what's going wrong with your sample, but the Java console
might be of some help. You can activate it in 5.4 by selecting
Tools->Adminstrative Tools->Java Console. Then try running your static
method, and in the Java Console you should see the stack trace for the
exception thrown by the method. Hopefully that will give you some clues
about exactly what it's looking for that it can't find.

--Clay

Clay Helberg
Senior Consultant
TerraXML

I'm using 5.3 so used Tools -> Java Console.

So that launched the Java Console, I then tried running at the Editor
command line with the same eval java_static('Hello','sayHello')

Nothing is output to the console window. Same with running without the eval.

> Hi Dan--
>
> I'm not sure what's going wrong with your sample, but the Java console
> might be of some help. You can activate it in 5.4 by selecting
> Tools->Adminstrative Tools->Java Console. Then try running your static
> method, and in the Java Console you should see the stack trace for the
> exception thrown by the method. Hopefully that will give you some clues
> about exactly what it's looking for that it can't find.
>
> --Clay
>
> Clay Helberg
> Senior Consultant
> TerraXML
>

I went to another machine that happens to have 5.4 but not the Inmedius
stuff and it worked. I've got to look through classpath info, other than
the different file location it looks like all the Arbortext stuff is in
the 5.3/Inmedius configuration.

..dan


> I'm using 5.3 so used Tools -> Java Console.
>
> So that launched the Java Console, I then tried running at the Editor
> command line with the same eval java_static('Hello','sayHello')
>
> Nothing is output to the console window. Same with running without the
> eval.
>
>> Hi Dan--
>>
>> I'm not sure what's going wrong with your sample, but the Java console
>> might be of some help. You can activate it in 5.4 by selecting
>> Tools->Adminstrative Tools->Java Console. Then try running your static
>> method, and in the Java Console you should see the stack trace for the
>> exception thrown by the method. Hopefully that will give you some clues
>> about exactly what it's looking for that it can't find.
>>
>> --Clay
>>
>> Clay Helberg
>> Senior Consultant
>> TerraXML
>>
>

OK, sorry about that. Apparently if the class loader can't load the
class it doesn't get to the point of generating a stack trace.

Did you verify that your Java code is OK on its own, e.g. by writing
another java class to invoke it and run it from the command line outside
of Arbortext? If there's really a problem with the class itself, this
should give you some more diagnostic information about the problem.

If that checks out, it may be something to do with the settings on your
Java compiler. If you're using 5.3, IIRC it comes with an oldish JVM
which may not be compatible with your compiled byte code if you're using
a more recent JDK. Try using the -target flag to compile your class to
be compatible with a 1.4 JVM and see if that has any effect. (For full
details about compiler flags, see

Glad to hear this is now working for you. We do quite a bit of work with
Java (and I'm actively updated our codebase to connect to new RESTful
services), so it's in the forefront of my mind.

If you decide to do any work with XUI, let me know. There's a bunch of
sample code up on adepters.org, but one pretty handy snippet we use to
instantiate java classes is to have a little javascript file (eg:
loadXui.js) in your custom\init folder. For some reason, it only works if
the command prompt is available (otherwise you get a java exception), but
here's the syntax we use to load at startup:

NOTE: This probably require Rhino Javascript to be default, since it tries
to load Packages.*

/**
* This function loads the initial XUI.
* ApplicationLoad event is used because first run will
* not have a valid document (editinit) and scripts in
* init are called before the window is fully available.
*/
function handleEvent(e) {

if (e.getType().equals("ApplicationLoad")) {
Packages.com.mcg.arbortext.LogUtil.getInstance();
Packages.com.mcg.arbortext.xui.XUIToolManager.loadXUI();
}
}
var o = { handleEvent: handleEvent };
var listener = Packages.org.w3c.dom.events.EventListener(o);
Application.addEventListener("ApplicationLoad", listener, true);

OK, this makes me think it is likely to be a compiler target version
issue. Try recompiling your class for a 1.4 target and see if that makes
it work in the 5.3 environment.

--Clay

Clay Helberg
Senior Consultant
TerraXML

I know we had some issues in the past setting Arbortext to use a different
JVM

You should be able to check it by typing:

eval option(javavmpath)

That would be another potential solution, but it's probably safer to
recompile the custom code for the standard Arbortext JVM.



--C



Clay Helberg

Senior Consultant

TerraXML


Ok, this is something new

So I'm compiling with javac 1.6.0_25

I used this command

javac -target 1.4 -classpath "C:\Program
Files\Arbortext\Editor53\lib\classes\aom.jar" *.java

and got

javac: target release 1.4 conflicts with default source release 1.5

compiling with target 1.5 worked ok.

I was able to then execute the class within Arbortext.

Chalk it up to yet another useful error message!

thanks for the help
..dan



> OK, this makes me think it is likely to be a compiler target version
> issue. Try recompiling your class for a 1.4 target and see if that makes
> it work in the 5.3 environment.
>
> --Clay
>
> Clay Helberg
> Senior Consultant
> TerraXML
>
>

Thanks Clay and Keith for the ideas. I just love readme files that are not
detailed enough and the documentation doesn't help with troubleshooting
issues like this. Only mention in the readme was

Make sure you have JDK 1.4.2 or later on your machine.

looking for the error message in help center turned nothing up.

..dan

> That would be another potential solution, but it's probably safer to
> recompile the custom code for the standard Arbortext JVM.
>
>
>
> --C
>
>
>
> Clay Helberg
>
> Senior Consultant
>
> TerraXML
>
>
>

Glad that got it working for you.

For future reference, the JVM makes assumptions about source version and
target version if you don't explicitly provide them. If you really
needed 1.4-compatible class files, it looks like you would need to
explicitly set the source version as well as the target. (Again, see the
javac man page for details.)

--Clay

Clay Helberg
Senior Consultant
TerraXML

I went looking for an option like that, but when I saw -sourcepath and
nothing else next to it, I didn't look further. I didn't pay attention to
the fact the -help listing was not in alphabetical order.

thanks


> Glad that got it working for you.
>
> For future reference, the JVM makes assumptions about source version and
> target version if you don't explicitly provide them. If you really
> needed 1.4-compatible class files, it looks like you would need to
> explicitly set the source version as well as the target. (Again, see the
> javac man page for details.)
>
> --Clay
>
> Clay Helberg
> Senior Consultant
> TerraXML
>
>

While we're on the java topic... is anyone using Netbeans, or more
specifically Maven to handle their Arbortext packages?

I had been using Ant with a target to copy to my custom\classes dir,
managing external jars manually. Now that I'm using Maven, I have
dependencies setup in my POM to automatically pull jars in from the repo.
So far I've still just been manually copying my main target jar (and any
deps) since I haven't had time to play around with the assembly plugin, but
it's starting to get tedious as I add more and more dependencies
(transitioning from Axis to Wink/Spring/Jackson)

keith

Announcements

Top Tags