Hi Tim,
Let’s start with the following simple example using the HelloWorld67:
@Stateless
public class HelloBean implements HelloRemote {
public String Greeting(String status) {
if (status.matches("RED"))
return "Hello World with Netbeans 6.7, GF 2.1 (Backend Server RED)";
else
return "Hello World with Netbeans 6.7, GF 2.1 (Backend Server BLUE)";
}
}
public class HellowWorld67ApplicationClient {
@EJB
private static HelloRemote hellobean;
public static void main(String[] args) {
if (args[0].matches("RED"))
System.out.println("Hello World with Netbeans 6.7, GF 2.1 (Front-end Client RED)");
else
System.out.println("Hello World with Netbeans 6.7, GF 2.1 (Front-end Client BLUE)");
System.out.println("args[0]" + args[0]);
System.out.println(hellobean.Greeting(args[0]));
}
}
Made the following settings on the HelloWorld67 (parent) ear project properties:
( i ) HelloWorld67 properties (Right Click & select properties) => Run categories => set RED in Arguments field under Client Info.
Run in Netbeans (RED)
Hello World with Netbeans 6.7, GF 2.1 (Front-end Client RED)
args[0]RED
Hello World with Netbeans 6.7, GF 2.1 (Backend Server RED)
Run it on command prompt
C:\Documents and Settings\jack\HelloWorld67>ant run
..............
run-ac:
-as-retrieve-option-workaround:
[copy] Copying 1 file to C:\Documents and Settings\jack\HelloWorld67\dist
-tool-HelloWorld67-app-client:
[java] Hello World with Netbeans 6.7, GF 2.1 (Front-end Client RED)
[java] args[0]RED
[java] Hello World with Netbeans 6.7, GF 2.1 (Backend Server RED)
-java-HelloWorld67-app-client:
run-HelloWorld67-app-client:
run:
-----------------------------------------------------------------------------------------------------------------
On the other hand, the following error (having cleared the argument in HelloWorld67 properties first) would occur if the same (RED) argument set in the same field under HelloWorld67-app-client properties as suggested:
26/10/2010 11:19:08 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
java.lang.ArrayIndexOutOfBoundsException: 0
at client.HellowWorld67ApplicationClient.main(HellowWorld67ApplicationClient.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:461)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
... 2 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
at client.HelloWorld67ApplicationClient.main(HellowWorld67ApplicationClient.java:12)
... 8 more
Java Result: 1
run-HelloWorld67-app-client:
run:
In other word, Ant targets appears to be looking up argument from HelloWorld67 (parent/root) ear project properties setting instead of HelloWorld67-app-client. However, it seems to have difficulty (java.lang.IllegalArgumentException) locating the same argument (HelloWorld67 properties) when running on command prompt despite having ran properly (able to lookup argument) in Netbeans.
I am a little clearer on which argument Ant is referencing but still don’t understand why it would work in Netbeans but not Ant, unless there is a special syntax where Ant could pickup the parameter either through Netbeans directly, or lookup the argument field itself.
Any suggestion would be much appreciated.
Thanks,
Jack
[Message sent by forum member 'htran_888']
http://forums.java.net/jive/thread.jspa?messageID=486316