gpt4 book ai didi

java - 在ant中运行java项目

转载 作者:太空宇宙 更新时间:2023-11-04 14:52:35 25 4
gpt4 key购买 nike

我正在尝试在 ant 中运行我的 java 项目(两个程序,服务器和客户端)。这是我的 build.xml

<project name="myproject" default="run" basedir=".">
<description>Client Server gui project</description>

<property name="srcdirserver" location="src/src_server"/>
<property name="srcdirclient" location="src/src_client"/>
<property name="lib" location="lib"/>
<property name="build" location="build"/>
<property name="buildserver" location="build/server"/>
<property name="buildclient" location="build/client"/>
<property name="dest_server" location="dest-server"/>
<property name="dest_client" location= "dest-client"/>
<property name="examples" location="examples"/>
<property name="doc" location="doc"/>




<!-- CLEAN -->
<target name="clean">
<delete dir="${build}"/>
<delete dir="${dest_server}"/>
<delete dir="${dest_client}"/>
</target>

<!-- COMPILE (Dummy)-->
<target name="compile" depends="clean,compileserver,compileclient,jarserver,jarclient,documentation">
</target>

<!-- DOCUMENTATION -->
<target name="documentation">
<javadoc sourcepath="${srcdirserver}" destdir="${doc}" encoding="UTF-8" charset="UTF-8"></javadoc>
</target>

<!-- COMPILE (Server code)-->
<target name="compileserver" depends="clean">
<mkdir dir="${buildserver}"/>
<javac includeantruntime="false"
srcdir="${srcdirserver}"
destdir="${buildserver}"
encoding="UTF-8"
classpath="${src}"/>
</target>
<!-- COMPILE (Client code)-->
<target name="compileclient" depends="clean">
<mkdir dir="${buildclient}"/>
<javac includeantruntime="false"
srcdir="${srcdirclient}"
destdir="${buildclient}"
encoding="UTF-8"
classpath="${lib}/swt.jar:${src}"/>
</target>
<!-- BUILD JAR (server) -->
<target name="jarserver" depends="clean,compileserver">
<mkdir dir="${dest_server}"/>
<jar destfile="${dest_server}/myserver.jar"
basedir="${buildserver}">
<manifest>
<attribute name="Main-Class"
value="game_server.main.Init"/>
</manifest>
</jar>
<mkdir dir="${dest_server}/examples"/>
<copy todir="${dest_server}/examples" >
<fileset dir="${examples}" includes="**"/>
</copy>
</target>

<!-- BUILD JAR (client) -->
<target name="jarclient" depends="clean,compileclient">
<mkdir dir="${dest_client}"/>
<jar destfile="${dest_client}/myclient.jar"
basedir="${buildclient}">
<manifest>
<attribute name="Main-Class"
value="game_client.main.Gui"/>
<attribute name="Class-Path"
value="lib/swt.jar"/>
</manifest>
</jar>
<mkdir dir="${dest_client}"/>
<mkdir dir="${dest_client}/lib"/>
<copy file="${lib}/swt.jar"
todir="${dest_client}/lib"/>
</target>

<!-- RUN -->
<target name="run" depends="compile,jarserver,jarclient">
<parallel>
<java jar="${dest_server}/myserver.jar" dir="${dest_server}" fork="true"/>
<java jar="${dest_client}/myclient.jar" dir="${dest_client}" fork="true"/>
</parallel>
</target>
</project>

服务器工作正常,但带有 gui 的客户端已成功编译/存档到 jar 中,但当我运行它时,它会抛出此错误:/编辑:我发现我使用了错误的 swt.jar 版本,我现在下载了正确的版本,但仍然遇到类似的错误:/

run:
[java] OpenJDK 64-Bit Server VM warning: You have loaded library /home/blackened/.swt/lib/linux/x86_64/libswt-gtk-4332.so which might have disabled stack guard. The VM will try to fix the stack guard now.
[java] It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
[java] Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
[java] no swt-gtk-4332 in java.library.path
[java] no swt-gtk in java.library.path
[java] Can't load library: /home/blackened/.swt/lib/linux/x86_64/libswt-gtk-4332.so
[java] Can't load library: /home/blackened/.swt/lib/linux/x86_64/libswt-gtk.so
[java] /home/blackened/.swt/lib/linux/x86_64/libswt-gtk-4332.so: /home/blackened/.swt/lib/linux/x86_64/libswt-gtk-4332.so: Kódovanie dát v ELF súbore nie je little-endian (Possible cause: endianness mismatch)
[java]
[java] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
[java] at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
[java] at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
[java] at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
[java] at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
[java] at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
[java] at game_client.main.Gui.open(Unknown Source)
[java] at game_client.main.Gui.main(Unknown Source)
[java] Java Result: 1

我正在使用 Fedora 18(Spherical Cow)操作系统。如有任何建议,我们将不胜感激。

最佳答案

在我看来,SWT 正在寻找这 2 个 jar 的 32 位版本,但从路径中的 x86_64 来看,您安装的只是 64 位版本。

此外,您说您使用的是 Fedora,但它正在尝试加载看似与 Windows 相关的 jar 文件。

“链接不满足”错误可能是由于它试图查找不存在的 DLL,而不是它应该在 Linux 上查找的 .so 文件。

这可能有帮助: http://www.eclipse.org/swt/faq.php#missingdll

关于java - 在ant中运行java项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23598915/

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