简体   繁体   English

使用Eclipse中指定的环境变量导出可运行的jar

[英]Exporting a runnable jar with environment variables specified in Eclipse

I am currently using Sikuli which requies both a PATH and SIKULI_PATH environment variable to be set in order to execute. 我当前正在使用Sikuli ,它需要同时设置PATHSIKULI_PATH环境变量才能执行。 Applying this in the run config is fairly straight forward and allows me to run the script as intended from within Eclipse. 将其应用到运行配置中非常简单,这使我可以在Eclipse中按预期运行脚本。

Exporting the runnable JAR is working well with everything except UnsatisfiedLinkError is being thrown which was the same exception I would receive when I didn't have the aforementioned variables set. 导出可运行的JAR可以正常工作,除了抛出UnsatisfiedLinkError之外,这与我没有设置上述变量时会收到的异常相同。

Is there a convenient way to export the below settings into the runnable JAR?: 是否有方便的方法将以下设置导出到可运行的JAR? 在此处输入图片说明

The idea is to essentially generate a stand-alone executable JAR that executes the Sikuli script. 这个想法实际上是生成执行Sikuli脚本的独立可执行JAR。

I have attempted to manually set PATH and SIKULI_HOME which worked as intended ( echo %PATH% & echo %SIKULI_HOME% both print the required paths). 我试图手动设置PATHSIKULI_HOME ,它们按预期工作( echo %PATH%echo %SIKULI_HOME%都打印所需的路径)。 However I'm still receiving the same UnsatisfiedLinkError . 但是我仍然收到相同的UnsatisfiedLinkError Below is the relevant StackTrace: 以下是相关的StackTrace:

C:\Users\XXXXX\Desktop>java -jar sikuli.jar -Dsikuli.Debug=3 -Djava.library.path = "C:\Program Files (x86)\Sikuli X\"
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at     org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Sikuli X\libs\Win32Util.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
    at org.sikuli.script.Win32Util.<clinit>(Win32Util.java:19)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.sikuli.script.Env.getOSUtil(Env.java:91)
    at org.sikuli.script.ScreenHighlighter.init(ScreenHighlighter.java:180)
    at org.sikuli.script.ScreenHighlighter.<init>(ScreenHighlighter.java:293)
    at org.sikuli.script.Screen.initBounds(Screen.java:105)
    at org.sikuli.script.Screen.<init>(Screen.java:117)
    at org.sikuli.tests.TestSikuli.main(TestSikuli.java:13)

I don't think there is an out of the box way, since this is os specific. 我认为没有开箱即用的方式,因为这是特定于操作系统的。 If you're on Windows, just create a batch file with lines along 如果您使用的是Windows,则只需创建包含以下行的批处理文件

 set PATH=%PATH%;...
 set SIKULI_HOME=...
 %JAVA_HOME%\bin\java yourrunnable.jar

Adding an environment variable was not sufficient. 添加环境变量还不够。 I had to log in as Administrator and set up System Variables and append the Sikuli libs path in PATH and create a SIKULI_HOME path with the base path for SikuliX . 我必须以管理员身份登录并设置系统变量,并在PATH附加Sikuli libs路径,并创建一个SIKULI_HOME基本路径的SikuliX路径。

After that I read that it is not recommended to maintain the Sikuli files within Program Files(x86) and instead moved them over to C:\\Users\\my_user\\SikuliX . 之后,我读到不建议在Program Files(x86)维护Sikuli文件,而是将它们移到C:\\Users\\my_user\\SikuliX


Also, the Sikuli-Java.jar is not to be kept within the project workspace (and referenced internally) but rather outside of the project (actually SikuliX path) and should always be kept there. 另外, Sikuli-Java.jar不应保存在项目工作空间内(并在内部引用),而应保存在项目外部(实际上是SikuliX路径),并且应始终保存在该位置。

If you modify any folders regarding SikuliX be sure to remove redundant copies to avoid possible collision issues with future updates. 如果您修改了有关SikuliX的任何文件夹,请确保删除冗余副本,以避免将来的更新可能发生冲突。

Some of this information may be redundant such as the movement from Program Files to User folder however that solved the issue for me. 这些信息中有些可能是多余的,例如从“ Program Files到“ User文件夹的移动,但是这对我来说解决了这个问题。


Note—if any modifications are made to System Variables, be sure to atleast logout and log back in so that they take affect. 注意-如果对系统变量进行了任何修改,请确保至少注销并重新登录,以使它们生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM