2017-08-12 33 views
0

在这个howto https://www.eclipse.org/swt/eclipse.php有一个很好的指导,如何用Eclipse构建一个基于SWT的GUI。 现在,我想与Maven组装相同的项目。通过使用pom.xml的结尾,我得到以下错误:如何使用Maven构建独立的SWT GUI?

[DEBUG] adding entry libswt-awt-cocoa-4626.jnilib 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.747 s 
[INFO] Finished at: 2017-08-12T15:06:45+02:00 
[INFO] Final Memory: 15M/225M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project swtsandbox: Failed to create assembly: Error creating assembly archive jar-with-dependencies: Problem creating jar: invalid LOC header (bad signature) -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (default-cli) on project swtsandbox: Failed to create assembly: Error creating assembly archive jar-with-dependencies: Problem creating jar: invalid LOC header (bad signature) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) 

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>pmu</groupId> 
    <artifactId>swtsandbox</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>swtsandbox</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 
    <swt.version>4.6.1</swt.version> 
    </properties> 

<repositories> 
    <repository> 
     <id>maven-eclipse-repo</id> 
     <url>http://maven-eclipse.github.io/maven</url> 
    </repository> 
</repositories> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

    <!-- select prefered one, or move the preferred on to the top: --> 

     <dependency> 
      <groupId>org.eclipse.swt</groupId> 
      <artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId> 
      <version>${swt.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.swt</groupId> 
      <artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId> 
      <version>${swt.version}</version> 
     </dependency> 
    </dependencies> 



<build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.6.2</version> 
      <configuration> 
      <!-- put your configurations here --> 
      </configuration> 
     </plugin> 

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
    <archive> 
     <manifest> 
     <mainClass>pmu.swtsandbox.App</mainClass> 
     </manifest> 
    </archive> 
    <descriptorRefs> 
     <descriptorRef>jar-with-dependencies</descriptorRef> 
    </descriptorRefs> 
    </configuration> 
    <executions> 
    <execution> 
     <id>make-assembly</id> <!-- this is used for inheritance merges --> 
     <phase>package</phase> <!-- bind to the packaging phase --> 
     <goals> 
     <goal>single</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

     </plugins> 
    </pluginManagement> 
    </build> 
</project> 

Maven的版本:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00) 
Maven home: /usr/local/apache-maven-3.3.9 
Java version: 1.8.0_101, vendor: Oracle Corporation 
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac" 
p 
+0

定义Maven的组装插件的版本,而且你使用哪个Maven版本?从简单的控制台运行?或从Eclipse内部? – khmarbaise

+0

这个想法是构建一个无头应用程序(即命令行) - 对于maven,请参阅编辑 – poseid

+0

你打开了通过'mvn -C ...'验证校验和......第一步简单地删除你的整个本地缓存' $ HOME/.m2/repository'并重建你的应用程序.... – khmarbaise

回答

1

看起来像一个或多个您当地的.m2 Maven仓库中的罐子被损坏(jar-with-dependencies试图首先解开所有的依赖关系,以便将它们捆绑在同一个罐子中)。

不幸的是,错误信息并没有说明哪个。

您可以:

  • 删除您.m2库的完整内容,并依靠Maven的重新下载他们(.m2库中找到,在Windows安装程序,在您的当前用户文件夹;例如对我来说这是位于C:\Users\Andrei\.m2
  • 重新运行您的版本与-X选项,其中应该提供有关哪个特定jar导致问题的更多细节。那么你只能删除那一个。

除非你在.m2文件夹中有任何自定义install S,我建议选择1