Fat jar with dependencies of imported jars - netbeans

I am rebuilding a decompiled fat jar. The fat jar embeds the dependencies of the compiled jar. The fat jar I have decompiled also includes jar files that are not imports of the code of the main compiled jar. I assume then that these jar files are dependencies of the jar files that are imported by the code.
I have included under Projects / project / Libraries (an Ant project) all the jar files (directly imported jars and those I assume are dependencies of the latter) and built the project to create a fat jar, but the jars which I assume are dependencies of the imported jars are still not being bundled. Is there any way I can include these in the fat jar?

Related

sbt how to specify dependency to a sibling project

I have a main sbt project which depends on two sbt subprojects, 'util', and 'common'. In addition the common project depends on the util project. In the build.sbt of the common project, how should I specify the dependency to the sibling project util, so that I can compile the common project independently?
Many thanks.
Azad

How to include jars under lib in multi-project sbt setup?

I have a project that is similar to the sbt-multi-project-example one. The only difference is that I have two already compiled jar dependencies inside a lib/ folder on root folder.
On a single-project sbt setup it automatically collects those jars and use them to compile my project, but in this case it is not being collected by the sub-projects.
Only one of my sub-projects require those jars.
Where should I put those jars and how should I setup build.sbt to recognize them?
Put the jars in a lib/ folder in the sub-project that requires them.

How to create multiple executable jars under same project, same src with sbt assembly

I have one project and project directory looks like this:
aProject/
build.sbt
project/Build.scala
src/main/scala/
packageA/MainA.scala
packageB/MainB.scala
I want to package 2 fat jars, one containing packageA.MainA and the other containing packageB.MainB. How can I do this with sbt-assembly?

Include Dependencies in JAR using SBT package

Apparently project dependencies are not being packaged into the jar generated by:
sbt package
How can dependencies be included?
Well, I use sbt-assembly plugin to create jar with dependencies,
(1) add sbt-assembly to projects/assembly.sbt
echo 'addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")' > project/assembly.sbt
(2) run sbt clean assembly to build the jar.
It will create ${name}-assembly-${version}.jar in target/scala-${scalaVersion}
(3) Only in case you get infamous de-duplicate error, use assemblyMergeStrategy as described in here
There's a project called onejar that will package a project and all its dependencies into a single jar file. There is an SBT plugin as well:
https://github.com/sbt/sbt-onejar
However if you're just looking to create a standard package (deb, rpm, etc.) there is sbt-native-packager:
https://github.com/sbt/sbt-native-packager
It can place all your dependencies into a Linux package and add the appropriate wrappers to load all your dependencies and start your program or service.

Including Hyperic Sigar library within jar while using sbt assembly for Scala project

I'm building a Scala project with sbt and creating a fat jar with the sbt-assembly plugin. I'm able to add unmanaged jars (such as the Sigar jar) by adding the following to build.sbt.
unmanagedJars in Compile +=
file("lib/hyperic-sigar-1.6.4/sigar-bin/lib/sigar.jar")
However, when I try running this, I get the following error because the *.so libraries are not included in the jar.
no libsigar-amd64-linux.so in java.library.path
org.hyperic.sigar.SigarException: no libsigar-amd64-linux.so in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.ptql.SigarProcessQuery.create(Ljava/lang/String;)V
at org.hyperic.sigar.ptql.SigarProcessQuery.create(Native Method)
at org.hyperic.sigar.ptql.ProcessQueryFactory.getQuery(ProcessQueryFactory.java:66)
at org.hyperic.sigar.ptql.ProcessFinder.findSingleProcess(ProcessFinder.java:44)
The libraries I want to include are in lib/hyperic-sigar-1.6.4/sigar-bin/lib/*.so and they need to be linked to a directory in the classpath within the jar. The only way I know of to do a mapping like this is:
resourceDirectory in Compile <<=
baseDirectory{ _ / "lib/hyperic-sigar-1.6.4/sigar-bin/lib" }
This causes the *.so libraries to be added to root of the jar, but not a specific directory. How can I specify a resource map to map from lib/hyperic-sigar-1.6.4/sigar-bin/lib/*.so to a directory in the classpath in my jar? What is the terminology for what I'm trying to do?
Assuming that sigar is indeed capable of loading native libs from classpath, this should do the trick:
libraryDependencies += "org.fusesource" % "sigar" % "1.6.4" classifier("native") classifier("")
Otherwise, you need to unpack them from the jar manually and provide proper java.library.path