Maven: How to create an api jar? - java

I have an Kotlin/Java project with maven, and other people should be able to write stuff based on it.
But I dont want to share the whole source code with them. Thats why I want to create a JAR that only includes functions and stuff, so its like an API.
E.g. a function has an empty body in that API JAR. But they can still build another project on their own on this lib without them having the source code. It will be build and deployed by Jenkins if they commit. The only question I have is, how to create this JAR with basically "no code" in it.

Related

Adding an External JAR and all its Dependencies in Eclipse

I am trying to add a single external JAR file to my Eclipse path to make it able to perform a needed function. I have attempted to load in the project through Maven in hopes that it would gather all needed dependencies, but it still gives me an error.
Is there an easy way to make one single call to the internet to download all necessary dependencies for an External JAR (and all their dependencies, etc, etc)?
Mind you, this code is a very specific, one-time implementation that does not need to be exported or run on any other machine. Even if the program I'm writing will not ever work as a JAR on it's own, that's okay. I just need a quick and easy way to get all my dependencies in one shot.

using a library file from within jar

This is a follow up of this question
What I try to do:
I have an eclipse project that uses th Sigar library in order to get the cpu information (among others). In order to do that Sigar needs a library file to work. Each CPU/OS have a different file, all of which are available.I have to pack this into a jar, that other can use my application as a library.
What I did:
added the available library files to my project and can access them like so
System.setProperty("org.hyperic.sigar.path",System.class.getResource("/lib").getPath());
System.load(System.class.getResource(getClass().getResource(
"/lib/libsigar-amd64-linux.so").toString()).getPath());
Both of these seems to work if i run my application as a stand alone application.
When i pack it to a jar and try to run it from an other project, it just doesn't work. I cant make it to see the directory or the file.
This is the structure of my project
I have tried to access the file with any path i could think of, but all returned a NullPointerException.
How can I do this? Using a temp file? I am not sure how i should do this, i would like to load the whole folder and not just one file, since i dont know the hardware/OS of the client application.

Add Native Shared Library (.so or .dll/.lib) to Jar File Using Maven Plugin

There are lots of posts about this already but I have not found one that describes my exact situation. Which is:
I have a preexisting build system that generates a C++ shared library in both .dll and .so format (depends on OS).
The build system also produces a set of java files generated by swig.
I also have a pom.xml file that builds the java source into a package.
What I need is a plugin for maven that simply copies the native shared library into the jar. It would be nice if the native shared library was also loadable from within the jar so clients don't have to manually add it to the library path. This seems like a problem that has been solved before.
I have looked at maven-dependency-plugin. Which seems to be able to copy artifacts that are in a maven repository (not my case). Or if you use an assembly it might be possible. However, if it is possible, it seems overly complicated for what I want to accomplish. I would like to accomplish it with only a pom.xml.
I have also looked at nar-maven-plugin, but this seems like it focuses only on building the native library and adding it to a .nar file. This is not what I need since I can already build the C++ library.
Finally, I looked at one-jar which I got to place the native library inside the jar. However, I was not able to import the classes from within that jar, and the clients of this library will expect to be able to do that.
If what I want is possible and I don't need to install the shared library into my local repository please provide a link or an example of how you accomplished it. If it is not possible, please state why.

Create a third pary library jar with JPA project

First off, I am pretty new to this. I am working on a desktop application which uses hibernate and an embedded h2 database. I am trying to create this project with 'modules' so that we may easily update code as needed. Right now I am trying to create a separate project witch contains our entity definitions, named-queries, and persistence.xml file. I created a JPA project to do this. My question is, how do I export this jar in order to be able to replace it in the future when changes are made? I create a runnable jar which points the the main of the core application, which I am not sure about, and it will run. My problem is when I create the lib folder next to the runnable jar of the core application, my custom 3rd party library containing our entity definition is not there? I am guessing this is because of how I pointed the library to the main of the core application, but as I said I have little experience with this so I am not sure. I cannot seem to find anything helpful out there but I know it must exist. If anyone knows what my issue is or where I should go to read about it, I would be most grateful.
It seems that the problem is with how you package your app? Be aware that a JAR file cannot include other JAR files (at least they are not included in the classpath). Only WAR and EAR may contain another JAR files. If you want to include a JAR nested in another JAR, you must repackage them and merge into a big JAR file, not only put one into another.

Eclipse - record and apply move and rename refactorings to another workspace

I'm currently working in a big java project with quite a few submodules that are worked on by different teams. Some of these teams are building the "framework", others are building the "application" based on the framework.
When the framework guys move or rename a class, the applications guys get compile errors wherever they are using a refactored framework class. Is there a way in Eclipse (Galileo Release) to record the change and update the references in another workspace?
What I've tried so far is creating a refactoring script during the rename refactoring, but when I try to apply that script to another workspace, it fails with The refactoring 'Rename Type' (org.eclipse.jdt.ui.rename.type) cannot be performed, since its input 'xxx.TestClass" does not exists. Well, it does not exist (anymore) alright, but what I want is for all references for xxx.TestClass in my project to be changed to xxx.MyRenamedTestClass. Is there a way in Eclipse to do this with built-in functionality or an existing plugin or do I have to write one myself?
Thanks for your help!
EDIT: By now I found out that the "Migrate JAR"-Plugin provides the functionality I am looking for, although we build our JARs with Maven, not Eclipse. I'm going through the source code now to find out what parts I can reuse.
Answering my own question to get some closure here.
The easiest way to do it is to use the Migrate JAR File... refactoring which uses a refactoring script in META-INF called REFACTORINGS.XML. You can get a JAR with this included automatically by using Export JAR in Eclipse. We build with Maven and thus just do Refactoring->Create Script... and put it into the appropriate position in the JAR.
The JDT-internal code that Migrate JAR executes creates Stubs for the source classes in a temporary source folder, so it actually executes the refactoring first and then updates the references. The user never gets to see these temporary files.

Categories

Resources