Results 1 to 20 of 45
- 04-01-2008, 07:05 AM #1
Creating jarfile containing external jarfiles
Hi there,
I am trying to create a jar file that containing external jarfiles.I copied that external files into my location and create the manifest file Manifest.mf as below:
Main-Class: MainClass
Class-Path: jar1.jar jar2.jar ...
and create the jar file using the command :
jar cfm MyJar.jar Manifest.mf *
I can execute this MyJar.jar at the location where I create that jar file..when am trying to execute it in another location its showing an exception regarding the external jar file such as java.lang.NoClassDefFoundError
can anybody please help me........:(
- 04-01-2008, 08:06 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Before go further, move your newly create jar file into a different location. Then try to execute it, ok you say that you can't.
Then extract the jar file on to the same location and try to execute the same jar file. What happened?
I hope you use Netbeans for developing your java applications.
- 04-01-2008, 08:18 AM #3
Thanks for your reply
Yes. I moved that jar file in to another location and extract its content there. its executing.But I have a doubt ,is it the real way to execute a jar file?
I create that jar file using the command jar cfm.......
- 04-01-2008, 08:40 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No it's not the real way to execute a jar file. Seems that additional jar file make not refer the resources correctly.
Did you have any addition resources in you project. I mean did you use addition folder for images or any. Those make not linked correctly.
Even that addition jar files?
Originally Posted by gowry
- 04-01-2008, 08:57 AM #5
- 04-01-2008, 10:58 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I never done this on notepad. Most of the IDEs gives the final jar files binding with all required libraries.
- 04-01-2008, 11:37 AM #7
I tried to create jar file in Eclipse.but it gives the same exception as in the situation when am trying to excecute the created jar file in another location.
- 04-01-2008, 11:42 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I don't know to say about Eclipse. I used Netbeans. There is a folder named 'dist' is created and that is the distribution package. There is a single jar file is included if you don't have use any libraries. If you use, there is a folder created inside the dist folder named lib.
So all the time you have to use whole dist folder as your package. Rather using a single file. I've never try to make a single jar file, because in deploying I keep the same folder structure. :)
- 04-01-2008, 01:30 PM #9
Thank you for the time spent here..
But Still am in the middle of sea...
- 04-02-2008, 03:40 AM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-02-2008, 06:55 AM #11
Yes.. I tried on NetBeans..As you wrote there is a dist folder and all the libraries are within that in the lib folder.. Jar file is executing in that location..
But if i move that jar file into another location still there the same Exception..
- 04-02-2008, 06:56 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
And as you said, if the jar file is extracted it works, right?
- 04-02-2008, 07:03 AM #13
No. Its not working even after extracting the jar file.
- 04-02-2008, 07:16 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
So you said inside the dist folder it works, and out of it it's not? Try it clean and build, then move the dist folder somewhere and try.
Is that you application(code) is too large. If you are ok to send it here or PM to me, I can try. If you don't like to do it, I don't :mad::( I always ;)
- 04-02-2008, 07:42 AM #15
Yes .Inside the dist folder its working.
executing the moved jar file after clean and build reporting an exception :
Failed to load Main-Class manifest attribute from
JarFile.jar
- 04-02-2008, 07:45 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, after extracting the jar file you should have a folder name, META-INF, is that right. Check the file there, what is the content of it. Check there Main-class attribute, is that main class of your application?
- 04-02-2008, 08:00 AM #17
There is no Main-Class attribute in the manifest file under the META-INF folder. that containing only the version and other such informations.
- 04-02-2008, 08:05 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That should be the error in this case. Because Main-class define the main class, or the starting point of the jar file.
Here is an example of one of my project.
See the last line, X-COMMENT, says that Main-class should be added automatically in the build.Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 10.0-b19 (Sun Microsystems Inc.)
Main-Class: testproject.StartingPoint
Class-Path: lib/beansbinding-1.2.1.jar lib/AbsoluteLayout.jar
X-COMMENT: Main-Class will be added automatically by build
- 04-02-2008, 08:11 AM #19
Yes.In that case the abscense of main class in the manifest is the error.ok.. but with the previous manifest file before the clean and build and the manifest file I created myself ,having those attributes Class-Path and Main-Class. i think its a Class-Path issue of the external libraries that am using.. But I dont know how to solve it.
- 04-02-2008, 08:18 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You can see in my Class-Path which included libraries. Like that check your libraries and added, which included in lib folder. Is there a lib folder?
Similar Threads
-
javac not recognized as an internal or external command
By kotoko in forum New To JavaReplies: 28Last Post: 10-26-2010, 04:39 AM -
External JavaScript files not loading
By sajut in forum New To JavaReplies: 0Last Post: 02-15-2008, 05:47 AM -
Using Runtime to execute external commands
By Java Tip in forum Java TipReplies: 0Last Post: 02-05-2008, 09:14 AM -
External Program execution problems
By vital101 in forum Advanced JavaReplies: 3Last Post: 10-30-2007, 05:17 PM -
Use a external file in my program
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks