Using SIGAR with maven - java

I'm currently trying to use Sigar in a maven-build, and it says everytime:
"org.hyperic.sigar.SigarException: no libsigar-x86-linux.so in java.library.path"
I've installed Sigar to maven with mvn install:install-file -DgroupId=org.hyperic -DartifactId=sigar -Dversion=1.6.4 -Dpackaging=jar -Dfile=sigar.jar (where sigar.jar is a jar only with the files in the org-folder, and the maven dependency with the things in the lib-folder), but then it does not find the .so-file.
I've tried to find answers, who mostly say one should unzip the files like Unzip dependency in maven . Unzipping (after installing the other things via install:install-file) does work fine, but the file isn't included in the path after all.
Then I've tried to find something to include the files in the build path, so I did something like this: Surefire JUnit Testing using Native Libraries (I want to use sigar in the tests), but this also doesn't change anything. I've tried it with many different folders, and even adding the file itself and not the folder it is in to the library path, but even this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>-Djava.library.path=${project.build.directory}/lib/libsigar-x86-linux.so</argLine>
</configuration>
</plugin>
does not work, but the file is clearly there. I'm using maven 2.2.1.
Has anybody an hint how to get sigar in this context working?
Thanks in advance,
DaGeRe

Using surefire plugin you do not need to prefix arguments with 'D' prefix (e.g. - -java.library.path=${project.build.directory}/lib/libsigar-x86-linux.so).

Related

Automatically install a project in the local repository?

I'm trying to work around a maven bug MDEP-187 ( https://issues.apache.org/jira/browse/MDEP-187 ) by not using workspace resolution.
This forces me to do a mvn install for all my dependencies, I'm doing this by creating a launch configuration in eclipse with goal install.
The problem is that i have to create a launch config for every project in my multiproject workspace, in addition to install i have to manually call every launch config and run it. Which just doesn't work.
Is it possible to automatically install a project in the local repository? (whenever i update my code)
If you don't need to run dependency:copy in Eclipse, you can use following work-around:
Add a profile to your pom.xml, something like this:
<profiles>
<profile>
<id>copy</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
[...]
</executions>
</plugin>
</plugins>
<build>
<profile>
</profiles>
Enable workspace resolution in Eclipse.
Then Eclipse will not use dependency:copy, but you can use dependency:copy with command line: mvn install -P copy.
I did go with #khmarbaise solution:
But than you need to can handle the whole thing via
maven-assembly-plugin which can create archives / folders with all the
dependencies. Apart from that a swing ui must be started somehow which
will need some kind of shell script / batch file which you can create
by using appassembler-maven-plugin...And it sounds like you need to go
for a multi module project in maven..cause you might have parts like
core, ui, etc. which are needed to be combined in the end.
#khmarbaise i was in the understanding that the assembly-plugin didn't
support putting dependencies in a lib/ folder (just putting everything
in 1 big jar), but after a little bit of trying i just go myself a zip
with a runnable jar and my dependencies in a lib/ folder. Tomorrow i'm
going to read a bit more about the assembly-plugin. I'm happy ;-

Is it possible to build a java project only once using eclipse and share?

Is it possible to actually build a maven project containing java code to be built once and the binaries can be shared?
Problem: The project I am trying to build would take me about 3-4 hours and requires high internet bandwidth. I am trying to check the possibility of re using this built project among several other machines.
I have worked with c++ projects involving makefiles earlier and this was pretty simpler. I am new to Java / eclipse and would need help to figure out if this is something really possible.
PS:
I did try to find existing solutions; they were not straight forward or they say that this can't be done.
Build once and share it offline
In Maven, you can build your project only once and get a JAR file fully packed with all dependencies. So that, you can share this JAR to other machines off-line.
Below are the steps to make it.
First update your pom.xml with the below setting
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.thanga.MyTest[REPLACE WITH YOUR MAIN CLASS]</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
Package your project with the goal package assembly:single as shown below
In console,
mvn package assembly:single
In eclipse,
Run this and you can get the two JAR files. One of them MyFullPack-0.0.1-SNAPSHOT-jar-with-dependencies.jar has the full
dependencies loaded.
You can open the JAR to see the dependencies are packed as shown below.
You can share this JAR to other machines off-line without any more build
Is it possible to actually build a maven project containing java code to be built once and the binaries can be shared?
Yes, that's the whole point of Maven, you build the project once, thus generating an artifact (your jar/war ...) which is stored in your local maven repository.
The following command build the project and save it in the local repo :
mvn clean install
However, if you do this, you only have the artifact on your local repo.
A good practise is to create a repository and store your artifacts over there :
https://maven.apache.org/repository-management.html
The use of the following command would store the snapshot dependency on the repository :
mvn clean deploy
You can then reuse your components through multiples computer by specifying the dependencies in your new project's pom.xml file.
You might want to give a look at this guide :
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
You would obviously need to configure the repository and your maven project in order to use a setup of this kind.
First things first. Is your project a web application (war) or an enterprise application (ear) or just a stand alone Jar?
you can use the packaging tag in POM.xml to package your application to a JAR,WAR,EAR
Examples:
<packaging>war</packaging>
<packaging>ear</packaging>
<packaging>jar</packaging>
Then run mvn clean install
In project/src/target you should see the jar,war or ear generated which you can use to deploy on your machine or any other machine.
OR
you can also find that in .m2 folder once you have run install.
If you use maven, a mvn install will install your binary into your ${home}/.m2 folder. Those binary will be available for all other maven job that will run on the same machine.
If you need to share your binary between multiple machine, you can deploy your jars to a repository, like nexus or artifactory.
You can just take the jar file of your target folder and copy it to the other machines, otherwise you could use some share repository like nexus oder artifactory to share your built binary. Maven is capable of automatically deploying artifacts into those repositories

java.lang.UnsatisfiedLinkError when using third party library in storm toplogy

I am creating a storm topology that uses a third party library MITIE in one of the bolts. Per the documentation MITIE has some required native libraries and jars that are required for it to run.
It comes packaged with an example java class and script (run.sh) to run it that looks like this:
export LD_LIBRARY_PATH=/opt/MITIE/mitielib
export CLASSPATH=/opt/MITIE/mitielib/javamitie.jar:.
javac NerExample.java
java NerExample
This works. I then modified my ~/.bashrc file to contain the two exports above so I can run the script without having to have these exports in there. I removed the export statements from the script and it also runs fine.
My thought is if I create these two exports in my ~/.bashrc, then when I run my storm topology it should be able to pick up the library directory and work also.
The problem is that for some reason it does not work when I run my storm topology. I get the following error:
java.lang.UnsatisfiedLinkError: no javamitie in java.library.path
I have looked everywhere for an answer, and have tired using the surefire maven plugin in my pom.xml like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<argLine>-Djava.library.path=${basedir}/lib/mitielib</argLine>
</configuration>
</plugin>
but nothing seems to work. Does anyone know how I can get Native Libraries to work within a java storm topology project?
Theoretically if you put any jars inside the storm's lib directory it will be included in the clssspath. Another way could be packaging all the dependencies inside the jar that you are going to submit to the cluster.
After researching all of the possible configurations for the storm.yaml file, there was one provided that I missed the first time around and was exactly what I needed to solve this. by adding:
java.library.path: "/opt/MITIE/mitielib"
to storm.yaml and rebooting storm, everything worked.

How to use Maven pom to download jar files only to a specific directory?

Is there a way to download dependencies from a pom.xml file to a specified folder in java? I'm able to run maven command from java and I got download messages, but I don't know where maven stores these libraries? How can I download these dependencies to a specific folder?
Take a look at maven's dependency plugin, specifically the
copy-dependencies goal. The usage section describes how to do exactly what you want.
To do it from the command line just do:
$ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR
Add this to exclude the transitive or inner dependencies:
-DexcludeTransitive=true
As explained here, you can use maven-dependency-plugin:get for this.
For example, if you want to download org.apache.hive:hive-common:2.1.1 in your local folder, execute this:
mvn dependency:get -Ddest=./ -Dartifact=org.apache.hive:hive-common:2.1.1
If you want to download the latest 3.0.0-SNAPSHOT:tar.gz version of com.orientechnologies:orientdb-community-gremlin from https://oss.sonatype.org/content/repositories/snapshots snapshots repository, execute this:
mvn dependency:get -Ddest=./ -DremoteRepositories=sonatype-nexus-snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dartifact=com.orientechnologies:orientdb-community-gremlin:3.0.0-SNAPSHOT:tar.gz
Add something similar to the following to pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>
${project.build.directory}
</outputDirectory>
</configuration>
</plugin>
Then run mvn clean dependency:copy-dependencies to perform the copy.
Combine this with the assembly plugin and you can package everything into a self contained archive for distribution.
Maven stores all of these in it's local Maven2 repository. By default, it will store them in your user home directory under a directory called repository.
You can use the maven-dependency-plugin's goal called copy to take all of your project's dependencies and put them in a folder.
http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html
Go to this site: http://jar-download.com/online-maven-download-tool.php
Insert the Maven dependencies XML
Download the jar files as a ZIP.

How to resolve Maven exec plugin: classpath too long error?

I have a large Java project with a large number of jar file dependencies. When I try to run the project (using exec) from Eclipse or Netbeans, Maven throws an exception which turns out to be a too large number of entries on the classpath (only 2/3 of the needed entries are included). Does anyone know a workaround for this? (Except from building an executable jar and running it from terminal.) Is it possbile to "extend" the "classpath-buffer"-size?
This is a Maven exec plugin bug, it is documented in MEXEC-68, the reporter created a patch so I hope it will be resolved soon.
One workaround would be to add the classpath to the manifest file using this config for the maven-jar-plugin, add the dependencies to a folder and add just that folder to the CLASSPATH envvar.
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
</project>
This will add to the manifest something like:
Class-Path: plexus-utils-1.1.jar commons-lang-2.1.jar
If that JARs are in a CLASSPATH folder, you can run your JAR using maven exec plugin hidding the classpath with something like:
mvn exec:exec [...] -Dexec.classpathScope="test"
I used -Dexec.classpathScope="test" to make the plugin ignore the dependencies and add just the ones in scope test.
This problem is fixed in Netbeans 6.10M1. Please take a look at Bug 188864. If you have an older version, you can still fix this yourself (you just have to edit an xml file inside org-netbeans-modules-maven.jar).
Then, don't forget to check Maven Best Practices (http://wiki.netbeans.org/MavenBestPractices#Binding_Maven_goals_to_IDE_actions) where it is explained how to bind maven goals to IDE actions.
Regards,
Mach
In Java 6 (which I hope you use) you can use wildcards in classpath entries. For the exact syntax check this page Setting the classpath and search to the right section by searching for "Understanding the class path and package names".
Or you try shortening the paths by placing all required jars in a single folder with a short path. e.g. C:\jars\

Categories