【问题标题】:error calling msbuild from maven从 maven 调用 msbuild 时出错
【发布时间】:2012-03-27 16:01:54
【问题描述】:

我正在尝试将一个项目集成到具有两个组件的 maven 中 - 客户端(用 silverlight 编写)和服务器(用 java 编写)。服务器端完全兼容 maven,但我在使用 maven 运行 msbuild 时遇到问题。我收到以下访问被拒绝错误

嵌入式错误:无法运行程序“C:\WINDOWS\Microsoft.NET\Framework\v4.0.3031 9\msbuild”(在目录“C:\workspace\something\client”中):CreateProcess 错误=5, 访问被拒绝

机器:Windows XP 外壳:git bash 和 cmd

pom.xml:

        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>x</groupId>
      <artifactId>client</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>pom</packaging>
      <name>client</name>
     <build>
       <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <executable>${msbuild.path}</executable>
            </configuration>
            <executions>
                 <execution>
                 <id>clean</id>
                 <phase>clean</phase>
                 <configuration>
                <arguments>
                <argument>/t:Clean</argument>
                </arguments>
             </configuration>
             <goals>
                 <goal>exec</goal>
             </goals>
             </execution>
             <execution>
             <id>build</id>
             <phase>compile</phase>
             <configuration>
                 <arguments>
                <argument>/t:some.sln</argument>
                 </arguments>
             </configuration>
                 <goals>
                    <goal>exec</goal>
                 </goals>
             </execution>
           </executions>
        </plugin>
      </plugins>
     </build>
    </project>

错误:

        $ mvn compile -Dmsbuild.path=C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/msbu
    ild -e
    + Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building client
    [INFO]    task-segment: [compile]
    [INFO] ------------------------------------------------------------------------
    [INFO] [exec:exec {execution: build}]
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Command execution failed.

    Embedded error: Cannot run program "C:\WINDOWS\Microsoft.NET\Framework\v4.0.3031
    9\msbuild" (in directory "c:\workspace\something\client"): CreateProcess error=5,
     Access is denied
    [INFO] ------------------------------------------------------------------------
    [INFO] Trace
    org.apache.maven.lifecycle.LifecycleExecutionException: Command execution failed
    .
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
    ultLifecycleExecutor.java:719)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
    fecycle(DefaultLifecycleExecutor.java:556)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
    ltLifecycleExecutor.java:535)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
    dleFailures(DefaultLifecycleExecutor.java:387)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
    ts(DefaultLifecycleExecutor.java:348)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
    fecycleExecutor.java:180)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
            at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:6
    0)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
            at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
            at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

            at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: org.apache.maven.plugin.MojoExecutionException: Command execution fai
    led.
            at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:363)
            at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
    nManager.java:490)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
    ultLifecycleExecutor.java:694)
            ... 17 more
    Caused by: java.io.IOException: Cannot run program "C:\WINDOWS\Microsoft.NET\Fra
    mework\v4.0.30319\msbuild" (in directory "c:\workspace\something\client"): Create
    Process error=5, Access is denied
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
            at java.lang.Runtime.exec(Runtime.java:593)
            at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13Com
    mandLauncher.java:58)
            at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:2
    54)
            at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecut
    or.java:319)
            at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:
    160)
            at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:602)

            at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:348)
            ... 19 more
    Caused by: java.io.IOException: CreateProcess error=5, Access is denied
            at java.lang.ProcessImpl.create(Native Method)
            at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
            at java.lang.ProcessImpl.start(ProcessImpl.java:30)
            at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
            ... 26 more
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: < 1 second
    [INFO] Finished at: Tue Mar 27 10:33:58 CDT 2012
    [INFO] Final Memory: 7M/494M
    [INFO] ------------------------------------------------------------------------

是否有人成功使用 maven/java 运行 msbuild 或使用 maven 运行任何 Windows 进程/批处理文件?

【问题讨论】:

  • 将 msbuild 放在路径中并避免长路径名可能会更好。他们似乎总是惹麻烦..

标签: java maven msbuild maven-plugin


【解决方案1】:

可能是因为您的 ${msbuild.path} 属性解析为文件夹 C:\Windows\...\msbuild,而不是可执行文件 C:\Windows\...\msbuild.exe

【讨论】:

  • 我在不需要“.exe”的命令窗口中进行了测试,但是当我使用 System.Diagnostics.Process.Start 时,我确实需要“.exe”。谢谢。
【解决方案2】:

移至 Windows 7 并且可以正常工作。不知道为什么它在 XP 上不起作用,但它为我解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2013-04-20
    • 1970-01-01
    • 2011-02-21
    • 2010-11-22
    相关资源
    最近更新 更多