2013-08-02 179 views
2

我有這個Maven配置,我想不同的操作系統上使用:不能建立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 

回答

4

我認爲它是因爲一些發送給exec-Maven的插件中包含空格的參數。

在你的情況下,它看起來像${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"與「」。

+0

我在Windows XP中使用NetBeans 7.4。我在nbactions.xml中加入了引號: -jar「$ {basedir} /target/mavenproject1-1.0-SNAPSHOT.jar」。問題解決了。 –

1

在你的exec-插件配置,把「」周圍所有的屬性<argument>標籤(包含在其中美元的) 這樣

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

我更新了帖子 –

+0

看起來你在運行maven-exec的時候在你的類路徑中缺少一個jar。你的一個''參數可能是錯誤的,特別是包含javafx.application.Application的參數。要麼你沒有通過它的jar,或者班級不在你認爲的文件夾中,請檢查你的屬性路徑以確保班級在其中一個路徑中 – Hilikus