In my application I have 3 public classes (with a lot of external dependencies)
that I want to convert to a Java library ( Jar ).
Problem is when I try to construct the Jar using the standard system they ask me for a main class, which my source does not have.
Am I doing something wrong here?
Can someone please guide me on how to build a library using IntelliJ IDEA without a main class and with external dependencies
I use maven in IntelliJ, but you could use ant or gradle. In all these cases, it is the default behaviour to not include a main.
BTW, having a main for a library is not a bad thing, you can use it to print out information about the library such as when it was built or where the developer using the library can get more information.
Related
I need to add an external library named ControlFX in my project. Here is the official link to download it: https://github.com/controlsfx/controlsfx
The issue is that this file is .zip type. So, I'm really confused about how can I add it as a library to my project (it doesn't include.jar files inside).
Any idea, please?
Check out How to add external library properly in Eclipse? if you want to add it manually, but it's very much not advised if you don't know what you're doing.
If you want to learn the proper way to use external resources look into how to use Maven or Gradle to incorporate libraries into your projects.
My application makes use of a third party jar that I want to improve and that has bugs in it. I can see from using a decompiler where the bugs are and can easily fix them. I am unable to extend the class and overwrite the problem methods as they are private and final, and make use of private and final fields.
At the moment, I solve this using a decompiler (which isn't perfect) to re-create the class in a project with the same class name, package etc. My gradle build script then extracts the contents of the original jar to $buildir/main/java so that when gradle compiles my version of the class, it overwrites the broken one, resulting in a new jar that is bug free.
I think this method is dirty and unmaintainable as if a new version comes out, merging changes could be difficult. Also, Eclipse and IntelliJ won't build the project when both projects are in my workspace with a compile project dependency, even though it builds on the command line, as the IDE is unable to see the source for all the extracted jar, but only the class I redefine to fix.
What is the best way to cleanly solve this problem?
I need to use deeplearning4j library in a new java project.
I downloaded .jar (in particoular deeplearning4j-core and ndj4-api-platform) from maven library.
I imported that in eclipse
I receive an error because org.ndj4.api.complex.IComplexNumber is not found.
Where may I find a .jar with that classes?
Please import our examples and use maven (or some build system):
https://github.com/deeplearning4j/dl4j-examples/
I say this due to the sheer number of jars you need for running dl4j.
I would consider using maven rather than avoiding it.
https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
We say all of this right in the deeplearning4j quickstart:
http://deeplearning4j.org/quickstart
I would suggest reading the docs for the project rather than trying to figure it out yourself. You are only wasting time by doing that.
So I took a Coursera course that had me work with external libraries. Two .jar files which most of the weekly projects depended upon.
I'm not entirely sure how eclipse compiles and runs the files, and how it links to these external libraries -- what is the proper way of organizing this? Do I put a copy of each .jar file in each project directory?
Is there another, cleaner way that I should be organizing this?
Thanks --
As a beginner programmer it is OK to put it in each project. But consider that this is ongoing work and at some time in future you want to upgrade to a new version of these external libraries. Then you would have to copy it everywhere.
Instead another option is to store them in one place and add it in classpath in each project. Now you have only one copy of it, which is always better.
Now, if and when you do get a new version then the file names might change, so you will still have to change the classpath of each project.
But I advise you to worry about these and other such problems later. For now, focus on programming related problems rather than configuration.
If you want to maintain your libraries professionally in a formal manor then you're better of using a build tool like Gradle of Maven.
I'd suggest you to use Gradle to maintain the project since it has a whole lot of useful build tools available to you to use. Eclipse has a Gradle plugin available which allows you to use Gradle projects with it. See link below.
To give you a idea of how Gradle is used professionally. Android uses it by default to maintain their projects now. So Android java projects uses the Gradle build tool to maintain its library sources, compilation processes and such.
The difference between a Gradle project and a normal java project is that a Gradle project has a list of pre-defined scripts available to you which fetches the libraries, compiles them and prepares them before exporting the final bundle (jar). So really all Gradle does in before hand is fetch the libraries and prepares the specified tools before compilation so you won't need to mess with them your self. It prepares your project directory and remotely maintains your libraries so if they're available from a repository then it'll make sure to prepare them appropriately in before hand and setup your projects directories.
So really the difference you'd physically notice is that instead of using the default Eclipse export button to create your bundle (jar) you'd instead use a button from the side menu which the Gradle plugin adds and also you'd cleanly list the libraries in a structured order in a file that gets added to your project root.
If you want to get a basic understanding of how it works and really want to start to proffesionally or formally structure your project then try to create a very basic android app in Android Studio. see link below
If this isn't what you want at all and don't want to take it to this advanced level yet then adding the library bundles into some kind of lib folder that's located in your project root is properly best practice.
If you wonder why? Well basically different projects might use different versions of the library which may add or remove support to them. So to keep the versions consistent and make sure to have the right version available to you, you have the direct source near the project it self.
Here's some useful link:
http://www.vogella.com/tutorials/EclipseGradle/article.html
http://developer.android.com/sdk/index.html
I am migrating to IDEA from Eclipse and have a few Eclipse UserLibraries that I want to easily reference.
I tried adding Libraries bt Attaching Classes and Jar Directories, but it seems IDEA doesn't pick up the class files? Even after I re-compile etc.
Am I doing something wrong?
What is the best and correct way of going about this?
Libraries that you configure in this dialog should be then added to the module dependencies.