Jar inclusion Issue - jar

How can i add external jars to my project before exporting the project so that the person about to use my code need not have to download those jars.He simply has to refer the jar i provided to run my project(Not using Maven).
Thanks

You might want to create a zip file containing
your_jar.jar
the libraries needed in a subdirectory lib
and add a manifest-classpath entry to point to those libraries
Manifest-Version: 1.0
Created-By: Hand
Main-Class: com.bitplan.gen.parser.m2java
Class-Path: lib/com.bitplan.smartgenerator-4.2.3.jar
After unzipping your code can be started with java -jar your_jar.jar

Related

How to convert jar file to eclipse project

I want to convert my jar file to eclipse project, so that i can make changes in the existing code. Can anyone help me with this. I tried extracting jar using jar xf myjar.jar command through command prompt but it gave me only .class files and i want to generate .java files of my project through it.

Using the jar created with lein in other Clojure project [duplicate]

When using lein 2.2, trying to put jar files in /lib does not work.
I tried and it doesn't seems to work but plenty of docs out there says this way still works.
The lib directory functionality was removed in Leiningen v2.0, in favor of a repository (repeatability).
To add free floating jars to a project, you will need to either deploy your dependency to Clojars or a Maven repository. The Maven repository can be as simple as a directory in your project folder.
Please see the answer to this question if you need the jar in a project local folder:
How do I use checked-in jars with leiningen
You do not need to use maven to access a local jar file in Leiningen v2.0
Just use syntax like this in your project.clj:
:resource-paths [ "local-jars/*" ]
and then place your *.jar files in the local-jars subdirectory of your project.
Please see this blog: http://www.troyastorino.com/tidbits/lein2-local-jars

error trying to run jar file

i have tried to get help me nobody seems to understand my problem. I created a project in netbeans and it produces a jar file when i compiled it. It runs just fine on through the IDE but when i try to launch it from the command prompt it simply does not do anything. It just moves the cursor to the next line for another command? when i echo my classpath this is the result i get
/opt/netbeans-7.1.2/ide/modules/ext/mysql-connector-java-5.1.13-bin.jar:/h/USERS/local/pagola/NetBeansProjects/mylib/dist/mylib.jar:/h/USERS/local/pagola/NetBeansProjects/EOPPrototype/build/classes
i have added the classpath which contains everything that is within the jar. My manifest file contains the main class(entry point) and this is what it looks like
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.13-bin.jar lib/mylib.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: eopprototype.EOPPrototype
and so i cant figure out what i am doing wrong? do i need to add anything to my PATH variable (maybe the java jdk bin stuff) is it not able to locate the java command because it doe not know where to look for that executable?
NOTE: i did not setenv my PATH and LIBRARY PATH -do i need to do this ? this is a c style shell script
Try this first
If your Manifest does not end with a newline it maybe ignored. See manifest requires a newline
Otherwise I have to make assumptions
You don't need lib/mylib.jar in your manifest if that JAR file contains EOPPrototype with a public static void main(String[] args) method that you wish to execute. So remove it so it only lists mysql-connector-java-5.1.13-bin.jar. Your manifest will then look like this
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Class-Path: lib/mysql-connector-java-5.1.13-bin.jar
X-COMMENT: Main-Class will be added automatically by build
Main-Class: eopprototype.EOPPrototype
Then assuming all your code is in mylib.jar and the only other dependant jar is mysql-connector-java-5.1.13-bin.jar, create a directory structure like this
/h/USERS/temp/mylib.jar
/h/USERS/temp/lib/mysql-connector-java-5.1.13-bin.jar
Then execute like this
cd /h/USERS/temp
java -cp .:mylib.jar eopprototype.EOPPrototype

Creating a JAR file which contains other library files

I want to create one executable JAR file which contains other JAR libraries. But when I execute the JAR, it gives an error of class path problem.
How do I solve the class-path problem?
I think you can try it like this;
Here is a simple example for you question. First, we assume we have a project directory like D:\javademo. In this working directory we then create a main class HelloWorld.java and thtat contains our other JAR files, like commons-lang.jar. Now, we must archive our main classes HelloWorld and commons-lang.jar into test.jar file.
First we must edit our manifest file so that we can specify our class-path and main-class
like this:
Manifest-Version: 1.0
Created-By: tony example
Class-Path: test.jar commons-lang.jar
Main-Class: org.tony.java.HelloWorld
We named this file test.mf. Now we use the jar command to generate our JAR file like this:
jar -cvfm test.jar test.mf -C ./ .
Then it will generate the JAR file test.jar. You can use this command to run this main class using java command:
java -jar test.jar
That is my solution. I hope it give you something helpful...
You should use third-party libraries for it. For example, OneJar. You'll have to build the final JAR file using the OneJar tool (like Ant task) instead of standard JRE's tools.
On running such a JAR file, OneJar's service class is launched instead of yours. This class then loads JAR files packed inside, as well as your classes, and run your main class.
There are similar questions and answers already. For example: Stack Overflow question Easiest way to merge a release into one JAR file.

warbler doesn't packages a standalone application in a jar file but instead in a war file

I've a JRuby-based standalone application with the following structure:
my_app
- bin
- my_app # that's a launcher script
- lib
- my_app.rb
And when I warble in the top level directory, it doesn't generates a jar file as expected but instead a generates a war file. And this war, as expected, follows the war file's standard structure.
I've followed the documentation to do it:
https://github.com/nicksieger/warbler
"If your project do not have a .gemspec, Warbler will attempt
to guess the launcher from the contents of the bin directory
and use the lib directory as the lone require path. All files
in the project will be included in the archive."
Anyone already did it?
Thanks a lot!
This functionality is in version 1.3.0 which unfortunately hasn't been released yet. Try the prerelease version on rubygems.org (gem install warbler --pre).

Resources