Discussion:
[vtp-dev] execute java code in jar from script module
Toni Rincon
2012-06-14 12:37:00 UTC
Permalink
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?

Thanks.

Toni

Code in DemoTools.jar
--------

import java.util.Date;

public class Demo {
public void date(){
Date d = new java.util.Date();
System.out.println("date: " + d);
}

public static void main(String [ ] args)
{
Demo d = new Demo();
d.date();
}
}


Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);

var d2 = new DemoTools.Demo();
d2.date();

Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001>
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001>
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001>
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not defined.
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
Trip Gilman
2012-06-14 15:11:34 UTC
Permalink
Toni,

To access the classes in your jar file simply address them using the fully
qualified class name like you did for java.util.Date. It doesn't appear
that Demo is in the DemoTools package so that line should look like:

var d2 = new Demo();

Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
public void date(){
Date d = new java.util.Date();
System.out.println("date: " + d);
}
public static void main(String [ ] args)
{
Demo d = new Demo();
d.date();
}
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not
defined.
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:365
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Toni Rincon
2012-06-14 15:42:03 UTC
Permalink
Thanks, I have tried also involing directly new Demo(), but I get a
similar error

INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=0001>
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not defined.

Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?

Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the fully
qualified class name like you did for java.util.Date.  It doesn't appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
     public void date(){
             Date d = new java.util.Date();
             System.out.println("date: " + d);
     }
     public static void main(String [ ] args)
     {
           Demo d = new Demo();
           d.date();
     }
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=0001
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not defined.
     at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:365
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Trip Gilman
2012-06-14 16:01:20 UTC
Permalink
It sure is. You might try using the special namespace Packages.Demo.

Trip
Post by Toni Rincon
Thanks, I have tried also involing directly new Demo(), but I get a
similar error
INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=0001
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not defined.
Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?
Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the
fully
qualified class name like you did for java.util.Date. It doesn't appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
public void date(){
Date d = new java.util.Date();
System.out.println("date: " + d);
}
public static void main(String [ ] args)
{
Demo d = new Demo();
d.date();
}
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not
defined.
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3
65
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Toni Rincon
2012-06-14 16:25:51 UTC
Permalink
Sorry I am trying to include the Demo.java in a package namespace like
demotools or Demo, but I still get similar errors, the name of the
package is reported as not defined.
I have verified that my jar is deployed in the war inside

webapps\Demo2\WEB-INF\eclipse\plugins\Demo2.e19222ebb03d4b17aa7af744a233baec_0.0.0\project\Dependencies\DemoTools.jar

inside the jar there my class Demo as
Demo.Demo.class or demotools.Demo.class (I have tryied both)
It sure is.  You might try using the special namespace Packages.Demo.
Trip
Post by Toni Rincon
Thanks, I have tried also involing directly new Demo(), but I get a
similar error
INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=0001
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not defined.
Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?
Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the fully
qualified class name like you did for java.util.Date.  It doesn't appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
     public void date(){
             Date d = new java.util.Date();
             System.out.println("date: " + d);
     }
     public static void main(String [ ] args)
     {
           Demo d = new Demo();
           d.date();
     }
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=00
01
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not defined.
     at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3
65
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Trip Gilman
2012-06-14 16:28:22 UTC
Permalink
Can you send the jar file to me to test with on my side?

Trip
Post by Toni Rincon
Sorry I am trying to include the Demo.java in a package namespace like
demotools or Demo, but I still get similar errors, the name of the
package is reported as not defined.
I have verified that my jar is deployed in the war inside
webapps\Demo2\WEB-INF\eclipse\plugins\Demo2.e19222ebb03d4b17aa7af744a233ba
ec_0.0.0\project\Dependencies\DemoTools.jar
inside the jar there my class Demo as
Demo.Demo.class or demotools.Demo.class (I have tryied both)
Post by Trip Gilman
It sure is. You might try using the special namespace Packages.Demo.
Trip
Post by Toni Rincon
Thanks, I have tried also involing directly new Demo(), but I get a
similar error
INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=00
01
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not defined.
Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?
Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the
fully
qualified class name like you did for java.util.Date. It doesn't
appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
public void date(){
Date d = new java.util.Date();
System.out.println("date: " + d);
}
public static void main(String [ ] args)
{
Demo d = new Demo();
d.date();
}
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=
00
01
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=
00
01
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e=
00
01
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not
defined.
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java
:3
65
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Trip Gilman
2012-06-15 16:31:21 UTC
Permalink
The form worked for me in our lab:

var d = new Packages.Demo.Demo();
d.date();


Trip
Post by Trip Gilman
Can you send the jar file to me to test with on my side?
Trip
Post by Toni Rincon
Sorry I am trying to include the Demo.java in a package namespace like
demotools or Demo, but I still get similar errors, the name of the
package is reported as not defined.
I have verified that my jar is deployed in the war inside
webapps\Demo2\WEB-INF\eclipse\plugins\Demo2.e19222ebb03d4b17aa7af744a233b
a
ec_0.0.0\project\Dependencies\DemoTools.jar
inside the jar there my class Demo as
Demo.Demo.class or demotools.Demo.class (I have tryied both)
Post by Trip Gilman
It sure is. You might try using the special namespace Packages.Demo.
Trip
Post by Toni Rincon
Thanks, I have tried also involing directly new Demo(), but I get a
similar error
INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=0
0
01
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not
defined.
Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?
Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the
fully
qualified class name like you did for java.util.Date. It doesn't
appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
public void date(){
Date d = new java.util.Date();
System.out.println("date: " + d);
}
public static void main(String [ ] args)
{
Demo d = new Demo();
d.date();
}
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not
defined.
at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a
:3
65
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Toni Rincon
2012-06-15 17:06:20 UTC
Permalink
Thanks!!!! invocking using var d = new Packages.Demo.Demo();
it worked for me too, I did not understand correcty the meanign of the
special namespace Packages

Thanks
Post by Trip Gilman
var d = new Packages.Demo.Demo();
d.date();
Trip
Post by Trip Gilman
Can you send the jar file to me to test with on my side?
Trip
Post by Toni Rincon
Sorry I am trying to include the Demo.java in a package namespace like
demotools or Demo, but I still get similar errors, the name of the
package is reported as not defined.
I have verified that my jar is deployed in the war inside
webapps\Demo2\WEB-INF\eclipse\plugins\Demo2.e19222ebb03d4b17aa7af744a233b
a
ec_0.0.0\project\Dependencies\DemoTools.jar
inside the jar there my class Demo as
Demo.Demo.class or demotools.Demo.class (I have tryied both)
It sure is.  You might try using the special namespace Packages.Demo.
Trip
Post by Toni Rincon
Thanks, I have tried also involing directly new Demo(), but I get a
similar error
INFO|2012/06/14|17:38:01|p=Demo2|s=B957620A33E6CB25D0F0B84042FD24E7|e=0
0
01
date: Thu Jun 14 17:38:01 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "Demo" is not defined.
Is dependencies folder the correct place to put my DemoTools.jar where
he Demo.class is defined?
Toni
Post by Trip Gilman
Toni,
To access the classes in your jar file simply address them using the
fully
qualified class name like you did for java.util.Date.  It doesn't
appear
var d2 = new Demo();
Trip Gilman
Post by Toni Rincon
I am trying to inclode java code developped in external project as a
jar in dependencies folder.
But when executing the script the classes and methods in in jar are
not available.
Is it possible to execute code developped in other java projects from
the script module? How is it done?
Thanks.
Toni
Code in DemoTools.jar
--------
import java.util.Date;
public class Demo {
     public void date(){
             Date d = new java.util.Date();
             System.out.println("date: " + d);
     }
     public static void main(String [ ] args)
     {
           Demo d = new Demo();
           d.date();
     }
}
Code in the script module
-------------------------------
var d = new java.util.Date();
Log.info('date: ' + d);
var d2 = new DemoTools.Demo();
d2.date();
Error in Tomcat logs
-------------------------------
INFO|2012/06/13|17:06:57|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
Action "Script" Starting
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
Executing script...
INFO|2012/06/13|17:06:58|p=Demo2|s=9C0D97CF472BF12731F0768ED4F3F823|e
=
00
01
date: Wed Jun 13 17:06:58 CEST 2012
org.mozilla.javascript.EcmaError: ReferenceError: "DemoTools" is not
defined.
     at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.jav
a
:3
65
4)
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
_______________________________________________
vtp-dev mailing list
https://dev.eclipse.org/mailman/listinfo/vtp-dev
Continue reading on narkive:
Loading...