How can I get Ivy to bundle dependencies for MY dependencies into their own jar? - jar

In my project, I have exactly one dependency (right now, it's early!) - Hibernate. In my Ivy config, I have the following:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency org="org.hibernate" name="hibernate-core" rev="5.4.0.Final" conf="sources->sources"/>
<dependency org="org.hibernate" name="hibernate-core" rev="5.4.0.Final" conf="binaries->default"/>
</dependencies>
And in my build.xml, I have this:
<ivy:retrieve conf="sources" pattern="war/WEB-INF/lib/[conf]/[artifact](-[classifier]).[ext]"/>
<ivy:retrieve conf="binaries" pattern="war/WEB-INF/lib/[artifact](-[classifier]).[ext]"/>
Now, in my lib folder, I have a folder called sources with exactly one jar, hibernate-core-sources.jar - perfect!! But in the lib folder itself, I don't have exactly one jar - I have 18 jars, one for each of Hibernate's dependencies (and grandparent dependencies, etc.)
What I'd really like to see is something like hibernate-core.jar and hibernate-core-deps.jar.
Is something like this possible? If it isn't, would it be possible to have it be hibernate-core.jar and my-app-deps.jar? And if THAT isn't possible, can it just bundle it all into a single my-app-deps.jar?
I'm not very experienced with Ivy, so the more explicit your answer, the better!

It's possible, but you have to be aware that when you build the classpath you may end um missing some classes and having NoClassDefFoundError thrown at runtime.
The solution is to call ivy resolve once with transitive set to false, and second time with it being set to true (which is default). After each of these you have to call retrieve but with different retrieve patterns, so the non-transitive (hibernate-core.jar) to lib folder and transitive to a temp folder from which you could create hibernate-core-deps.jar.

Related

built.sbt without .repositories file with m2compatible set to true

i am in a scenario that the artifacts are published to a local maven repository with both both pom file and ivy file. I am trying to access this repository by treating it as an ivy repo, as a result, I had to set m2compatible=true so that the resolvers can correctly identify the path pattern.
sbt allows one to override the default list of resolvers through the following properties:
-Dsbt.override.build.repos=true -Dsbt.repository.config=<path to sbt repository file>
The foramt of the repository file is something like the following,
[repositories]
local
my-artifacts: http://my.artifact.proxyserver.com/artifacts/,[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]
maven : http://my.artifact.proxyserver.com/artifactory/maven-central
My question is how am I able to specify m2compatible=true for the resolver "my-artifacts" in the above file? Because without that setting, if I depend on
com.google.common % guava % 23.1
the resolver will look for the path:
com.google.common/guava/23.1
instead of
com/google/common/guava/23.1
sbt allows to add mavenCompatible towards the end of an ivy resolver.

Maven - SQLite - Missing database

I'm new to maven and I'm trying to make my project work with an sqlite database.
Code works as a normal java project.
I made a Maven project with the exact same working code and added the dependacies in the pom.
pom.xml
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.1</version>
</dependency>
Also, the Library.sqlite is in the root folder of the project (where it works as a normal java project)
works in java, not in maven
"jdbc:sqlite:‪Library.sqlite"
The error reads "[SQLITE_ERROR] SQL error or missing database"
Since it's the same code as the java project, I'm sure there is no syntax error, so it must be something with the location of the Library.sqlite?
How can I make this work?
SOLUTION
It seems my program created a new empty Library.sqlite in my folder and that's why it couldn't find my tables. After deleting the original and editing the new one, it works!
I tried using the same library as you and it seems to work fine for me. Take a look: https://github.com/ajorpheus/SqliteHelloWorld
Sample output after a successful build:
name = leo
id = 1
name = yui
id = 2
Process finished with exit code 0

How to solve 2 classes in dependency with exact same path&name?

I'm using SBT to manage dependencies. I added 2 jars AAA and BBB into my project. However, both AAA and BBB have a class with exact same name and path like com.ccc.ddd.eee.fff.foo.java.
Now, the compiler does NOT complain. However, when I import foo.java, it always comes from jar AAA although, unfortunately, I want it to come from jar BBB.
Any suggestions about how to solve this puzzle? Thank you in advance.
EDIT:
I was using libraryDependencies +=, managed dependencies.
You didn't say how the 2 jars were added; it would be helpful to see your build.sbt.
That said, the classpath is affected by the order in which you list the dependencies. If you are using unmanaged dependencies, and you want a specific version of a class to be found, list that library dependency first.
If they were specified as managed dependencies, it is more common to try something like:
libraryDependencies += "foo" % "bar" % "x.y.z" exclude("org.domain", "AAA")
or:
ivyXML :=
<dependencies>
<dependency org="org.domain" name="AAA" rev="x.y.z">
<exclude module="activation"/>
</dependency>
</dependencies>
There is more information here: http://www.scala-sbt.org/release/docs/Library-Management.html

Export package in OSGi Bundle

I have an OSGi Bundle and a servlet. Now I want to access the bundle from the servlet. For that purpose I use the following in the servlet:
#Resource
BundleContext context
...
ServiceReference ref = context.getServiceReference("package.MyOSGiServiceInterface");
MyOSGiServiceInterface service = context.getService(ref);
The Problem is that my servlet doesn't know MyOSGiServiceInterface 'cause that is defined in the OSGiBundle. In Eclipse I added a reference to the bundle Project in my Build Path. But at runtime it obviously can't find it.
To solve that Problem I played around with
(in bundle manifest)
Export-Package: package-of-osgi-service-interface
(in servlet manifest)
Import-Package: package-of-osgi-service-Interface
Dependencies: ...,deployment.MyBundle
But I couldn't solve it.
Whats the missing step? How can I tell JBoss to add the package containing MyOSGiServiceInterface in OSGiBundle to the class path?
Thanks for answers!
(JBoss AS 7.1.1)
--> error message <--
Eventually I solved it. I had to put the right combination of settings together to reach my goal:
Deploy the bundle per: File - Export - "Deployable plug-ins and fragments" into folder: "jboss/standalone/deployments"
Bundle-Manifest:
Bundle-SymbolicName: TestBundle
Bundle-Version: 1.0.0
Export-Package: "package-which-includes-my-service"
Servlet-Manifest:
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.TestBundle:1.0.0
Import-Package: "package-which-includes-my-service"

NoClassDefFoundError: org/jbox2d/collision/shapes/Shape in netbeans

I am trying to add jbox2d as a dependency to my project in netbeans (playn-jbox2d-1.1-SNAPSHOT.jar), but at run time, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jbox2d/collision/shapes/Shape
All other classes can be accessed fine, just not Shape.
I simply right clicked dependencies in my core directory and did add dependency and searched for jbox2d.
Anyone know what could be wrong?
What version of jbox2d do you have, as a dependency? You can crosscheck in the dependency jar file, if that class (Shape.class) exists or not?
EDIT: Most of the times, 'NoClassDefFoundError' happens due to incorrect classpath settings or when there's more than one class (or jar file) in the classpath, with the same namespace.

Resources