gpt4 book ai didi

java - 如何使用 Maven 构建独立的 SWT GUI?

转载 作者:行者123 更新时间:2023-12-02 12:22:47 25 4
gpt4 key购买 nike

在本指南中https://www.eclipse.org/swt/eclipse.php有一个很好的指南如何使用 Eclipse 构建基于 SWT 的 GUI。现在,我想用 Maven 组装同一个项目。通过最后使用 pom.xml,我收到以下错误:

[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

最佳答案

看起来您的本地 .m2 Maven 存储库中的一个或多个 jar 已损坏(jar-with-dependencies 尝试首先解压所有依赖项,以便将它们捆绑在同一个 jar 中)。

不幸的是,错误消息没有说明是哪一个。

您可以:

  • 删除 .m2 存储库的全部内容,并依靠 Maven 再次下载它们(.m2 存储库可在 Windows 设置中找到,位于您当前的用户文件夹;例如对我来说,它位于C:\Users\Andrei\.m2)
  • 使用 -X 选项重新运行您的构建,该选项应该提供有关哪个特定 jar 导致问题的更多详细信息。那么你就只能删除那个了​​。

除非您的 .m2 文件夹中有任何自定义安装,否则我建议选择 1。

关于java - 如何使用 Maven 构建独立的 SWT GUI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45651150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com