Class-path in manifest not read when running jar in Unix - unix

I have a client application that needs to run on Unix. It works fine in Windows but i get a NoClassDefFound exception in unix. Here's my manifest file:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 2.3 (IBM Corporation)
Main-Class: com.main.Client
Class-Path: lib/commons-lang-2.3.jar lib/commons-io-1.3.2.jar lib/comm
ons-logging-api-1.1.jar lib/log4j-1.2.12.jar
And the Client.jar structure:
com
com/main
lib
meta-inf
To run it, i use the command below:
$JAVA_HOME/jre/bin/java -jar Client.jar
It works fine in windows. Somehow i think that its not reading the manifest right. Help please! Thanks!

Maybe because your meta-inf folder is in lower-case?

One way is to make sure you have defined your CLASSPATH variable for the user that is running the program.
$ echo $CLASSPATH
if there is nothing shown from the above, then export it
$ export CLASSPATH="/lib/commons-lang-2.3.jar:/your/other/paths"

Related

How to compile java file from windchill shell

I am trying to compile a simple Hello World from windchill shell using command javac com.A.B.Test.
But it is displaying could not find main class error.
I think your problem is Java and not Windchill related.
Let's say your Java source file is stored in the following location:
/src/com/A/B/Test.java
To compile that file in shell (Linux for example):
cd /src
javac com/A/B/Test.java
To run that file (if it contains a main method):
java -cp /src com.A.B.Test
Try using the below command from the windchill Shell.
Hope you are following the default file structure provided by the Vendor i'm providing the same below otherwise just edit the path mentioned in the below command.
javac -d codebase -cp %CLASSPATH%;%WT_HOME%\srclib\tool\Annotations.jar src*.java
First Go to Windchill Shell then navigate to the folder where java file is present. At that location type javac Test.java and press enter.
Put the code into WT_HOME/src/com/package, than run from WT_HOME:
ant -f bin/tools.xml class -Dclass.includes=com/..path-to-package/*

Jar inclusion Issue

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

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