Mam projekt Java, który używa this driver do komunikacji szeregowej. Sterownik używa biblioteki DLL w systemie Windows do tworzenia portów szeregowych.Jak dodać ścieżkę do biblioteki rodzimej do zadania JUNIT?
Projekt zawiera kilka testów JUnit, które pomyślnie zakończono przy użyciu testu "Uruchom jako -> JUnit". Jednak testy odwołujące się do biblioteki natywnej kończą się niepowodzeniem podczas działania ant (i testów, które nie odwołują się do przepustki natywnej biblioteki).
Według mojej najlepszej przypuszczenia, do katalogu java.library.path należy dodać katalog zawierający bibliotekę macierzystą, ale nie udało mi się tego zrobić poprzez plik build.xml.
Czy ktoś może powiedzieć (czyste) rozwiązanie?
Oto moja build.xml:
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${junit_home}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="test.classpath">
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${junit_home}">
<include name="**/*.jar"/>
</fileset>
</path>
<target name="compile">
<mkdir dir="${bin}" />
<echo Message="Compiling src folder..." />
<javac includeantruntime="no" classpathref="compile.classpath" srcdir="${src}" destdir="${bin}" />
<echo Message="Compiling test folder..." />
<javac includeantruntime="no" classpathref="compile.classpath" srcdir="${test}" destdir="${bin}" />
</target>
<target name="test">
<mkdir dir="${test.reports}" />
<junit fork="yes" printsummary="yes" haltonfailure="yes">
<test name="${test.class.name}" todir="${test.reports}" />
<formatter type="xml" />
<classpath refid="test.classpath" />
</junit>
</target>
I tu jest częścią testu (w formacie XML):
<testcase classname="nl.timo.comport.test.buildservertests.ComportFactoryTest" name="testGetInstance" time="0.0" />
<testcase classname="nl.timo.comport.test.buildservertests.ComportFactoryTest" name="testCreateDefaultComport" time="0.016">
<error message="giovynet.nativelink.SerialPort.getStateSerialPortC(Ljava/lang/String;)Ljava/lang/String;" type="java.lang.UnsatisfiedLinkError">java.lang.UnsatisfiedLinkError: giovynet.nativelink.SerialPort.getStateSerialPortC(Ljava/lang/String;)Ljava/lang/String;
at giovynet.nativelink.SerialPort.getStateSerialPortC(Native Method)
at giovynet.nativelink.SerialPort.getFreeSerialPort(SerialPort.java:50)
at package.comport.GioComport.getFreeSerialPorts(Unknown Source)
at package.comport.GioComport.findDevice(Unknown Source)
at package.comport.GioComport.<init>(Unknown Source)
at package.comport.ComportFactory.createNewPort(Unknown Source)
at package.comport.ComportFactory.createComport(Unknown Source)
at package.comport.test.buildservertests.ComportFactoryTest.testCreateDefaultComport(Unknown Source)
</error>
</testcase>
<testcase classname="nl.timo.comport.test.buildservertests.ComportFactoryTest" name="testCreateComportWithWrongSettings" time="0.0">
<error message="giovynet.nativelink.SerialPort.getStateSerialPortC(Ljava/lang/String;)Ljava/lang/String;" type="java.lang.UnsatisfiedLinkError">java.lang.UnsatisfiedLinkError: giovynet.nativelink.SerialPort.getStateSerialPortC(Ljava/lang/String;)Ljava/lang/String;
at giovynet.nativelink.SerialPort.getStateSerialPortC(Native Method)
at giovynet.nativelink.SerialPort.getFreeSerialPort(SerialPort.java:50)
at package.comport.GioComport.getFreeSerialPorts(Unknown Source)
at package.comport.GioComport.findDevice(Unknown Source)
at package.comport.GioComport.<init>(Unknown Source)
at package.comport.ComportFactory.createNewPort(Unknown Source)
at package.comport.ComportFactory.createComport(Unknown Source)
at package.comport.test.buildservertests.ComportFactoryTest.testCreateComportWithWrongSettings(Unknown Source)
</error>
</testcase>
<system-out><![CDATA[]]></system-out>
<system-err><![CDATA[java.lang.UnsatisfiedLinkError: no libSerialPort in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
Dzięki za odpowiedź! To zastępuje ścieżkę, prawda? Jak mogę ** dodać ** mój katalog do ścieżki (ścieżka = ścieżka + nowy katalog)) – Timo
@Timo, możesz znaleźć [pathconvert] (http://ant.apache.org/manual/Tasks/pathconvert .html), aby był przydatny do tego celu. Zobacz także [to pytanie SO] (http://stackoverflow.com/questions/2140637/how-do-i-build-a-list-of-file-names). –
' ' Czy to również zadziała? –
Timo