【问题标题】:Cannot build Maven Project无法构建 Maven 项目
【发布时间】:2013-08-02 13:23:04
【问题描述】:

我有这个我想在不同操作系统上使用的 maven 配置:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.dx57dc</groupId>
    <artifactId>DX57DC</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>DX57DC</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <mainClass>com.dx57dc.MainApp</mainClass>
    </properties>

    <profiles>
        <profile>
            <activation>
                <os>
                    <name>Windows XP</name>
                    <family>Windows</family>
                    <arch>x86</arch>
                    <version>5.1.2600</version>
                </os>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.8</version>
                        <executions>
                            <execution>
                                <id>unpack-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <excludeScope>system</excludeScope>
                                    <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <id>unpack-dependencies</id>

                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${java.home}/../bin/javafxpackager</executable>
                                    <arguments>
                                        <argument>-createjar</argument>
                                        <argument>-nocss2bin</argument>
                                        <argument>-appclass</argument>
                                        <argument>${mainClass}</argument>
                                        <argument>-srcdir</argument>
                                        <argument>${project.build.directory}/classes</argument>
                                        <argument>-outdir</argument>
                                        <argument>${project.build.directory}</argument>
                                        <argument>-outfile</argument>
                                        <argument>${project.build.finalName}.jar</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>  
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                            <compilerArguments>
                                <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
                            </compilerArguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

        </profile>

        <profile>
            <activation>
                <os>
                    <name>Linux</name>
                    <family>Linux</family>
                    <arch>x86</arch>
                    <!-- <version>5.1.2600</version> -->
                </os>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.8</version>
                        <executions>
                            <execution>
                                <id>unpack-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <excludeScope>system</excludeScope>
                                    <excludeGroupIds>junit,org.mockito,org.hamcrest</excludeGroupIds>
                                    <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <id>unpack-dependencies</id>

                                <phase>package</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>${java.home}/../bin/javafxpackager</executable>
                                    <arguments>
                                        <argument>-createjar</argument>
                                        <argument>-nocss2bin</argument>
                                        <argument>-appclass</argument>
                                        <argument>${mainClass}</argument>
                                        <argument>-srcdir</argument>
                                        <argument>${project.build.directory}/classes</argument>
                                        <argument>-outdir</argument>
                                        <argument>${project.build.directory}</argument>
                                        <argument>-outfile</argument>
                                        <argument>${project.build.finalName}.jar</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>  
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                            <compilerArguments>
                                <bootclasspath>/opt/java/jre/lib/ext/jfxrt.jar</bootclasspath>
                            </compilerArguments>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

        </profile>
    </profiles>


</project>

我收到此警告消息:

--- exec-maven-plugin:1.2.1:exec (default-cli) @ DX57DC ---
Error: Unable to access jarfile D:\Documents

你能告诉我配置这个 POM 文件的正确方法是什么吗?

P.S 在我添加“”之后,无论是否添加,我都会在 Windows 上收到此错误:

[exec:exec]
java.lang.NoClassDefFoundError: javafx/application/Application
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more
Exception in thread "main" [INFO] ------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.000s
Finished at: Fri Aug 02 14:09:35 PDT 2013
Final Memory: 6M/15M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project DX57DC: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

【问题讨论】:

    标签: maven build maven-3 maven-plugin


    【解决方案1】:

    我认为这是因为发送给 exec-maven-plugin 的一些参数包含空格。

    在您的情况下,它看起来像 ${project.build.directory} 或其他一些变量解析为 C:\Documents and Settings\something。

    当你传递这个时:

    <argument>-srcdir</argument>
    <argument>${project.build.directory}/classes</argument>
    

    它将解析为:-srcdir=C:\Documents and Settings\something/classes。

    什么时候应该是这样的:-srcdir="C:\Documents and Settings\something/classes" with ""。

    【讨论】:

    • 我在 Windows XP 中使用 NetBeans 7.4。我在 nbactions.xml 中加上引号:-jar "${basedir}/target/mavenproject1-1.0-SNAPSHOT.jar"。问题已解决。
    【解决方案2】:

    在您的 exec-plugin 配置中,将 "" 放在所有属性 &lt;argument&gt; 标记(其中包含 $ 的标记)周围 像这样

    <arguments>
         <argument>-createjar</argument>
         <argument>-nocss2bin</argument>
         <argument>-appclass</argument>
         <argument>"${mainClass}"</argument>
         ....
    </arguments>
    

    【讨论】:

    • 当您运行 maven-exec 时,您的类路径中似乎缺少一个 jar。您的&lt;argument&gt; 参数之一可能是错误的,尤其是包含 javafx.application.Application 的参数。要么您没有传递它的 jar,或者该类不在您认为的文件夹中,请检查您的属性路径以确保该类在其中一个中
    猜你喜欢
    • 2018-11-24
    • 1970-01-01
    • 2022-08-24
    • 2016-02-02
    • 2016-05-25
    • 2019-12-16
    • 1970-01-01
    • 2012-09-28
    • 2022-11-27
    相关资源
    最近更新 更多