Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default How to work out jar files solely ?

    I am still confused about some features of executable jar and usage of it.

    - When I make jar file, it includes all my classes, other 3rd-part jar files and other files (images, xml etc.) in it but it still does not working solely. I had to put in under a director which includes classes and other files. (but dont need to include 3rd-part jar files).

    I am missing some point, an executable jar file must have work solely, right ?
    Anyone can help me ?

    By the way, I am using Eclipse, and export to executable jar from Eclipse.

    Best Regards,

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I am not extremely familiar with all the details of jar files, however; I do know that you need to create a manifest file which contains what class contains the main method. Did you do this?

  3. #3
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Of course I have show class file with main method, but I did not mention a manifest file.

    Actually without manifest file you can also declare main file, it is mandatory, wihthin Eclipse.

    I have produced succesful jar file, and it works, this is not the problem.

    The problem is oit only works under project directy where it sees all other files.

    If I remove any of files (lets say a class or wrl file) it does not work.

    But When I look inside jar files , I see that it includes all files, classes, jar files etc.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    Of course I have show class file with main method, but I did not mention a manifest file.

    Actually without manifest file you can also declare main file, it is mandatory, wihthin Eclipse.

    I have produced succesful jar file, and it works, this is not the problem.

    The problem is oit only works under project directy where it sees all other files.

    If I remove any of files (lets say a class or wrl file) it does not work.

    But When I look inside jar files , I see that it includes all files, classes, jar files etc.
    Running a .jar file with a mouse click takes several steps:

    First the OS needs to have an association between the file extension .jar and an executable, notably java.exe or javaw.exe; I presume you have that step right.

    Next the java(w).exe has to know which of the classes in that .jar file contains the main( ... ) method; that is described in the manifest entry of the .jar file as:

    Java Code:
    Main-Class: YourMainClass
    Your application may use other .jar files; those files can not be stored in the first main .jar file but have to be mentioned in the manifest entry, like this:

    Java Code:
    Class-Path: second.jar third.jar ...
    Note the spaces between those .jar names, no semicolons or colons or whatever. You can put path names in there too, e.g. foo/second.jar where the path is considered a relative path, relative to your main .jar file.

    You don't have those entries so you java(w).exe checks the file system according to the class path where it incidentally finds the needed resources.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Hi Josah, Thank you for your reply.
    I did not make a manifets files but this is not problem I think,
    Let me clarify my problem.

    I ahev a jar files, but id not work by itself.

    Introduction page class (where I showed as class with main method)
    From this introduction page, users starts some programs by clicking buttons to invoke classes
    (and these classe has main methods can work solely, but these classes not working by invoking main ! , just invoke class)

    Problem: introduction page works, but when I click button to start 3D program, not working (of some files missing in the directory)

    By the way, another question, Jar files means I can include everything , right ?

    Even I make a basic program, that uses an image (just a 2D swing program)
    Not showing image file if it not there.

    Is it possible to include and work everything in a project just by a jar file ?

    And my final aim is to make it an exe file (or installer) but that will be another post.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    Hi Josah, Thank you for your reply.
    I did not make a manifets files but this is not problem I think,
    Let me clarify my problem.

    I ahev a jar files, but id not work by itself.

    Introduction page class (where I showed as class with main method)
    From this introduction page, users starts some programs by clicking buttons to invoke classes
    (and these classe has main methods can work solely, but these classes not working by invoking main ! , just invoke class)

    Problem: introduction page works, but when I click button to start 3D program, not working (of some files missing in the directory)

    By the way, another question, Jar files means I can include everything , right ?

    Even I make a basic program, that uses an image (just a 2D swing program)
    Not showing image file if it not there.

    Is it possible to include and work everything in a project just by a jar file ?

    And my final aim is to make it an exe file (or installer) but that will be another post.
    Your questions are not clear to me and yes, you need a manifest entry to show java(w).exe what the main class is. You cannot store other .jar files in your .jar file (aamof you can do that but it is no use). Read the Class.getResource() API documentation for an explanation how to find resources (like images) in your .jar file.

    Also there is completely no need to try to craft a .exe out of it all.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Hi Josah,
    Thank you, your information is really helpful to me. You wrote" Your questions are not clear to me and yes" I will try to write in a more clear way.

    First of all, it is not me but the Eclipse put those 3dparty jar files and everything else into generated jar file.

    So , at this point, I want to ask,

    -How can I deploy a Java Swing Desktop application that uses 3party jars and other files into a one file application ?? Is that possible ?

    Another point,
    You wrote "You cannot store other .jar files in your .jar file (aamof you can do that but it is no use). "
    But it works, like this;
    My generated jar works without those 3dparty jar files in the directory.. ??,
    (only need classes and other files which also shouldnt need, what I ask.)


    And another question, on another computers (that has JRE and j3D installed)

    my jar does not work even with those files ! How can that happen ?

    And that is my actual problem, what I am trying to do for days..

    How can get my appllication worked out on other computers, without an IDE like Eclipse.

    I tried everything making jar, using exe4j, launch4j, but I think I miss some point.

    There is no satifactory documentation out there for this kind of problem..Please Help.
    Last edited by johny2011; 04-26-2011 at 11:01 AM.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    Hi Josah,
    Thank you, your information is really helpful to me. You wrote" Your questions are not clear to me and yes" I will try to write in a more clear way.

    First of all, it is not me but the Eclipse put those 3dparty jar files and everything else into generated jar file.
    If Eclipse puts those .jar files in your .jar file, that's because you put those .jar files in Eclipe's workspace in the first place. Eclipse duly does what you told it to do: stick each and every file from a project in a .jar file. Note that you can manually select which files are to be stored in your .jar file. It is wiser not to put those other .jar files in Eclipse's workspace; store them somewhere else and import them in Eclipse (project>properties>build path).

    Create your manifest entry (it's just a text file in the workspace) and tell Eclipse to include that file as the manifest entry in your .jar file. Oh, and the creators of Eclipse did their best to create extensive online help for all the users; don't ignore that effort.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Thank you Josah, I will try that manifest file as soon as possible

    By the way, I think something misunderstood here, I am not ignoring Eclipse documentation, what I mean is that,
    not much topic on any Java site (even oracle site) about making a jar file (or a working installation) from a project that includes something more than just class files..

    And not much information how to carry projects to another computers..

    I want to ask you what you mean to store 3rd party jars somewhere else ?

    I mean, I know I load them as you told project>properties>build path).
    But in order to work in a clear way, these jar files are also in a folder JARS in my project directory, is that wrong ?

    What I must to do ?
    In order to get work my program on other computers, as a -finished product- , I mean normal software
    show other 3party JARS in the manifest file and put that manifest file and my classes into a JAR file ,
    move my JAR and all those 3rd party JARs to wherever I want my application to get work ?

    That is the way you follow ? Can you speficy more about this?

    -------------------------
    Another question I have asked before bot not answered;

    jar file works fine (while other files around) in the computer I ahve developed the project,

    It does not work when I transfer all those files to another computer (jar file and other files) . And other computer JRE J3D installed

    JRE is not enough ?
    I even installed jdk, but still not working. (just first class works, without images etc.)

    What is the problem you think ? Here is the steps I follow..

    Eclipse -> export project to jar

    Take jar (and other files) to another computer where JRE installed, and execute jar ?

    -- > not working.

    That is not enought, am I missing some point in somewhere ? (except manifest file)
    Last edited by johny2011; 04-26-2011 at 01:03 PM.

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    I mean, I know I load them as you told project>properties>build path).
    But in order to work in a clear way, these jar files are also in a folder JARS in my project directory, is that wrong ?

    What I must to do ?
    Suppose you have a .jar file YourJar.java that uses three other .jar files: A.jar, B.jar and C.jar. Also suppose the class Main contains the main( ... ) method where everything starts. Also suppose you store those four .jar files in one directory on a computer. Your manifest entry must contain the following two lines:

    Java Code:
    Main-Class: Main
    Class-Path: A.jar B.jar C.jar
    Your .jar file must not contain other .jar files but it can contain resource files such as .txt files, image files etc. Read the API documentation for the Class.getResource( ... ) and Class.getResourceAsStream( ... ) methods to read those resources. Remember: a resource in your .jar file isn't a file (anymore), it is just an entry in your .jar file.

    Installing those .jar files on another computer can be done manually but installers might be handy here; google for IzPack for a nice and free installer.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    not much topic on any Java site (even oracle site) about making a jar file (or a working installation) from a project that includes something more than just class files.

    Perhaps you should step away from Eclipse for a moment and read the Packaging Programs in Jar Files section of Oracle's Tutorial. It talks about the manifest (and classpath). Eclipse's "wizards" offer - but do not attempt to explain - all sorts of options that are more clearly seen at the command line.

    As far as packaging things other than classes are concerned, there are two problems: how you include them in the archive (covered in the Tutorial), and how you access them in your program. The latter question often involves using URLs to reference the archive entries rather than files using methods and constructors particular to the type of resource you are accessing.

    If you want your application to run correctly the key is get the classpath set correctly at runtime: as discussed above using the jar's manifest, or using a launching .bat file. The acid test is that you should be able to move the program away from your development environment and have it run.

    my final aim is to make it an exe file (or installer)

    I agree with Jos that some third party installer might be a good idea. But if you intend on setting up the installation process yourself you really should read the whole "deployment" section of the Tutorial to see what the options are.

  12. #12
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Hi, Thank you guys for the helpful information
    I have already looked at those oracle java tutorials but not satisfied,
    they dont cover the whole thing.

    As I understood there is no way to distribute my application as a single jar-file,
    I need to cary other jar files seperately whereever I want project to get work.
    (Actually I have found that there is a project to overcome this problem at this address.)
    One-JAR(TM) | Download One-JAR(TM) software for free at SourceForge.net

    (still confused, Eclipse has three options to make a jar file of a project
    and there is no option to show manifest file whilee doing a jar file, as

    Extract required libraries into generated JAR
    Package required libraries into generated JAR
    Copy required libraries into a sub-folder next to the generated JAR

    And first choice works ?? I mean it puts all JAR files into a one JAR file and that JAR file works (only on the computer I have developed my project)

    Whatever my problem is this, either way I can not get work this JAR (or JARS) on another computer..

    All I want to do is, distribute my project as a single jar-file or install or exe,
    and get it work without an IDE, for final users.

    And Another question, On one-jar project site, on oracle jar help pages, or on some other sites, it has been told to jar within command prompt.
    jar jar-file etc. etc.

    But right now I do compile my project using command prompt, I compile withing Eclipse

    I know how to compile with java, before I was using it.

    What I wonder is can compile a project later with javac from command prompt, that has been coded and generated with Eclipse ?

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    (still confused, Eclipse has three options to make a jar file of a project
    and there is no option to show manifest file whilee doing a jar file, as
    Right click on a project; then Export ...>Jar file; in the left pane select the (parts of) the project(s) you want to export; click Next> a few times and select "Use existing manifest from workspace" and select the text file you want to use for your manifest entry. Finally click Finish and you're done. Eclipse packs the files/directories you have selected and the optional manifest file in a .jar file. It is no rocket science; and above all: it's all in the online documentation ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Hey Josah, Sory to bother you but I have found that those options are only in the reguler JAR. I want to make runnable JAR

    When I want to make runnable JAR in Eclipse Helios, it does not ask anything except JAR name, main class and JAR includes which I wrote before.

    And for my other questions, still confused why a working JAR is not working properly on another computer that has JRE and J3D installed.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    Hey Josah, Sory to bother you but I have found that those options are only in the reguler JAR. I want to make runnable JAR

    When I want to make runnable JAR in Eclipse Helios, it does not ask anything except JAR name, main class and JAR includes which I wrote before.

    And for my other questions, still confused why a working JAR is not working properly on another computer that has JRE and J3D installed.
    A runnable .jar file is an ordinary .jar file with a manifest option. Don't simply push buttons and hope for the best; instead, know what you're doing even if it takes a few more button presses. Also, you can inspect your .jar file with a zip utility (zip.exe?) afterwards.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Josah, thanks . I am not trying to solve my problems by pressing buttons. I searched other sites and could not find a solution to my problem, this is why I am posting here.

    I know I can inspect those files (if you have read my previous post carefully, I wrote few time that I look inside my generated JAR files)

    Ok, I followed your instructions, prepared a manifest file and produced a jAR file but it doesnt work (even if I put this JAR file under my project - no work)

    Only way is to generate Runnable JAR in Eclipse and put it under my project, that works.

    (Another thins with Eclipse If I include other JAR file within generated runnable JAR, I dont need JAR files again under my project when I wunning it, so it seems it is not impossible to include and get work other JAR files in a JAR file ?)

    By the way, I give up project and tried my another project which does not use any external JAR. Again I exported it runnable JAR within Eclipse and again the same thing

    It does not work solely , I had to put it under my project

    When I look inside that runnable JAR, all classes, and other files (icons,images etc.) are there

    but still not working by its own. Do I have to use classes in order to load files ?
    if so isnt it only for images ? But is is not working without even classes
    How can it be possible ?

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    How can it be possible ?
    I don't know; all the information in your last reply was "it does not work"; the jar mechanism works and Eclipse is very well capable of generating jar files; all you have to do is specify what files you want to pack in that .jar file. Obviously you're specifying the wrong files or your manifest entrry isn't correct or your code doesn't read the resources from that .jar file correctly.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  18. #18
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    This is my manifest file, I dont know if is correct. In a page I have read there must be a blank line at the end of manifest file to work correct, I tried it no work.


    Main-Class: starter.class
    Class-Path: JARS\jhall.jar JARS\vrml97.jar

    Josah, if you are so sure, is it possible that I send you my java files and you make a runnable JAR and work it in any directory ?

    If it not possible, thanks anyway.

    again, I want to remind you
    -not working under different directories
    -not working on another computer
    -not working et all if I produce normal JAR with my manifest file.

    I can only get work Eclipse generated runnable JAR inside my project

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by johny2011 View Post
    This is my manifest file, I dont know if is correct. In a page I have read there must be a blank line at the end of manifest file to work correct, I tried it no work.


    Main-Class: starter.class
    Class-Path: JARS\jhall.jar JARS\vrml97.jar

    Josah, if you are so sure, is it possible that I send you my java files and you make a runnable JAR and work it in any directory ?

    If it not possible, thanks anyway.

    again, I want to remind you
    -not working under different directories
    -not working on another computer
    -not working et all if I produce normal JAR with my manifest file.

    I can only get work Eclipse generated runnable JAR inside my project
    So if you store your .jar file in a directory X the other third party .jar files have to be stored in a directory X\JARS. Did you do that?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    johny2011 is offline Member
    Join Date
    Apr 2011
    Posts
    28
    Rep Power
    0

    Default

    Yes, I already put them inside JARS directory, but not worked.

    Another question before I ask,

    All examples around oracle and sites deal with directlcy compiling with java and jaavc, from command prompt.

    Right now I am using Ecilpse,in the early days I was also using command prompt while writing with java, but I wonder how many people today out there still compiling their projects with these javac, jar etc. commands directly from command prompt ?

    Is is possible to carry big project with command prompt compiling ??

    And also, Is it possible to continue compile a project from command prompt which is before written and developed in Eclipse IDE. I am confused about this points.
    My project has many classess files etc, how can compile it from console ?
    Last edited by johny2011; 04-28-2011 at 12:17 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Creating Jar Files with functioning input files
    By appleLove in forum NetBeans
    Replies: 1
    Last Post: 04-10-2011, 10:37 PM
  2. How to get Jar files to work with Databases
    By hunterbdb in forum JDBC
    Replies: 14
    Last Post: 01-12-2011, 07:45 PM
  3. Replies: 8
    Last Post: 07-30-2010, 05:47 PM
  4. Replies: 6
    Last Post: 02-06-2009, 08:05 PM
  5. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •