I want to create a library in JAVA with all its dependencies contained in it so that the versions of the dependencies do not conflict with the versions that may be available in the environment in which the library will be used. I have explored the concept of a module in JAVA. I was also able to create a module using Maven in Eclipse. Now I am not sure how to create a JAR out of it. Or is there any alternative to a modular jar for such a library. ( P.S. I am very new to JAVA)
If I understand you correctly it is not a module you would like to do, but rather a distribution with all jar files included.
To fix this you could do a fat jar with Maven.
Related
I am upgrading a legacy application to java 11. Currently we don't use maven or gradle.
As i've updated it, i've replaced certain libraries that have been removed from the jdk in 11. Some of the newer dependencies i've added contain module-info.java files. When I go to create a custom jre for my application using jdeps (in preparation for jlink), i have the option of specifying a class path and a module path. My question is, can the paths be the same 'lib/*' directory? In my mind this would try to use the jars as both modular jars and regular jars. If i must separate them, maybe there is a tool to help me know which ones need to be put in a separate directory (identify jar's containing 'module-info.java') and give me a list of them.
In short, yes you do need to put modular jars in a separate directory than your non modular jar dependencies for jdeps.
Here is a great video on the module system:
https://www.youtube.com/watch?v=M7q3C8OwJe8
I have used SBT to build a pure-java project. This project consists of multiple modules, and projectB depends on projectA.
Now after switching to JDK 11, this dependency should be modeled not via classpath but via module path.
Is it possible to tell SBT that module depencencies must be resolved via module path instead of the classpath?
Basically I have set up a inter-(sbt-)module depencencs that says projB.dependsOn(projA) - so can I tell SBT somehow to put this depencency on the javac module-path instead of using the classpath? I see currently no way of doing that.
EDIT: Further analysis showed that I needed also to use normal library depencencies (from libraries on a nexus repository) as module depencencies. So the next question would be - how can I treat these library depencencies as module depencencies in SBT?
I do know that SBT is a scala build tool, and that it is something of a stretch to use it for a java-only project, but I use SBT for other (scala-)projects, and I do not want to introduce too many different build tools, until I really have to. So - is there a sbt-level solution for this?
EDIT: To clarify the issue - the project in question is a kind of open-source library which we modified. The SBT build file is from our organization, so I have to maintain it.
The project switched to using module-info classes, and it depends on other (binary-only) libraries via module path, if you include module-info.java in the compilation, that is.
So in our SBT build I have to use the module path for some of the external library depencencies.
Also the SBT-subprojects have dependencies on each other, i.e. we also have to use the module path for that.
Is there a way to tell SBT that:
This library must be on the module path, and not on the classpath
This project dependency must be on the module path, and not via classpath?
That is the core of the question. I may be able to write a plugin for the first problem (having not libraryDepencencies, but modularLibraryDepencencies for example) - but I do not yet know how I could handle the second part (tell a project that project depencencies must be on the module path and not on the class path).
I have a big gradle project with a lot of gradle modules.
I want to add java11 support with back compatibility (with java 8).
1) Do I have to use java9 modules system, or such migration is possible without it ?
2) If yes, can I auto-generate module-info files automatically, my project is huge.
If not defined otherwise all you classes will be packed into a unnamed module.
But you should be able to run your app without code modifications.
What is the difference between Jar and Plugin in Java? Both looks the same by achieving the same purpose and when do use Jar and when do we use Plugin.
A plugin is an extension to Maven, something used to produce your artifact. Plugins are used only to make maven process successful. They are not directly connected to your application. plugins do not include in your last war/jar file for the service or client.
A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time. the classes you used from jars will include in your final war/jar.
This will be helpful for you,
What is the difference in maven between dependency and plugin tags in pom xml?
Difference between plugin and external jar file
plug-in is a software component that adds a specific feature to any computer program.It specially use to customize any computer program.But .jar file is a java executable file which can only run on an environment which Java installed.
I have a Java project which is heavily used by all sorts of other Java and Android projects. The project contains some JAR libraries which shall be used by all projects, except for the Android one (in fact the Android project is a Android library project to be precise).
I marked the JARs as "export" in the Eclipse build path preferences of the Java project. However, the Android project shouldn't import these libraries (as they are Java libraries which make use of some classes which are not available on Android), but it shall import the rest of the code (which doesn't really use the libraries, but they are stored in there for convenience reasons and to ensure, that all other projects use the same library.
How can I prevent the JARs from being exported to the Android projects?
You can prevent all jars from being exported so that only the common project is a dependency for each project that needs it.
Then you can change the build path of each project to only include its necessary jars through the add jar.. dialog in build properties.
That's the easiest way.
A more extreme way would be to move to maven and then eclipse will only include the jars you specify in the pom - though that's a load of extra work for not much gain.
Alternatively, you could split the android specific code into a android-common separate project and then make your common project depend on it and export it - then your android project could rely on this android-common project instead of the existing common project.