1

Is there a way to convert JAR lib into JAR standalone? I need to find a standalone java executable that convert PDF into TIFF and I've found these JARs: http://www.icefaces.org/JForum/posts/list/17504.page

Any ideas?

user626415
  • 71
  • 3
  • 6
  • this can help you: http://stackoverflow.com/questions/804466/how-do-i-create-executable-java-program and http://www.herongyang.com/Java-Tools/jar-Create-Executable-JAR-Files.html. Also you can try Jar2Exe converter to create .exe if you are running on windows machine. – Harry Joy Feb 21 '11 at 13:13
  • That question handles the case when there is a main class. – user unknown Feb 21 '11 at 14:06
  • I've found another class that seems easier to configure: http://kickjava.com/src/PDFtoTIFF.java.htm – user626415 Feb 22 '11 at 13:06

3 Answers3

1

Easiest might be to create another Jar with a Main() entry point, and then just use the java.exe executable to run it:

e.g.

> java.exe -cp MyJarMain.jar;MyPDFJar.jar com.mydomain.MyMain myPDF.pdf

Where MyMain is a class with a Main static method.

You'll need something with a main entry point to pass in and interpret some command line arguments (myPDF.pdf in my made-up example)

izb
  • 50,101
  • 39
  • 117
  • 168
0

You could do an assembly (are you using maven?) and make sure the Main-Class entry in the manifest.mf points to the main class.

extraneon
  • 23,575
  • 2
  • 47
  • 51
  • in manifest.mf thers is no Main-Class entry, I think because these are lib jar... – user626415 Feb 21 '11 at 14:17
  • @user626415 You usually write a main class. And then modify/write a new Manifest.mf that points to the main class. That way java knows where to start running your code. – extraneon Feb 21 '11 at 14:41
0

Since there is no main-Method, you have to write one, or write a whole new class to call the class/method TiffConver.convertPDF .

The question is, how you're going to use it. From the command line, you need no executable jar. From the Gui, maybe you want to pass a file to be converted by drag and drop? Then you should take the parameter(s) passed to main as Input-PDF-Names (if they end in .pdf) and pass the names iteratively to TiffConverter, for "a.pdf b.pdf" => TiffConver.convertPDF ("a.pdf", "a.tiff"); TiffConver.convertPDF ("b.pdf", "b.tiff");

TiffCoverter will silently overwrite existing tiffs, so check that before or change the code there - this is clearly bad habit, and look out for more such things - I didn't.

/*
 * Remove target file if exists
 */
File f = new File(tif);
if (f.exists()) {
    f.delete();
}

Maybe you wan't to write a swing-wrapper, which let's you choose Files interactively to be converted. This would be a nice idee, if no filename is given.

If the user passes "a.pdf xy.tiff" you could rename the converted file to xy, as additional feature.

Without a main-class, however, a standalone jar would be magic.

However, building a native executale is almost always a bad idea. You loose portability, you don't profit from security- and performance improvements to the JVM or fixed bugs. For multiple programs you need always an independend bugfix, which you might have to manage yourself, if you don't have a package-management as most linux distros have.


after clearing some questions:

public static void main (String [] args) {

    if (args.length == 1 && args[0].endsWith (".pdf")) {
        String target = args[0].replaceAll (".pdf$", ".tif");
        convertPDF (args[0], target);
    }
}

This method you put into TiffConvert. It will allow you to convert a simple pdf-File, and generate a tif-File with the same basename but ending in .tif, silently overwriting an existing one of the same name.

I guess you now need to know how to start it?

user unknown
  • 35,537
  • 11
  • 75
  • 121
  • We are going to use it from AS/400 command line. I need to compile it from another pc (Linux Host), copy into AS/400 server and launch it from the command line. I need a single file portable executable – user626415 Feb 21 '11 at 14:17
  • But java is installed on the AS/400? I never used an AS/400 but if there is a JVM, class-files will be portable. How do you wan't to invoke your conversions? You don't know java at all, right? – user unknown Feb 21 '11 at 14:23
  • Yes, Java is installed on the AS/400. We need to launch the conversione with "java" command. I used Java long time ago, but at the moment I'm a bit ignorant about java... – user626415 Feb 21 '11 at 14:30
  • And do you give it always one pdf-File, or multiple? Do you like to start it `java TifConvert a.pdf b.pdf c.pdf` and expect it to generate `a.tif b.tif c.tif` or is it sufficient it you start it with `java TifConvert a.pdf` and get `a.tif'? Or do you need to specify the name of the output tif: `java TifConvert source.pdf target.tif`? Is it ok to silently override probably existing tifs? – user unknown Feb 21 '11 at 15:13
  • Because of code-formatting I give a simple extension in my answer. – user unknown Feb 21 '11 at 15:17
  • while trying to compile the stuff I realize, that you need the package where org.icepdf.core.pobjects.Document and the like is included. It wasn't part of the zip. – user unknown Feb 21 '11 at 15:30
  • I need a simple 1-to-1 pdf-to-tif conversion, the name of the file can be the same but with different extension. I've put the method into a file called TiffConvert.java and exec it: java TiffConvert test.pdf but it fails. – user626415 Feb 21 '11 at 16:22
  • You have to be more specific, **what** error do you get? `TiffConvert.java:35: package org.icepdf.core.exceptions does not exist import org.icepdf.core.exceptions.PDFException;` As I mentioned, you need a package (jar) which contains it - I would google for it. – user unknown Feb 21 '11 at 16:49
  • Ok, I have only copy and pasted the code into a file called TiffConvert.java and executed it with: java TiffConvert test.pdf – user626415 Feb 21 '11 at 17:02
  • Errors: Exception in thread "main" java.lang.NoClassDefFoundError: TiffConvert Caused by: java.lang.ClassNotFoundException: TiffConvert at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: TiffConvert. Program will exit. It misses some libs I think – user626415 Feb 21 '11 at 17:02
  • a) You don't create a new file TiffConvert.java, but use the one which is on the side you gave yourself. b) You have to compile the file first - did you did that? To compile it, you need said pdf-library from http://www.icepdf.org/ which is pretty big, so I'm not going to download it myself, because I'm sitting on a lowbandwidth connection right now. – user unknown Feb 21 '11 at 17:09
  • Ok guys, I'm really sorry about my ignorance. At the moment I have 2 dirs, called com and org, and TiffConvert.java patched as described above. In org dir I put icepdf libs (icepdf/core/...) and in com dir I put others lib (pjr/tif/...). Now, trying to compile with javac TiffConvert.java, it say me: TiffConvert.java:287: class, interface, or enum expected public static void main (String [] args) { ^ TiffConvert.java:291: class, interface, or enum expected convertPDF (args[0], target); ^ TiffConvert.java:292: class, interface, or enum expected } ^ 3 errors – user626415 Feb 22 '11 at 07:55
  • You never used java - am I right? You have to put the main method **inside** the class, which means after the method there is **one** additional closing } . – user unknown Feb 22 '11 at 08:33