I want to make my project into a jar executable.
That much I can do but I need my external library as well.
How do you specify the location of an external library? Right now I have added it to my eclipse project,but later on I need it to execute my program outside of eclipse on a server.
The Library is the postgres-jdbc driver to connect to database.
Do you mean Fat Jar or Runnable Jar i.e a single jar which will contain all it's dependent jars in it.
If yes, it can be generated in eclipse using File -> Export -> Java -> Runnable Jar
Optionally you can specify the start-class having the main method.
If you don't want as a Runnable jar, you've to add all your dependent jars in classpath before starting your application.
java -cp <add all lib> -jar <jar-file-name>.jar
Related
I am writing an app in businessobjects sdk and I need to develop it with like 8 million businessobjects jars brought into the build path.
I need one jar - opencsv - that will not be in the businessobjects platform build path when I run the app, so I think I should package this jar with my runnable jar for sure. The other businessobjects jars I do not need to package with my jar, BOE is already configured with them in the build path when I run the app from BOE .
However, do I need to package ALL the jars? I only want one third party jar to go with my runnable jar.
Is there a way I can pick and choose which jars I pacakge with my runnable jar?
If you don't need a runnable JAR (ie, a "plain old" JAR), you can use Eclipse's export JAR wizard which allows you to specify exactly what files are included. You could easily include just the one library that you want that way, instead of relying on Eclipse to include every library (which is the normal expected behavior for a standalone runnable JAR).
I made a simple standard-lone java Application using Spring,Apache Camel,Activemq for processing messages.
Note: My Application don't have any GUI.
My project structure is in the following way.
SACLib folder have nearly 70 external jars(all Spring,Camel and Activemq corresponding jars).
It's working fine in Eclipse. SO Now We want to deploy into Jar file.I tried in Eclipse,But I didn't seen Rod1,Rod2,Copy1 and SACLib folders in my Jarfile.
after Deploying Jar, If I run FirstConsumer.java it runs Rod1-->ThMapInfratab1-2.exe file. For this I mention Real paths of .exe file.
How can I make Jar file with including all my folders.
Thanks
Well, this is a kind of work that is typically done with build automation tools like Apache Ant, Maven or Gradle, so you can investigate there if you want to make this happen automatically next time.
But, if you want to do it manually...
First, you project needs a META-INF folder where you will place a file called a MANIFEST.
That manifest contains a Main-Class entry pointing to you main class. You can read about this in the Java Tutorial: Setting Application's Entry Point.
But it can also contain a Class-Path entry, pointing to all other jars required by your application and that should be loaded by the executable jar.
You can read about it the Java Tutorial: Adding Classes to your Jar Class Path.
If you are building your executable jar with Eclipse, it will let you choose the MANIFEST file that you want to use during the creation process.
Now, if you want to use build automation tools, there are other answers here that explain how to do it:
Creating a bundle jar with ant
How to create executable jar with dependencies with Maven
How to export an executable jar in Gradle
simply using ant download it , and then make a build.xml file and put it
Here's an simple example of an ant target that will create a jar (named test.jar) that includes all jar files under the lib directory. Maybe this will solve your problem?
for using apache ant, see this
http://ant.apache.org/manual/using.html
I have made a utility java project which contains XML, DB and other such utility classes. This requires 3rd party dependencies on some of the Apache common libraries, so I have added it in my java project by configuring the build path in eclipse Juno. Now I want to export this java project as jar file. When I am exporting this project as runnable jar file, it is working fine i.e if I include this jar in some other java project, I am able to access the utility classes, but when I am simply exporting the utility project as jar, I am not able to use it. Runnable jar requires a main class, but I don't want to keep a main class in my utility java project. I have compared both the jar files. The difference that I found out was that in runnable jar file, there is no .classpath file but a simple jar file that is in there. In the runnable jar file, all the jar files are mentioned in file named MANIFEST-INF.mf file, but in simple jar file it contains only version of .mf file. Can anyone tell me how can I make a jar file without a main class and use it for my other java projects so that I just have to include the jar file and use it as it is.
I assume it has not been provided in eclipse because extracting external 3rd party library classes in a utility project is something non-standard. It can result in a lot of problems as your project grows, class conflicts being one of them.
Still if you want to continue with your approach, yon can export your project as a normal jar project. Thereafter after open your project as well as the other third party libs in a utility like 7zip and drag-and-drop your third party library contents(except META-INF) into your project jar. That's all.
If you however want to automate it, ant would be your friend.
If you just export the project to jar file, you can package the jar(war) by using the apache ant tool.
Do something like this:
<jar destfile="${dist}/lib/app.jar"
basedir="${build}/classes"
excludes="**/Test.class"
/>`
I am creating an executable jar file for my program in java.
The program uses jtds.1.2.jar and javacsv-2.0.jar.
Is it possible to include the external jars when I create my executable jar file??
Please help.
Thank you.
Try this, this is the way to create a jar or runnable jar in eclipse, all your external libraries in the project will be included
File -> Export-> Java ->Runnbale JAR file
Launch configuration : your Class containing the public static void main(String[] args)
Export destination : Target place
Library Handling:
Package required libraries into generated JAR
FINISH
Yes it is possible.
You may use eclipse export jar function doing this
Sure it's possible! Just add the classes of the Jars to your Jar!
You can either do this by hand (unsuggested), or any build tools like Ant ( target) and Maven (search for shading plugin) can do that for you.
If you don't want to bother creating any scripts, just use the IDE to do it for you (newer Eclipse versions have a checkbox for including libraries automatically, for older ones just install a plugin that does the job for you automatically, like the FatJar plugin).
It's possible to create a folder structure like this
main directory:
your_app.jar
subdirectory:
other jar files
Then add the dependencies to your jarfile's manifest and "zip" the whole thing together, to move it to the computer where you want it to be. Netbeans, for example, supports this kind of deployment.
For a more general / "foolproof" solution, you will have to create a setup program.
I have developed an application using Eclipse IDE. After creating the application I exported the project in jar format. When I am trying to run this jar file, I get the error: Unable to load main class. Please Help.
When you are exporting your project as a jar (see this SO question), you must specify your main class in the export Jar wizard.
This should work always:
java -cp MyJar.jar pkg.name.MyClass
I'd prefer this anyway because it causes less classpath trouble compared to the java -jar way of starting a java application.
You need to create a runnable jar file. From Eclipse 3.4 you can do that by choosing Export, Java, Runnable Jar File. If you also want to include dependencies have a look at the Fat Jar plug-in.