I use IntelliJ IDEA IDE and I want use the Gradle system as a build system in my JavaFX application. I want to create preloader for my program and pack it with program into one jar file. Here says that I must have at least two modules: application and preloader. How build the JavaFX application with preloader by using gradle system?
Disclaimer: I'm the creator and maintainer of the javafx-gradle-plugin.
You don't need to create some preloader, it is used while the JVM loads the libraries and while booting all classloaders, but you don't have to create some preloader.
There is a conflict in interests here: you are using two systems to generate that javafx-appliaction, one is the gradle-build-system, the other is your IntelliJ IDEA-IDE. There is a JavaFX-plugin for IDEA, which does some things, and there is the gradle-plugin i wrote, which does some things withing normal gradle-development-cycle.
The javafx-gradle-plugin is IDE-agnostic, so you are not required to have some IDEA-plugins enabled.
To have some example with included usage of proguard, you can see it at github.
Related
I'm currently experimenting with golang's plugin system. A problem which I experienced in my testings is that the file size of the plugins is relativly big.
The application loading the plugin will be referenced as "host".
The host application itself is ~50MiB big since it is a web application and should be extended with plugin functionality.
I've implemented a small plugin loader to start the plugins up.
The plugins may use the already existing APIs in the application for example to access the database.
I've prepared a example plugin for this question. The plugin .so file size is ~39MiB. This gives me the reasonable suspicion that the plugin also contains source code from the host application.
Command used to create main.so:
go build -ldflags="-s -w" --buildmode=plugin main.go
Is it possible to "remove" the duplicated source code from the application to reduce file size since it is already loaded on runtime when the plugin gets loaded?
Plugin loader: https://github.com/jonasfranz/gitea/blob/feature/plugin/modules/plugins/loader.go
Example plugin: https://git.jonasfranz.software/JonasFranzDEV/giteaplugin
Source code is not included in plugins. But what is included in them is their dependencies, recursively. This is so because there is no guarantee that the main app that loads the plugin also contains the dependencies, so to ensure the viability of the plugin, its dependencies must be self-contained.
This does not cause problems if the main app also include the same dependencies (with the same version), they will only be "instantiated" once in the go runtime, for details, see How do Go plugin dependencies work?
What to do in order to reduce plugins' sizes? Besides removing the debug information (what you did), you should minimize the dependencies.
This may require redesign and major changes both in the plugin or in the app you wish to create the plugin for. For example, plugins should not refer to "implementation" packages, plugins should only refer to "interface" packages. If interfaces and implementations are not separated, this may not be possible (hence may it be required to change the main app too).
You may also try utilities that try to compress binaries, for details see: Shrink your Go binaries with this one weird trick
Does anyone know if there is a way to use JavaFX modules in eclipse workspace? I have an OSGi-maven multi-modular application.
Up until now, I have tried a couple of things.
To download JavaFX SDK and to add jars in eclipse as a user-defined library.
To bundle JavaFX jars and to use them as regular OSGi bundles after that (added as dependency and after that in target-platform).
Both of these things work. But, in the first case, every developer would have to manually add those jars as a library on the classpath. And in the second for every platform, we would have to have a different bundle for each module.
If I do neither of those things I have compile errors that JavaFX classes cannot be found (as expected).
Is there some third way to do this? By using some OSGi functionality or something like that?
I haven't found any way to add a module in MANIFEST.MF. Is that even possible?
I have added JavaFX modules as VM arguments in the OSGi framework launcher, and everything works fine. But I have to do one of those things mentioned before so that I don't have compile errors.
VM arguments: --module-path /path/to/javafx/sdk/11/lib --add-modules javafx.controls,javafx.graphics,javafx.base
I tried to convert an E4/OSGI/GEF/JavaFx project that uses JRE 8 to JRE 11 and OpenJFX 11, and found a way to do so.
In my case, I use SWT and javafx.embed.swt.FxCanvas. Including the user defined JavaFX library in the modulepath didn't work, generating class not found errors during compile-time; but including the library in classpath worked.
I also couldn't run the application using --module-path arguments; it gave NoClassDefFoundError exception for org.eclipse.swt.widgets.Canvas
My solution uses E(fx)clipse, which could also be the third option for you. After including the javafx libraries in the classpath, and including org.eclipse.fx.osgi in the project configuration, I used the following VM parameters to load JavaFX classes using E(fx)clipse.
-Dosgi.framework.extensions=org.eclipse.fx.osgi -Defxclipse.java-modules.dir=[openjfx-lib-directory]
You can also add -Defxclipse.osgi.hook.debug=true" to see debug messages from E(fx)clipse while loading the classes.
I am a total beginner at maven, I have read about it online but I am still confused how it can be used. I have eclipse Oxygen version installed and when I open projects I can see maven project option is already there. I was even able to create a maven project using YouTube tutorial. But now then I saw popular plugin called m2eclipse but I am not able to comprehend why is it actually used; when my application ran without it.
I am learning maven to get started with spring boot but I am finding it really overwhelming where to begin with, and many of the tutorial sites state to download maven (But maven already comes along with eclipse?)
Please explain.
Apache Maven is a build tool - a tool for compiling the source code of a project into a program that you can run (for example a jar file, or a war file that can be deployed on a Java EE application server). Besides automating all the tasks for building a project, it also gives you a standard way to organize your project and to keep track of dependencies (libraries that your project needs).
Why do you need such a tool?
When you write a small program that consists of one, or maybe a few source files, it's easy enough to compile it by hand on the command line, by directly using the Java compiler javac that comes with the JDK.
But when your project becomes more complex, and you have hundreds or even thousands of source files in multiple modules, it becomes really hard to keep track of everything and cumbersome to compile the files using javac. If your program needs libraries, it becomes even more complex, because you have to make sure that all the libraries are on the classpath, and some libraries need other libraries, which also have to be on the classpath.
A tool such as Maven helps you to compile all the source files in the right order and to keep track of all the libraries. Maven can automatically download libraries from the web and add them to your project, and downloading everything and building the whole project can be done with one simple command such as mvn clean package.
Spring Boot is part of the Spring Framework, which is a huge framework with tons of useful functionality for developing projects in Java. A Spring Boot project typically needs dozens of libraries, and it would be very hard to use if you'd have to keep track of all those libraries by hand - so that's why it uses Maven to manage all of this for you.
A Maven project is configured using a file named pom.xml - in that file, you describe your project and you put a list of libraries that your project needs. When you build your project, Maven will read the pom.xml file and figure out automatically what source files need to be compiled, and what libraries need to be downloaded.
m2eclipse comes preinstalled in Eclipse (at least when selecting "Eclipse for Java developers" or "Eclipse for Java EE developer"), thats why you were able to use Maven by default.
Still you probably want a command line Maven, because that's most likely how it will eventually run on the CI server, sometimes Eclipse Maven installation can produce different result than the command line install.
I'd like to create my own gradle library, that can be compiled into other projects using gradle compile statement.
Example from Picasso's README:
Download the latest JAR or grab via Gradle:
compile 'com.squareup.picasso:picasso:2.5.2'
I'm developing few applications that share common source: fragments, views, some logic... Sometimes I extend these sources while I'm developing app A, sometimes while I'm developing app B,... And I feel that copy-paste of packages/classes in Android Library Module is not an proper solution.
So I would like to setup my own library, that:
it could be easily deployed to as gradle library that could be used by compile.
I can easily develop/extend it together with currently developed application
Disclaimer: I had been googling it a lot, but without luck.
If you want to reuse a library across completely separate projects then you'll want to publish your library to repository. Assuming this is open source and you don't mind sharing, you could use JCenter, which is already added as a repository to Android projects by default.
https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/
A little back ground: We are using Apache Felix implementation of OSGI for our web development (Adobe CQ5 which inturn is built on apache felix). We have a few bundles of our own (around 10) and each of them are configured as a project.
Issue: During the development lifecycle, we make changes to a bundle and then use an ant script to create the bundle and deploy it in the felix. I am wondering if there is some way to enable hot deployment of the changes I make during development mode that would save developers time.
Based on my research, we can use the felix file install which will monitor a folder(s) for changes to any bundles and can deploy them automatically. But this again means I need to run ant script to build the jar file and move it to the auto deploy folder the file install is watching. Is there a better/fast way to achieve this? The script is currently taking a around 10 seconds (approx) to compile the classes, create osgi specific meta data files, bundle the classes+metadata in a new jar. Is there some way to do hot deployment, so that any change I make to a java file is automatically reflected in the bundle?
Many thanks
If you develop your project in Bndtools, and run from the built-in launcher, then Bndtools will handle immediately building any Java code that you change, and deploying the updated bundle into the runtime. This leads to an extremely quick code/test/debug/fix cycle.
Having said that, I'm amazed that it takes 10 seconds to compile and build your bundles currently! Are you building on an extremely ancient computer? Or is the bundle multiple gigabytes in size?
We tried DCEVM and it does almost everything we expected to reduce the develop+fix+test life cycle. I recommend this to all java developers using big web applications. Thanks for your suggestion on bndtools Neil.