in the script using java code i am printing something and using external jar for the some purpose.
like mail.jar
Working:
I am [color=red]able to call [/color]the java code from asterisk using FastAGI
Normal Script is running fine and printing whatever is directed in the streamfile() method.
Problem:
in the java code i am taking the reference of some externam APIs, say [color=red]mail.jar [/color]i am using.
on the UNIX system when i am setting the classpath, compiling and running is fine for the
java code.
But when the same script is been run from the Asterisk, it gives error as follows:
[color=red]Sep 9, 2008 12:00:47 PM org.asteriskjava.fastagi.DefaultAgiServer startup
INFO: Received connection from /127.0.0.1
Exception in thread “Asterisk-Java DaemonPool-1-thread-1” java.lang.NoClassDefFoundError: javax/mail/Service
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.asteriskjava.fastagi.AbstractMappingStrategy.createAgiScriptInstance(AbstractMappingStrategy.java:60)[/color]
I know this error is only that FastAGI server is not getting the reference to the mail.jar
I have included this jar into the same folder where the java code is running as well as in the library folder too. I have set the CLASSPATH on the unix end, and if i run the code only from unix things works fine for me.
But gives problem when run by Asterisk - FastAGI.
Please give me any helping pointer, if someone had already done something on this.
This is definitely a class path issue. It has nothing to do with asterisk, as FastAGI is simply a TCP protocol. How are you firing up your JVM? Can you do a ps - ax | grep java and post the output?
for “[color=red]ps -ax | grep java[/color]” output is:
ps -ax | grep java
[color=blue]Warning: bad syntax, perhaps a bogus ‘-’? See /usr/share/doc/procps-3.2.3/FAQ
3549 pts/2 S+ 0:00 grep java[/color]
and for “[color=red]ps -ef | grep java[/color]” output is:
[color=blue]root 3551 3421 0 19:10 pts/2 00:00:00 grep java[/color]
below is my directory structure:
why don’t you start the JVM with the classpath properly set right in the command line. I am not sure how you are starting your java app, but just add the -classpath argument.
One other thing I just noticed… your $CLASSPATH is referring to a /lib directory under your asterisk_java workspace, yet your “ls” is an output of the src/com directory.
Are you sure the files exist in the /lib as specified in your environment var?
[why don’t you start the JVM with the classpath properly set right in the
command line]
Ya things are working fine at my end as you have directed. But the thing
is i am already able to call the program from the UNIX successfully and it
sends the mail successfully (as i am able to receive the mail as well)
[color=green]Means code is working fine when run from UNIX.[/color]
But the problem that i am facing is, calling that java program through the
AGI script. Means “java-asterisk server” fails to load the library(mail.jar),
as at the runtime it shows error like this:
[color=red]Sep 9, 2008 12:00:47 PM org.asteriskjava.fastagi.DefaultAgiServer startup
INFO: Received connection from /127.0.0.1
Exception in thread “Asterisk-Java DaemonPool-1-thread-1” java.lang.NoClassDefFoundError:
javax/mail/Service at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.asteriskjava.fastagi.AbstractMappingStrategy.createAgiScriptInstance
(AbstractMappingStrategy.java:60) [/color] Are you sure the files exist in the /lib as specified in your environment
var?
[color=green]Yes i have mail.jar both in /lib as well as src/com directories.[/color]
So what is guess “[color=red]java-asterisk server” it not able to get the correct
CLASSPATH. [/color]Now what i am trying in the java code is to set the
CLASSPATH programatically and then call the java email script.
Hi,
on my side, i am only starting the “asterisk-java server” by giving the
following command:
[color=red]/home/vishal/java_workspace/asterisk_java/src/com>java -cp asterisk-java-0.3.jar:. org.asteriskjava.fastagi.DefaultAgiServer[/color]
Then in the dialplan i have written like this:(in extension.conf file)
[color=red]exten => 1300,1,Agi(agi://10.77.143.5/hello.agi)[/color]
and at the location:
/home/vishal/java_workspace/asterisk_java/src/com
the contents of the [color=red]“fastagi-mapping.properties”[/color] file are:
[color=red]hello.agi = MailEx[/color]
So when i make a call from xlite at 1300, then the AGI server calls the
script and gives the error. My sample Hellow AGI script is working fine.
Problem is only with the mail sending program as the server fails to get
the mail.jar file.
[size=117][color=green]Thanks a lot g2010,
Thanks a ton.
It solved my problem, the problem was only that i was not starting the
AGI server by giving path of all the jars used. I assumed it should pick the jars from the current location by itself.
Thanks a lot again.
Now i am looking forward with more examples of asterisk-java.
and will ping you when i will be in need of your help.