Create on single .JAR with no lib folder [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
NetBeans - deploying all in one jar
I am using netbeans to develop a project. My project also depends on the javaMail files which I added using Netbeans libraries. When I build the project I get a dist folder under which is my jar file and a lib folder. I want to distribute the project simply to my users and want to some how wrap the lib contents into the project jar file. Is there a simple way to accomplish this using Netbeans?

There are a few posts on this topic:
Put external libraries to the jar (NetBeans specific)
Netbeans - deploying all in one jar (NetBeans specific)
Classpath including JAR within a JAR
Java: Easiest way to merge a release into one jar file
And others specific to other build environments and IDEs

Related

Adding multiple Jar files to Inelij idea

I'am working on a project which requires adding multiple jar files to intelij idea as a plugin but only one jar files gets added as a plugin to the IDE.

How to export projects in eclipse [duplicate]

This question already has answers here:
Export maven project from eclipse
(2 answers)
Closed 3 years ago.
I have an eclipse workspace with 2 non-web based projects, with over a dozen jars as maven dependencies. How do I transfer this to run on another computer that does not have eclipse? Do I export as a war, jar, or wnat?
As far as I understand your question about copying the projects to another computer, I provide below the followings.
Build the maven project, if it is a web application, copy the .war file which contains all the dependent libraries inside web-inf/lib.
Build the maven project, if it is a non-web application, copy the jar file only. To copy all the dependent jar files, you need to identify. Follow the step 3..
To copy or identify the all the dependent jar files for a project, there is no need to go to .m2 directory and search. Go the project directory and run the maven command mvn dependency:copy-dependencies. You will find all the dependent jar files inside the target folder. If you want, you can copy all the jar files.
If the project is a maven based project, you can directly copy the entire project to another computer and if maven setup is there in that computer, you can still build the project there. You do not need eclipse in that computer.
I would suggest if a project has maven wrapper, while copying the entire project, there is no need to install maven. In that case, go to command prompt for that project and type mvnw clean install or mvnw clean package.
If you want to copy or export the project using eclipse, you can do it like this. Make right click on the project, select export and then select General > Archive File.

How to make xxx-source.jar available for project [duplicate]

This question already has answers here:
Can Maven collect all the dependent JARs for a project to help with application deployment?
(6 answers)
Closed 7 years ago.
I have a cloud application which uses git and maven, so the source code is uploaded by Eclipse using GIT, and the required libraries are downloaded to the server by maven. But I have one library not in maven, it's downloaded as a source and also run time jar, xxx.jar and xxx-source.jar. When I upload the source, the reference libraries are not uploaded to the server, so the compile will fail on the server.
I could unzip it and package in the source folder and upload altogether. However, is there a simpler way just to put the source.jar as part of the project so Eclipse can upload that jar file as part of the project to the GIT server? and then the server will use that jar for compile?
is it a third party? if so, why you need the sources? you can simply upload it manually to your repository and set it as a dependency in your pom.xml.
if you still need the source for reference, you can upload it with a classifier, like you have (source).

Java Configuring Build Paths or WEB-INF/lib folder [duplicate]

This question already has answers here:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
(5 answers)
Closed 7 years ago.
I've seen a lot of tutorials and applications that put their jars inside a build path while others put it inside their web-inf/lib folder, Are there any significant difference? What are the pros and cons of both? What is an indicator for me to put a certain jar inside the libs folder and put the jar in the build path?
An application with WEB-INF folder is a web application. Meaning it will be packed as a WAR file and deployed on a server.
If you are using an IDE like eclipse, and you export the project as a WAR file, it will automatically take jars under the lib folder and pack them with the WAR and that will make them available for the application running on the server (jars under WEB-INF/lib are included in the application classpath).
If you just put them anywhere else and include them in the build path, when you export the project you have to declare that you want the jars in the build path to be included as well.
Basically, there is no big difference but if you know you need this jar in runtime (i.e. after deploying the application to the server), it is better to put it under the WEB-INF/lib folder.
What do you mean by build path? Most of the JARs you use need to be available during building (compiling) because your code depends on them - otherwise it won't compile.
The real question is between placing JARs in WEB-INF/lib vs. your container /lib directory. In general you should always put your JARs inside an application in WEB-INF/lib. Placing them globally has several consequences:
singletons are now global to all web applications (one class loader) if multiple deployed
it's easier to introduce memory leak if a library holds a reference to any of your classes (see above)
you don't duplicate the same classes (each web application will reuse the same class as opposed to having a separate copy in each class loader

creating jar file for java application

i have created a java application which uses data from its config folder and , it also uses third party jar files those are located in lib folder, could anyone tell me how to create jar file for this project with the content stored in config file and lib folder.
i tried creating jar using eclipse export functionality. when i run this jar file, it says it can not find the third party libraries that i have used for this project and configuration file.
thanks in advance for any help
You can create a Runnable JAR in Eclipse 3.4+ in the Export wizard selection dialog (right click on a project and go to Export...) using an existing launch configuration which will incorporate the libraries or repack them. Config files should be readable from the same directory as the runnable jar is located. If you need any help with loading these in, just ask :)
(source: eclipse.org)
You have two options
include the stuff in the third-party jars in your jar
provide access to the jars on the classpath when you run your jar.
Both have their benefits and their drawbacks.
Java does not support putting JAR files inside executable JAR files, so you can't just put your third-party library JAR files inside your own JAR - Java won't be able to find them.
If you don't want to distribute your application as a whole bunch of JAR files, you can use a look such as One-JAR which will build a JAR file for you that contains your own classes plus the classes of the third-party libraries that you're using.
To learn more about how to package a program in an executable JAR file, see Packaging Programs in JAR Files in Sun's Java Tutorials.
If you use netbeans just by click on "build" a jar file will show up in the "dist" file in your project directory

Categories

Resources