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
Related
I want to create independent jar files in netbeans like we can do in eclipse. Normally people suggest to clean and built the project and there is a jar file created. But to run these jar file the .java files, the codes are also required. Isn't there any way to create jar files which runs independently without requiring java codes?
Thanks
set the main class in run configuration
do a clean build
go to the dist folder and you can find the jar there as a runnable one
for further information refer this Creating_an_Executable_Java_File_in_NetBeans
In eclipse tree or any eclipse based application.
I can see that inside the plugins folder.
most of plugins are in the jar format while some of them are in folders
and this folder is just the jar extract .
why someone could do this ? what is the benefit of putting a plugin as extracted jar rather than only jar file ?
You can do this to embed jars in the plugin that are used in classpath because yo can have issues with nested jars in classpath.
I think that you can also access resources differently. And it can be an easy (and dirty?) way to allow some customizations by overriding some resources such as images.
Let's say a plugin will need to execute an embedded OS dependent script on its start-up (ex. ".bat" script). If this plugin is installed as a jar, it will need to :
get an InsputStream of the embedded script
ensure it can write it somewhere (temp folder usually)
run the script
at the next start-up; check that the script has not already been extracted
...
Or, if this plugin is extracted as folder :
run the script.
I am trying to use the Eclipse export function to create a jar file to be deployed in an Axis2 deployment in Tomcat. When I have source code projects, I can export this jar, rename it to aar, and it works fine. All the classes from all the projects are present inside that exported jar.
Now I convert a few of those projects to jar files (they form a library). The primary project now points to these library jars as external jars in the build path. It builds fine. Now I want to export the same type of jar file from this primary project that no longer has access to the projects containing the library source code.
SOO...I followed these instructions to create my own Manifest.txt file that would point to these external jars using the Class-Path directive. The line appears as follows:
Class-Path: file1.jar ../../libraryJars/file2.jar
So I follow the usual export to jar (not runnable of course; there is NO main here!) with the option to use my Manifest file and the Class-Path directive in that manifest is ignored. I look inside the created jar and the only classes I find are from the primary project. All those classes in the external jars were NOT loaded.
How do I get the classes inside the external jars to be exported with the classes in the primary project when creating this jar? I understood that using the Manifest.txt approach was the way to do this. Perhaps it only works when making a runnable jar (which I cannot do)?
I do NOT want to use something as messy as ANT. If I have to resort to script files to accomplish this task I will just do the copies with a bat file.
I have a java application I've written in eclipse. It works fine there.
It works fine run from a command line in the directory where I export it to. In that directory is another directory containing two jar files that I need for the application, and the manifest file has a Class-path option specifying them.
I want a way to use eclipse to generate the necessary file(s) to package this application to run on another machine. Is that possible?
If I choose "create executable jar file", it creates this huge file; it does unpack and repack the two libraries, which I know is one way to get their functionality included. I would actually prefer it if they were left as their own jars somehow, but I am not certain eclipse can do that. More annoying is the fact that the executable jar file option puts lots of files from my eclipse project into that jar file. I don't see an option to choose what gets included there, though I do see a place to enter inclusion and exclusion "rules' in the project properties. Do those apply here? Is there somewhere else I go to select what does and does not get included in the "executable jar"?
If I choose "create jar" (ins of "create executable jar"), I don't see where there's an option to include these two jar files anywhere. Perhaps there is no place to include them where they could be used.
If possible, I do not want to use Ant, I do not want to use Maven, I do not want to download another tool. It seems to me that Eclipse already has all this information and I suspect it can already do this without having to go and learn yet another "nifty" tool.
Eclipse has its own Jar export wizard for generate a runnable jar packed with required library or with the required library in a folder aside the jar.
Going in File ---> Export then choose Java - Runnable Jar
You can then choose how pack the jar and how handling libraries :
You can also save the ant script for later modification or use ...
You actually should use Ant or Maven for your task, I see no other option. Ant is already packed with eclipse, you only need to install a JDK, not only a JRE.
Ant is very easy to learn and you can find billions of examples in the internet. With ant you can do exactly what you want.
Maven is the more up-to-date way to build and package jars and do much more other stuff. Maven also is a good choice for you.
I'll second a vote for Maven. Eclipse has a decent maven integration (m2eclipse). Then check out this answer for building the jar effectively using Maven2
Building a runnable jar with Maven 2
Well I have 2 .jar files. The main jar file is the jar file for my whole project and the other .jar file being the MySql JDBC Connector.
Well basically whats happening right now is that when I build the project I have the one main .jar file with everything but the MySql JDBC Connector .jar file is inside the main jar file when it builds in NetBeans.
Now when I am just running the project from within NetBeans the MySql JDBC driver can be found inside the src/com/game/mysql folder that I have it in. But when I build the project the Java application cannot locate the JDBC driver from within the main jar file.
When I open the main jar file with WinRar I can see that the JDBC jar file is still in its /com/game/mysql/ folder. But why cant the Java application access it?
I have heard that nested .jar files are not supported in Java so Im thinking this might be the reason although Im not sure if thats true. Is there a way that I can make it so that the application can find the JDBC .jar file within the main jar file?
Also I have done the thing in NetBeans where you add the .jar file through right clicking project -> properties -> Library -> Add Folder/Jar. Thats what makes it work in the NetBeans run but still not the App build.
I have heard that nested .jar files are not supported in Java
More precise, classes in a JAR file which is packaged as a child JAR inside a main JAR are indeed by default invisible to classes in the main JAR.
You have basically 2 options:
Ship your application with 2 loose JARs: your.jar and mysql.jar and define the relative path to the mysql.jar in the Class-Path entry of the MANIFEST.MF file of your.jar.
Class-Path: mysql.jar
When you put both JARs in the same folder and execute your.jar by java -jar your.jar, then it will work.
Let your IDE repackage all loose classes of mysql.jar inside your.jar or add a special classloader which preloads the classes of any embedded JARs. Since I don't do Netbeans, I can't tell whether it supports it and if so, how to do it. In Eclipse, however, this is definitely possible. See also this answer.