How to create a Runnable jar from an OSGI project - jar

Is it possible to convert an OSGI project to jar?
I tried to export as a runnable jar using eclipse, But it did not work because launch configuration didn't show up.

Related

Error: JavaFX runtime components are missing, (Permanent Solution)

I know you can solve this by adding
--module-path "pathToLib" --add-modules javafx.controls,javafx.fxml,javafx.graphics when running the jar file in command line.
But my question is, Is there no permanent solution to solve this error in system settings or configurations and be able to run a jar file as normal as java -jar myfile.jar rather than every time I am suppose to add the module java --module-path "C:\Users\..\Downloads\javafx-sdk-17.0.2\lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics -jar myfile.jar
Also I know you can make a script for this operation for every jar file, but I was thinking of something like system settings or configuration that will be applicable for all jar file with javafx, and be able to run the jar file as normal as java -jar myFile.jar
I am using Ant as a build tool.
Recommended Alternatives
See the packaging resources of the JavaFX tag for recommended alternate solutions to a jar distribution: jlink, jpackage, or native image.
Using JRE's that include JavaFX
Pre-installed JREs that include JavaFX, such as some Bellsoft, Zulu, and Corretto distributions, will execute JavaFX apps without additional module specifiers because they include the JavaFX modules in the base module setup for their distributions.
Note, you must use the correct versions of the JDKs if you want a JDK which includes JavaFX (not all JDKs include JavaFX):
for BellSoft, download and install the "Full JDK", not the "Standard JDK".
for Zulu, download and install the package type "JDK FX", not "JDK".
You can also create your own JRE distribution that includes JavaFX modules using jlink (which is actually simpler to do than it may sound).
Using ant to build a single JAR containing App and JavaFX components
But I still hope that there might be a solution for the above while working with ANT as building tool for JavaFX.
There is some info on building modular JavaFX apps with ant in this answer:
bad name in value for --add-modules when trying to compile through ant
It probably isn’t everything you are looking for though.
To create a single executable jar using ant, you could try emulating the output of this maven JavaFX shade on classpath answer:
Maven Shade JavaFX runtime components are missing
But use ant tasks to build the massive shaded jar instead of maven. I don’t have explicit instructions for that, you would need to work out to accomplish that non-trivial task yourself.
The created jar will include a launcher class, your application code, dependent library code, JavaFX java, and native code. The jar will run on any modern JRE as long as you have included the native code for the relevant platform. The jar will run in the unsupported classpath configuration.
Zip Distributions
Or (better) create a zip distribution:
only put your own code in your app jar.
place the dependent libraries and JavaFX modules in a lib directory.
Create a script that invokes Java with your jar file running with the modules in the lib directory added.
Make your app modular if possible:
Define a module-info.java.
This step isn’t strictly necessary or reasonably possible for some apps.
Use ant to place everything in a zip file for distribution.
Include a jlink generated JRE in the zip if you want.
Note: the maven JavaFX plugin, once properly configured, can accomplish most of these tasks with a single command:
mvn javafx:jlink
Additional info
See the eden guide for resolving JavaFX runtime components.
Add a module-info.java file under your java/ folder and populate it with the following content:
module module_name {
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
requires java.base;
requires java.desktop;
opens com.example.matformater to javafx.graphics;
opens com.example.matformater.controller to javafx.fxml;}

Run Spring batch with CommandLineJobRunner error impossible to find or load main class CommandLineJobRunner

I am new to Spring batch and want to run a batch with a command line using CommandLineJobRunner class, So I copied the generated jar file and CommandLineJobRunner to my Desktop and after I ran the following command:
Java -cp spring-batch-example.jar org.springframework.batch.core.launch. support. CommandLineJobRunner classpath: /jobs/file-import-job. xml simpleFileImportJob
which give this error (impossible to find or load main org. springframework. batch. core. launch. support. CommandLineJobRunner).
I think that I should deal with the classpath, I don't know how doing it.
You need to add Spring Batch jars to the classpath too, something like:
java -cp spring-batch-example.jar:lib/* org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/jobs/file-import-job.xml simpleFileImportJob
where lib contains Spring Batch jars and their dependencies. Note that if you are on windows, you need to use ';' instead of ':' to separate classpath entries.
I recommend to use maven shade plugin or a similar plugin to create an uber jar, or use Spring Boot and it will do it for you. In both cases, you would be able to run your job with:
java -jar spring-batch-example.jar

UnsatisfiedLinkError running .jar of alljoyn project, no error when running in Eclipse

I am creating a simple Alljoyn java application to send and respond to a few signals. When I run the code in Eclipse (on Win7) it runs fine. However when I export it as a runnable jar file and attempt to run that I get the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no alljoyn_java in java.library.path
The exception is triggered upon calling executing the following code:
static { System.loadLibrary("alljoyn_java");}
I have configured the build path of the project to use the external jar alljoyn_java and set the Native library location of that library to the parent directory of the alljoyn_java.dll file.
You have to place the files alljoyn_java.dll, alljoyn_java.lib and alljoyn_java.exp in the same directory of the jar file.
Then, run the jar with the following command:
java -jar -Djava.library.path=. [your-jar-file.jar]
The JVM looks for native libraries at path specified in java.library.path (as mentioned in answer above) and/or path specified in environment variable LD_LIBRARY_PATH. Either use the command mentioned in comment above or add path of directory containing your library to environment variable LD_LIBRARY_PATH.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<<path_of_dir_containing_lib>>
java -jar <<your_jar_file>>
So what I ended up doing is downloading jarsplice and using that to add the native libraries after I exported the project from Eclipse as a .jar

Check that a Clojurescript jar file is working

I have some Clojurescript source files that output messages to the browser console on a timer. Eventually I would like to make a Clojars library from these files. So far I have created an uberjar using lein. All the user of this library would need to do is :require a namespace from the library, and messages should be emitted to the browser console. Seeing these messages is the "all working fine" test I want to perform.
In other words how do I check that the jar file I have created works? Can I start off with a fresh lein project and just put the jar file in some special 'un-managed' directory and :require the namespace? Actually I don't think you can do such a thing with lein, hence the question.
Assuming you have a project.clj file already with the line
(defproject bigco/biglib "0.1.0-SNAPSHOT”
...
run
lein install
This will build the JAR and install it in your local Maven repo.
Then in your new project, add that dependency and run it.
If your jar (definition of jar includes uberjar of course) does not come neatly from a lein project then an alternative is to use Maven 2 directly:
mvn install:install-file -Dfile=./my-deps.jar -DgroupId=my-deps -DartifactId=my-deps -Dversion=1.0.0 -Dpackaging=jar
Here mvn will store the jar in your local .m2 maven repository. Once stored you can use this jar in any lein project on your machine by referring to it in the dependencies section:
[my-deps "1.0.0"]
Maven documentation for this.

PlayN Export runnable .jar File in Eclipse

I'm unable to export a runnable .jar file.
When I export the java project (using the eclipse export wizard) and then try to run the resulting .jar file I only get errors that jwgl library can't be found!
What can I do to get a working .jar file?
Thanks in advance!
Regards Fleckdalm
You can export runnable jar with maven. Just run
mvn package
and projectname.jar and projectname-jar-with-dependencies.jar will apear under target directory.

Resources