Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By quad64bit
  • 1 Post By UJJAL DHAR

Thread: Single executable jar

  1. #1
    Mawrecki is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Exclamation Single executable jar

    Hi,

    I have a PhoneBook directory with the following files:
    - PhoneBook.jar (the main executable jar file)
    - img.jar (includes PNG files only)
    - itextpdf-5.1.3.jar
    - qtjambi-4.7.1.jar
    - qtjambi-win32-msvc2008-4.7.1.jar
    - sqlitejdbc-v056.jar
    - database.db (SQLite)

    I know how can I conver PhoneBook.jar to PhoneBook.exe with icon-added. For this purpose I uses Launch4j tool. Launch4j - Cross-platform Java executable wrapper. The program works properly.

    Now, I would like to distribute it but only in single executable file form with the database file. Therefore, I must merge all six jar file into the one and then convert it to exe file. I was instructed to use the One-Jar with Ant, but I do not know how to do it. Can you help me with that?

    Thank you for your help in advance.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Single executable jar

    In the past, I have unpacked the jars manually (unzipped them) and then repacked them into a fresh jar with the provided java jar tools. You might need to modify the manifest file to include the other packages into the class library, but the result would be a single jar file which you could then bundle into an executable. You do realize however, that bundling into an exe will make the app platform dependent which kind of defeats the point of java to begin with right?

    I've done similar stuff with a nice app called Platypus, but I think it might be Mac only.
    Mawrecki likes this.

  3. #3
    Mawrecki is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Single executable jar

    Have you ever heard about JarJar?

    I think I should use the following syntax:

    Bash Code:
    java-jar-1.1.jar jarjar process <rulesFile> <inJar> <outJar>
    But I don't know what should be inside of the rulesFile in my case.

    Would you be willing to help me with it?

  4. #4
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Single executable jar

    you can add all jars to one single jars. You have to execute
    Java Code:
    jar cf new-jar-file-name old1.jar old2.jar.... (s)
    Then you have to manifest the new jar file. Check this for manifest.
    Mawrecki likes this.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  5. #5
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Single executable jar

    Mawrecki,
    jar umf MANIFEST.txt PhoneBook-all.jar
    Well,there is a problem.Because your main class is in PhoneBook.jar ,not in PhoneBook-All.jar . Thus this way of manifest will not work.
    Error: Could not find or load main class PhoneBook
    means that you didnt manifest PhoneBook.jar
    Got it?

    Before merging,manifest the PhoneBook.jar . Then merge all into PhoneBook-all.jar by only the first command using cf. Then I think it will work. Otherwise you may have to manifest the merged JAR too.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  6. #6
    Mawrecki is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Single executable jar

    I give you more details of this process.

    In PhoneBook directory I have got:
    - img (directory with PNG files)
    - database.db (SQLite)
    - PhoneBook.java
    - PDF.java
    - GUI.java
    - Core.java
    - MANIFEST.txt

    First of all, I create img.jar from img directory:

    Bash Code:
    jar cf img.jar img
    Next, compile Java code (which generates class file):

    Bash Code:
    javac PhoneBook.java
    Create jar file from PhoneBook.class based on MANIFEST.txt:

    MANIFEST.txt
    Manifest-Version: 1.0
    Main-Class: PhoneBook
    Class-Path: img.jar itextpdf-5.1.3.jar qtjambi-4.7.1.jar qtjambi-win32-msvc2008-4.7.1.jar sqlitejdbc-v056.jar
    <empty line>
    Bash Code:
    jar cmvf MANIFEST.txt PhoneBook.jar *.class
    Finally, I copy database.db file, PhoneBook.jar, img.jar and other jars (itextpdf-5.1.3.jar, qtjambi-4.7.1.jar, qtjambi-win32-msvc2008-4.7.1.jar, sqlitejdbc-v056.jar) into the new PhoneBook-bin folder. As you know PhoneBook.jar is executable and working now.

    In PhoneBook-bin directory I have got:
    - database.db (SQLite)
    - PhoneBook.jar (executable)
    - img.jar
    - itextpdf-5.1.3.jar
    - qtjambi-4.7.1.jar
    - qtjambi-win32-msvc2008-4.7.1.jar
    - sqlitejdbc-v056.jar

    So, what should I do next? Finally, I want only single executable jar and database.db. I tried your methods and it doesn't work.

  7. #7
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Single executable jar

    Quote Originally Posted by Mawrecki View Post
    I give you more details of this process.

    In PhoneBook directory I have got:
    - img (directory with PNG files)
    - database.db (SQLite)
    - PhoneBook.java
    - PDF.java
    - GUI.java
    - Core.java
    - MANIFEST.txt

    First of all, I create img.jar from img directory:

    Bash Code:
    jar cf img.jar img
    Next, compile Java code (which generates class file):

    Bash Code:
    javac PhoneBook.java
    Create jar file from PhoneBook.class based on MANIFEST.txt:

    MANIFEST.txt


    Bash Code:
    jar cmvf MANIFEST.txt PhoneBook.jar *.class
    Finally, I copy database.db file, PhoneBook.jar, img.jar and other jars (itextpdf-5.1.3.jar, qtjambi-4.7.1.jar, qtjambi-win32-msvc2008-4.7.1.jar, sqlitejdbc-v056.jar) into the new PhoneBook-bin folder. As you know PhoneBook.jar is executable and working now.

    In PhoneBook-bin directory I have got:
    - database.db (SQLite)
    - PhoneBook.jar (executable)
    - img.jar
    - itextpdf-5.1.3.jar
    - qtjambi-4.7.1.jar
    - qtjambi-win32-msvc2008-4.7.1.jar
    - sqlitejdbc-v056.jar

    So, what should I do next? Finally, I want only single executable jar and database.db. I tried your methods and it doesn't work.
    Now,Try this.
    jar uf PhoneBook.jar img.jar all_jars_by_space
    And try double click on PhoneBook.jar.

    If it doesnt work, read this carefully,
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  8. #8
    Mawrecki is offline Member
    Join Date
    Dec 2011
    Posts
    4
    Rep Power
    0

    Default Re: Single executable jar

    Ok, it's working now!

    Btw. there is another option:
    1. Unzip all jar files into the same directory for example: PhoneBook
    2. Add line "Main-Class: PhoneBook" into the META-INF/MANIFEST.MF file
    3. Pack all files from PhoneBook directory into PhoneBook.zip
    3. Rename PhoneBook.zip to PhoneBook.jar
    4. Double click on PhoneBook.jar

    In my idea I used 7-zip with ULTRA compression. Thanks for that my single executable jar is smaller.

  9. #9
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default Re: Single executable jar

    Ok. Remark this problem as "SOLVED"
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

Similar Threads

  1. Jar executable
    By mwr1976 in forum New To Java
    Replies: 2
    Last Post: 10-09-2011, 12:46 PM
  2. create windows executable using executable jar file
    By sarwar1234 in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 09:29 PM
  3. Packaging all files into a single executable .jar
    By ichwar in forum New To Java
    Replies: 5
    Last Post: 01-27-2010, 02:31 AM
  4. executable
    By smooth in forum New To Java
    Replies: 4
    Last Post: 06-14-2008, 06:12 PM
  5. Executable JAR
    By bugger in forum New To Java
    Replies: 4
    Last Post: 12-05-2007, 06:41 PM

Tags for this Thread

Posting Permissions

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