ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Menelaos Perdikeas <mperdik...@gmail.com>
Subject java.security.AccessControlException when using Ant, but runs ok when invoking java from console
Date Sat, 01 Sep 2012 22:32:51 GMT
I have the following *Ant < java >* task:

<echo message="running the app with classpath = ${classpath-run.msg}"/>
<echo message="Java version used (ant.java.version): ${ant.java.version}"/>
<echo message="Java version used (    java.version): ${java.version}"/>
<java classname ="${project.MainClass.name}">
    <permissions>
        <grant class="java.security.AllPermission"/>
        <grant class="javax.management.MBeanTrustPermission"
action="register"/>
    </permissions>
    <classpath refid="run.classpath"/>
</java>

When I run *Ant* the execution of the **task fails (see trace below my
signature). When I copy-paste the echoed classpath and run my code from the
command line with *java -classpath ..* the execution succeeds! I was
advised that apparently I had to add some permissions to the Ant <java>
task and so I have as you can see above, but the problem persists.

In both cases the same version of *java* is used.

I have the book "Ant in Action" (Manning Press) but there's no mention
about any Security Managers with Ant. So my questions are:

[1] Why should Ant's <java> task even bother with permissions and Security
Managers? It is a long-established convention that running Java from the
command line never sets any Security Managers.

[2] How can I disable Ant's Security Manager or grant permissions that
would ensure my Ant <java> runs are the same as executing the code from the
command line ?

Menelaos.

 [java] java.lang.ExceptionInInitializerError
 [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
 [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
 [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
 [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 [java]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [java]     at java.lang.reflect.Method.invoke(Method.java:601)
 [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:68)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 [java]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [java]     at java.lang.reflect.Method.invoke(Method.java:601)
 [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:398)
 [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
 [java]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [java]     at java.lang.reflect.Method.invoke(Method.java:601)
 [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:390)
 [java]     at org.apache.tools.ant.Target.performTasks(Target.java:411)
 [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
 [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
 [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
 [java]     at org.apache.tools.ant.Main.runBuild(Main.java:809)
 [java]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
 [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
 [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
 [java] Caused by: java.lang.ExceptionInInitializerError
 [java]     at TranslationClient.main(TranslationClient.java:5)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [java]     at java.lang.reflect.Method.invoke(Method.java:601)
 [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
 [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
 [java]     ... 34 more
 [java] Caused by: net.sf.ehcache.CacheException:
java.security.AccessControlException: access denied
("javax.management.MBeanTrustPermission" "register")
 [java]     at net.sf.ehcache.management.sampled.SampledMBeanRegistrationProvider.initialize(SampledMBeanRegistrationProvider.java:98)
 [java]     at net.sf.ehcache.management.provider.MBeanRegistrationProviderImpl.initialize(MBeanRegistrationProviderImpl.java:63)
 [java]     at net.sf.ehcache.CacheManager.doInit(CacheManager.java:454)
 [java]     at net.sf.ehcache.CacheManager.init(CacheManager.java:374)
 [java]     at net.sf.ehcache.CacheManager.<init>(CacheManager.java:356)
 [java]     at TranslationCache.<clinit>(TranslationCache.java:10)
 [java]     ... 41 more
 [java] Caused by: java.security.AccessControlException: access denied
("javax.management.MBeanTrustPermission" "register")
 [java]     at java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
 [java]     at java.lang.SecurityManager.checkPermission(SecurityManager.java:585)
 [java]     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.checkMBeanTrustPermission(DefaultMBeanServerInterceptor.java:1848)
 [java]     at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:322)
 [java]     at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:512)
 [java]     at net.sf.ehcache.management.sampled.SampledMBeanRegistrationProvider.registerCacheManagerMBean(SampledMBeanRegistrationProvider.java:118)
 [java]     at net.sf.ehcache.management.sampled.SampledMBeanRegistrationProvider.initialize(SampledMBeanRegistrationProvider.java:95)
 [java]     ... 46 more

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message