Where to save jar's for project? - java

I'm knew to the stackoverflow community so forgive me if I'm doing this wrong.
I have a java project that I'm building [using itellij], where I am using an API with a jar I downloaded. What is the best way to add the jar to the project so a user (or another programmer) can just open it and not have to download the jar? Or if I was to deploy the program, how would I include the jar so it could be run with the necessary jars?
Currently I have made a separate folder named jars and load it from there.

You can use maven for solve these problems.
See this tutorial, if you are interested in maven: http://www.mkyong.com/maven/how-to-create-a-java-project-with-maven/

Related

Creating a JAR using Ant but not including external jars inside

I've recently come with the need to create for a Java project a build.xml file in which is meant to be run using the terminal.
The issue is that until now we've used Eclipse as the utility to run the build.xml while depending on Eclipse UI to let the Ant package manager to create our jars, but not putting the external jars in each jar we create.
That way, the memory in which the jar libraries take(~40MB) isn't replicated to each Jar we make.
I'm pretty a beginner in Ant so what I'm trying to do is create a build.xml in which take a folder of Jar libraries, and for the project which is a Jar library itself, create the Jar while knowing the libraries but not include them in the end Jar.
I alternatively tried understanding how eclipse teels the build.xml for ant but the classpath of the project, how to access the jars and other configurations, so if there's a possibility for that then it will be much better.
If possible, it would be great to help with that.
I've tried of course seeing other questions on Stackoverflow but didn't saw something similar to this.
If there's one of course I'll be happy to see it :)
Thanks heads up! :)

How to export a java project from eclipse that contains all libraries required to compile?

For a project I completed a game in Java on Eclipse using LibGDX. I now need to turn in the source code to my professor. When I export the project and try opening it on a new computer, about a dozen libraries are missing.
I would like to export my entire project so that when the project is opened in eclipse, it will still compile. Is there any way to do this? I know that runnable jars come with the .jar files of the dependencies and no source code, but I need both.
Thanks in advance
Libgdx required number of dependent jars so it's hard to manually add all jars into project.
Make your project gradle based so that When you import your project through gradle into another System then gradle do most of your task* for you.
*gradle try to find dependent jars in file system if already exist then link with your project if not then it download from given repository and link them in your project. Make sure your system is connected with internet when you build your project.
I highly encourage to use Android Studio or IntelliJIDEA.
On window, by default all jars are stored inside
C:\Users\User_name\.gradle\caches\modules-2\files-2.1
In Mac OSX
/Users/User_name/.gradle/caches/modules-2/files-2.1
When you want to deploy or packaging for the desktop run this command on your IDE terminal.
gradlew desktop:dist
You can use maven or gradle to build your project, take a look of one of the tool and it's won't take you too much time. these tool could help you define your own way for build
A much easier way you could use "fat jar". this is an old tool for build a jar with all lib you need and could be run in any place.

why I can use the sources or jar downloaded in my project?

I am trying to use Maven and JDeveloper for a week now and I'm always get stuck with the same problem. I can download and install the extensions and create new Maven projects. When I package or compile them I can see that the sources are being downloaded and added to my local repository but they are not added in my .jar and I cannot use them in my project unless I add them as lib manually in my project.
If I try to add the folder (where the downloaded jars are) as lib folder to project they are only added as jar and I cannot use them.
Is there another way to update my dependencies from JDeveloper? How can I integrate them properly to my project so I can use them? Is there a newer Hands-On maybe solving my problems? What am I doing wrong? Is there a template project to download maybe? I hope I could explain my problem good enough...

Setting up Eclipse to always include hadoop jar files

I am trying to create an Eclipse folder(package?) team members can download and when they create new projects, it will automatically add the Hadoop jar files into the classpath, is this possible?
Thanks!
PS. I did ask in the Eclipse forums but there was no response.
You could create a dummy project with complete config and libs. A dev would only have to rename it..
Or if you want to go the maven road, use an archetype.
I have not heard about such a folder / package concept. Why not create a preconfigured empty project with all your dependencies ? You may also create a Maven project to easily manage dependencies.

Netbeans generating .jar file

When I clean and build, Netbeans generates a .jar file for my Java project, and it uses a "lib" folder which has all of my external Jar files that I use. Can I somehow tell Netbeans to package these Jar files into the .jar it makes? So that I can run my project as a stand-alone .jar file?
I am using Netbeans 7.1.1 on Mac OSX
The short answer is no, the long answer is complicated.
Firstly, Java does not support embedded Jars (ie, you cann't simply add the depended Jars into the main Jar).
Secondly, uncompressing all the Jars and merging them into one will overwrite any resources/classes that share the same path/name. This may not be an issue in small projects but is a major issue in large ones (we have this problem with the project I'm working on at work).
One solution is to use something like One-Jar, which basically uses it's own boot class loader to all you to reference Jars inbedded within a single Jar.
I've had issues with this when using our own custom classloader, but otherwise it seems to work well.
It includes Ant support, so you can include it in your projects Ant build script, if you not using Maven, otherwise, you'll need to devise your own build process
There is no options in netbeans to do that.
There are some other options that a quick search would help, but requires manual intervention.

Categories