简体   繁体   中英

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. Applying this in the run config is fairly straight forward and allows me to run the script as intended from within 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.

Is there a convenient way to export the below settings into the runnable JAR?: 在此处输入图片说明

The idea is to essentially generate a stand-alone executable JAR that executes the Sikuli script.

I have attempted to manually set PATH and SIKULI_HOME which worked as intended ( echo %PATH% & echo %SIKULI_HOME% both print the required paths). However I'm still receiving the same UnsatisfiedLinkError . Below is the relevant 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

 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 .

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 .


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.

If you modify any folders regarding SikuliX be sure to remove redundant copies to avoid possible collision issues with future updates.

Some of this information may be redundant such as the movement from Program Files to User folder however that solved the issue for me.


Note—if any modifications are made to System Variables, be sure to atleast logout and log back in so that they take affect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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