5

i would like to launch an applet in an build.xml like this:

<java classname="sun.applet.AppletViewer" classpath="${libraries}">
</java>

(at least that is how it works in netbeans)

but i get the error message:

 [java] JVM args ignored when same JVM is used.
 [java] Could not find sun.applet.AppletViewer. Make sure you have it in your classpath
 [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:138)
 [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
 [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 [java]     at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [java]     at java.lang.reflect.Method.invoke(Method.java:597)
 [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
 [java]     at org.apache.tools.ant.Target.execute(Target.java:357)
 [java]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
 [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
 [java]     at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
 [java]     at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:30)
 [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
 [java]     at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:416)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [java]     at java.lang.reflect.Method.invoke(Method.java:597)
 [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
 [java]     at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:62)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [java]     at java.lang.reflect.Method.invoke(Method.java:597)
 [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
 [java]     at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:394)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [java]     at java.lang.reflect.Method.invoke(Method.java:597)
 [java]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 [java]     at org.apache.tools.ant.Task.perform(Task.java:348)
 [java]     at org.apache.tools.ant.Target.execute(Target.java:357)
 [java]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
 [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
 [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
 [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 [java]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
 [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
 [java]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:423)
 [java]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:137)
 [java] Java Result: -1

it seems that the classpath="..." argument overrides the eclipse-ant default classpath. unfortunately i really need to specify an additional classpath.

clamp
  • 33,000
  • 75
  • 203
  • 299
  • I _guess_ you have to add the tools.jar to your classpath – Tim Büthe Aug 11 '10 at 11:14
  • @Tim: i have added rt.jar to the classpath, but then i get this exception: java.lang.IllegalAccessError: tried to access class sun.applet.AppletMessageHandler from class sun.applet.AppletViewer – clamp Aug 11 '10 at 11:26
  • try to remove the classpath argument (and the jvm argument), then it takes the classpath it was started with – Tim Büthe Aug 11 '10 at 12:59
  • 1
    @Tim: yes thanks, that is true. unfortunately i need to specify an additional classpath. – clamp Sep 27 '10 at 15:38
  • The point is, that proves that your classpath is not complete. I guess the AppletViewer is in some JVM Library, like the tools.jar. Find the jar and add it to your classpath. – Tim Büthe Sep 29 '10 at 10:16

2 Answers2

8

Try using fork parameter.

<java classname="sun.applet.AppletViewer" classpath="${libraries}" fork="true">

Will create a new JVM process and run your applet.

Plínio Pantaleão
  • 1,229
  • 8
  • 13
1

This works fine:

<project default="test">

<target name="test">
    <java classname="sun.applet.AppletViewer">
        <arg value="http://java.sun.com/applets/jdk/1.4/demo/applets/BarChart/example1.html"/>
    </java>
</target>

</project>
Tim Büthe
  • 62,884
  • 17
  • 92
  • 129
  • 1
    yes it works because there is no classpath="" argument. unfortunately i really need to specify it with some variables. – clamp Sep 27 '10 at 15:42