why not add the grant for javax.management.MBeanTrustPermission to
%JAVA_HOME%\jre\lib\security\java.policy 
?
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.


> Date: Sun, 2 Sep 2012 01:32:51 +0300
> Subject: java.security.AccessControlException when using Ant, but runs ok 
> when invoking java from console
> From: mperdik...@gmail.com
> To: user@ant.apache.org
> 
> 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
                                          

Reply via email to