2

I get the following ant error in console while running jetty:stop command using mvn tasks,

[artifact:mvn] org.apache.tools.ant.ExitException: Permission (java.lang.RuntimePermission exitVM) was not granted.
[artifact:mvn]  at org.apache.tools.ant.types.Permissions$MySM.checkExit(Permissions.java:196)
[artifact:mvn]  at java.lang.Runtime.exit(Runtime.java:88)
[artifact:mvn]  at java.lang.System.exit(System.java:904)
[artifact:mvn]  at org.codehaus.classworlds.Launcher.main(Launcher.java:376)
[artifact:mvn]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[artifact:mvn]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[artifact:mvn]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[artifact:mvn]  at java.lang.reflect.Method.invoke(Method.java:597)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
[artifact:mvn]  at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
[artifact:mvn]  at org.apache.maven.artifact.ant.Mvn.execute(Mvn.java:81)
[artifact:mvn]  at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[artifact:mvn]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[artifact:mvn]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[artifact:mvn]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[artifact:mvn]  at java.lang.reflect.Method.invoke(Method.java:597)
[artifact:mvn]  at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[artifact:mvn]  at org.apache.tools.ant.Task.perform(Task.java:348)
[artifact:mvn]  at org.apache.tools.ant.Target.execute(Target.java:357)
[artifact:mvn]  at org.apache.tools.ant.Target.performTasks(Target.java:385)
[artifact:mvn]  at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
[artifact:mvn]  at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
[artifact:mvn]  at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[artifact:mvn]  at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
[artifact:mvn]  at org.apache.tools.ant.Main.runBuild(Main.java:758)
[artifact:mvn]  at org.apache.tools.ant.Main.startAnt(Main.java:217)
[artifact:mvn]  at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[artifact:mvn]  at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

In search for this error, I got similar posts,

https://stackoverflow.com/a/8588201/1793718

https://issues.apache.org/jira/browse/MANTTASKS-201

https://readthefuckingmanual.net/error/1010/

suggesting setting fork="true" would solve the problem but I get this error when already my fork is set to true(or even false)

Below is my ant target to invoke stop jetty server,

<target name="jetty-stop" fork="true">
    <artifact:mvn mavenHome="${maven.home}">
        <jvmarg value="-Xmx1024m" />
        <arg value="jetty:stop"/>
    </artifact:mvn>
</target>

Update :

I also noticed error messages while initializing the c3p0 same as mentioned in this question,

java.security.AccessControlException when using Ant, but runs ok when invoking java from console

while starting up the server using the following ant-task,

<target name="jetty-start-jdk8">
    <delete dir="war/WEB-INF/lib"/>
    <artifact:mvn mavenHome="${maven.home}" fork="true">
        <jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000" />
        <jvmarg value="-javaagent:${jrebel.path}" />
        <jvmarg value="-Xbootclasspath/p:C:/Users/admin/AppData/Local/Temp//rebelboot.jar" />
        <arg value="compile"/>
        <arg value="war:exploded"/>
        <arg value="jetty:run"/>
    </artifact:mvn>
</target>

The above post also suggests to set fork="true" to solve it. But it's already set to true. What could be the issue here?

Community
  • 1
  • 1
Lucky
  • 16,787
  • 19
  • 117
  • 151

2 Answers2

2

Solution:

Use JDK instead of JRE in your build path.

The problem was my project was configured in eclipse with a JRE instead of a JDK and the build.xml was picking up my project configuration which is a JRE. For some reasons, running the ant tasks with JRE as your System Library. Changing to JDK 1.8 solved the issue. After changing the Build path delete the Build.XML from the Ant View and add again to run the tasks.

Lucky
  • 16,787
  • 19
  • 117
  • 151
0

The System.exit( ) call speaks directly to the JVM, causing it to die immediately. Since a Java program running from Ant is running in Ant’s JVM, any calls to System.exit( ) will kill Ant’s JVM.

Since you try to call to kill ant's JVM, you may not have permission for it.

Security permissions can be revoked and granted during the execution of the class via a nested permissions element. For more information please see https://svn.apache.org/repos/asf/ant/core/trunk/manual/Types/permissions.html

When the permission RuntimePermission exitVM has not been granted (or has been revoked) the System.exit() call will be intercepted and treated like indicated in failonerror.

You can provide in your java task

<java classname="org.stackoverflow.SpecialTool" fork="true">
    <permissions>
       <grant class="java.security.AllPermission"/>
    </permissions>
</java>

OR

The java task has an attribute called fork.

<java classname="org.stackoverflow.SpecialTool" fork="true"/>

The fork attribute on the java task gives you the ability to avoid this problem. The attribute tells the java task to run the class in a separate JVM. Being in a separate JVM means the program’s System.exit( ) call can’t kill Ant’s JVM.