Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, November 2007
Maven2 and Jambi


Message 1 in thread

Hi,

Does anyone have any experiences using Maven2 [1] with Jambi? I
can't get it to work, possibly because of difficulties with loading
libraries inside a jar file.

When I make Maven2 use the qtjambi.jar file shipped with the .gz package
I get compile time errors saying QApplication can't be found etc. I
tried to just rename the .gz to .jar, this results in no compile time
errors, however the following runtime exception i thrown:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.trolltech.qt.core.QtJambi_LibraryInitializer.__qt_initLibrary()V
	at com.trolltech.qt.core.QtJambi_LibraryInitializer.__qt_initLibrary(Native Method)
	at com.trolltech.qt.core.QtJambi_LibraryInitializer.<clinit>(QtJambi_LibraryInitializer.java:10)
	at com.trolltech.qt.core.QAbstractFileEngineHandler.<clinit>(QAbstractFileEngineHandler.java:10)
	at com.trolltech.qt.QtJambi_LibraryInitializer.<clinit>(QtJambi_LibraryInitializer.java:24)
	at com.trolltech.qt.QtJambiObject.<clinit>(QtJambiObject.java:29)


Anyone have the same problem?

[1] http//maven2.apache.org

-- 
 [ signature omitted ] 

Message 2 in thread

Jostein Gogstad wrote:
> Hi,
> 
> Does anyone have any experiences using Maven2 [1] with Jambi? I
> can't get it to work, possibly because of difficulties with loading
> libraries inside a jar file.

Hi Jostein,

First of all, do the Qt Jambi examples run? They are started by 
qtjambi.exe on windows and qtjambi.sh on linux / mac os x. If not then 
we need to figure out the libraries don't load. The native libraries are 
loaded from the local disk, and are located in the JAMBI/bin directory 
on windows and JAMBI/lib on Mac OS X and Linux.

On windows open up a shell and set classpath to include qtjambi.jar in 
the qtjambi directory. Then try to launch the using:

java -Dcom.trolltech.qt.verbose-loading com.trolltech.launcher.Launcher

On Linux you can just add edit the .sh file to add the -Dcom... command 
above to the "java" command. This will give you loads of messages on how 
and where Qt Jambi tries to resolve the native libraries. If you're 
doing this on Mac OS X you may also need to specify

export DYLD_LIBRARY_PATH=$PWD/lib

prior to trying to run examples.

> When I make Maven2 use the qtjambi.jar file shipped with the .gz package
> I get compile time errors saying QApplication can't be found etc.

I haven't tried maven, so all suggestions will be taken out of the blue, 
but this sounds just like a normal classpath issue. Does maven look in 
the classpath or do you need to specify .jar files explicitly as 
dependencies? Do you also need to have some special .jar file metadata 
for maven to load accept them in the build path? There is nothing 
special about our qtjambi.jar file. It contains only class files and a 
few resources so it should behave just like any other .jar file.

> I
> tried to just rename the .gz to .jar, this results in no compile time
> errors, however the following runtime exception i thrown:

Which .gz file is this? The qtjambi-linux32-gpl-4.3.2_01.tar.gz? I 
suspect maven just rejects the file from the build completely as its not 
a valid .jar file.

best regards,
Gunnar


Message 3 in thread

Gunnar Sletta:
> Hi Jostein,

Hi Gunnar,

> First of all, do the Qt Jambi examples run? They are started by 
> qtjambi.exe on windows and qtjambi.sh on linux / mac os x. If not then 
> we need to figure out the libraries don't load. The native libraries are 
> loaded from the local disk, and are located in the JAMBI/bin directory 
> on windows and JAMBI/lib on Mac OS X and Linux.

Yes, the examples run perfectly. In fact my application also runs
perfectly, I just can't get Maven to load the libraries right.
 
> On windows open up a shell and set classpath to include qtjambi.jar in 
> the qtjambi directory. Then try to launch the using:
> 
> java -Dcom.trolltech.qt.verbose-loading com.trolltech.launcher.Launcher

Great, exactly what I was looking for. I got an interesting exception
each time a .so file is loaded. Below is an example.

Going to load: libcom_trolltech_qt_svg.so
.. from environment: com.trolltech.qt.library-path (Skipped, environment was empty)
.. from environment: com.trolltech.qt.internal.jambipath (Skipped, environment was empty)
.. from classpath: java.lang.RuntimeException: Library: 'libcom_trolltech_qt_svg.so' could not be resolved
	[stacktrace here]
Loaded(/usr/local/lib/qtjambi-linux32-eval-4.3.1_01/lib/libcom_trolltech_qt_svg.so) using deploy path, as libcom_trolltech_qt_svg.so

The line which loads the jar file in qtjambi.sh now looks like this
(only changes is the verbose part in the java sentence).

	PATH=$me/bin:$PATH
	QT_PLUGIN_PATH=$me/plugins
	java -cp $me/qtjambi.jar:. -Dcom.trolltech.qt.verbose-loading com.trolltech.launcher.Launcher
 
$me is set to $(dirname $0) earlier in the file. Nothin in the file has
been modified though.

> >When I make Maven2 use the qtjambi.jar file shipped with the .gz package
> >I get compile time errors saying QApplication can't be found etc.
> 
> I haven't tried maven, so all suggestions will be taken out of the blue, 
> but this sounds just like a normal classpath issue. Does maven look in 
> the classpath or do you need to specify .jar files explicitly as 
> dependencies? Do you also need to have some special .jar file metadata 
> for maven to load accept them in the build path? There is nothing 
> special about our qtjambi.jar file. It contains only class files and a 
> few resources so it should behave just like any other .jar file.

Maven mainly decribes which libraries/dependencies the sourcecode  will
be compiled against and put in the library dir of the finished  build.
The Maven artifact is a folder that contains .class files and the
libraries in an own dir. Unless told otherwise, it will copy the
libraries and resources (jars, zips, dll's aso) to the target/
classes/lib directory as they are.  When running the application that
has been compiled by Maven, it  will have all the necessary dependencies
in its classpath.

The possible problem that I can see is if the resources need to be
zipped or uncompressed in any particular fashion so that the
application can reference them. Or if the application expects to find
the resources in a zip file of a certain name, or in a specific
location relative to the directory of ... say qtjambi.jar. With the
exception thrown above, I suspect the latter to be the case.

Do you know why the .so files can't be resolved from the classpath?
 
> >I tried to just rename the .gz to .jar, this results in no compile
> >time errors, however the following runtime exception i thrown:
> 
> Which .gz file is this? The qtjambi-linux32-gpl-4.3.2_01.tar.gz? I
> suspect maven just rejects the file from the build completely as its
> not a valid .jar file.

Most likely, never mind that.

Thanks for your reply.

-- 
 [ signature omitted ] 

Message 4 in thread

Jostein Gogstad wrote:
> Great, exactly what I was looking for. I got an interesting exception
> each time a .so file is loaded. Below is an example.
> 
> Going to load: libcom_trolltech_qt_svg.so
> .. from environment: com.trolltech.qt.library-path (Skipped, environment was empty)
> .. from environment: com.trolltech.qt.internal.jambipath (Skipped, environment was empty)
> .. from classpath: java.lang.RuntimeException: Library: 'libcom_trolltech_qt_svg.so' could not be resolved
> 	[stacktrace here]
> Loaded(/usr/local/lib/qtjambi-linux32-eval-4.3.1_01/lib/libcom_trolltech_qt_svg.so) using deploy path, as libcom_trolltech_qt_svg.so

As you can see, it actually loads the library, so the message above 
indicates success in this case. It loads the library relative to 
qtjambi.jar in the lib folder.


> The possible problem that I can see is if the resources need to be
> zipped or uncompressed in any particular fashion so that the
> application can reference them. Or if the application expects to find
> the resources in a zip file of a certain name, or in a specific
> location relative to the directory of ... say qtjambi.jar. With the
> exception thrown above, I suspect the latter to be the case.
> 
> Do you know why the .so files can't be resolved from the classpath?


The .dll's need to be located relative to qtjambi.jar like this:

JAMBIDIR/qtjambi.jar
JAMBIDIR/lib/libcom_trolltech_...so
JAMBIDIR/lib/libqtjambi.so
etc...

So they need to be copied to a subfolder of the location of qtjambi.jar. 
If maven is incapable of doing this I suggest you put all native 
libraries into a .jar file as suggested by our deployment guide.

http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/qtjambi-deployment.html

best regards,
Gunnar