7

I've been having trouble setting up ditaa to work in emacs, I got my copy of the ditaa jar from here And I've been trying to run this code block

#+begin_src ditaa :file hello.png :exports results 
  +----------------+
  | Hello World!!! |
  |                |
  +----------------+

#+end_src

When I evaluate it with C-c C-c I get A blank png buffer and this:

 Error: Unable to access jarfile /home/nalis/emacs-custom-packages/ditaa/ditaa.jar

in a buffer called Shell Command Output

I've tried moving the jar files to shorter names, putting their location in my system path, and running ditaa outside of emacs to my success.

My Current configurations for my org group are:

Org Ditaa Jar Path: ~/emacs-custom-packages/ditaa/ditaa.jar
Org Babel Ditaa Java Cmd: java
Org Ditaa Jar Option: -jar

And I am running: GNU Emacs 24.5.1 (x86_64-unknown-cygwin, GTK+ Version 3.14.13) of 2015-06-23 on desktop-new

Nalisarc
  • 296
  • 3
  • 11
  • 1
    Since this is on Windows, I think I remember there was an issue with "trusting" files that were downloaded from the internet. Could it possibly be something like that? I think that in the file properties (something that should be accessible from the context menu in explorer) on the first tab it'd say something about downloading files from the internet and have a checkbox you need to tick / untick. Also, is this Java installed through Cigwin, or is this a Windows Java? If it is the later, did you try giving it the Windows-y path instead? – wvxvw Mar 04 '16 at 09:20
  • I had @melioratus take a look at it, and he said something along those lines about it being a permissions problem. As for my java installation it was done in windows, and the windows-y paths all net the same problem. But I'll take a look at the jar files themselves. – Nalisarc Mar 05 '16 at 01:04
  • @wvxvw You're right! I had to unblock them in properties, now I can call them as long as I am above the jar files in cmd and minty, so that's part of the problem thanks! – Nalisarc Mar 05 '16 at 01:18
  • Cool, glad I could help. – wvxvw Mar 05 '16 at 09:38

4 Answers4

6

I am afraid that moving files manually will mess up my system, confuse my package manager and only work until the next update. Instead, you can simply added the true path for ditaa.jar to your .emacs or .emacs.d/init.el. In my case:

(setq org-ditaa-jar-path "/usr/share/ditaa/lib/ditaa.jar")
AstroFloyd
  • 409
  • 3
  • 11
4

Try this

  1. Find full directory path where emacs expects ditaa.jar to be located.

    This code is copied from ob-ditaa.el

    #+begin_src elisp
    (expand-file-name
                 "ditaa.jar"
          (file-name-as-directory
                (expand-file-name
                    "scripts"
                   (file-name-as-directory
                      (expand-file-name
                          "../contrib"
                         (file-name-directory (org-find-library-dir "org")))))))
    #+end_src
    

    Note: This path in your setup may be different, so you should run the code above to check then adjust the instructions to meet your specific path.

    #+RESULTS:
    : /usr/share/emacs/24.5/lisp/contrib/scripts/ditaa.jar
    
  2. Copy ditaa.jar and DitaaEps.jar into expected directory, e.g. /usr/share/emacs/24.5/lisp/contrib/scripts

  3. Windows specific step - Confirm that ditaa.jar and DitaaEps.jar are unblocked otherwise Windows OS will block execution.

  4. Cygwin specific step - Create call-ditaa.sh wrapper script.

    Note: The Oracle JSE for Windows expects Windows paths not Cygwin paths, so we needed to convert using cygpath command.

    #+begin_src sh :tangle yes :shebang #!/usr/bin/env bash
    
        #
        # Convert to windows file paths.
        #
    
        java $1 $2 "$(cygpath -w $3)" "$(cygpath -w $4)" "$(cygpath -w $5)"
    
    
    #+end_src
    
  5. Cygwin specific Step - Customize org-mode to use wrapper script instead calling java directly.

    Note: I suggest putting call-ditaa.sh script in same directory as ditaa.jar.

    Org Babel Ditaa Java Cmd: /usr/share/emacs/24.5/lisp/contrib/scripts/call-ditaa.sh
    
  6. Customize org-mode to Org Ditaa Jar Path to expected path, e.g. /usr/share/emacs/24.5/lisp/contrib/scripts/ditaa.jar

  7. Apply & Save customization

  8. Test Updated ditaa Settings

    #+begin_src ditaa :file ./helloworld.png
    +----------------+
    | Hello World!!! |
    |                |
    +----------------+
    #+end_src
    
    #+RESULTS:
    [[file:./helloworld.png]]
    
Melioratus
  • 4,504
  • 1
  • 25
  • 43
  • When I save in org-mode, it removes the trailing whitespace off each line. This breaks my diagram. any ideas on how one might mitigate that issue? – JonathanPeel Jan 09 '22 at 13:12
1

Base on Melioratus answer I did this:

 cd .emacs.d/elpa && mkdir contrib
 cd contrib %% mkdir scripts
 cd scripts
 which ditaa   ## I have mine in /usr/local/bin
 ln -s /usr/local/bin/ditaa0_9.jar ditaa.jar
 ln -s /usr/local/bin/DitaaEps.jar DitaaEps.jar

Now emacs/ org-babel can find ditaa, success!

0

I've tried moving the jar files to ... my system path

try lib path instead, or run this command at a terminal prompt to see if ditaa runs on your system without errors:

java -jar ditaaXXX.jar

adjust the path to the jar file, where xxx is the version number. If installed properly, you'd get the help screen for command line options.

Emacs User
  • 5,553
  • 18
  • 48
  • Okay, I moved ditaa.jar to my /lib/ directory, and renamed it ditaa0_9.jar when I call it in bash I get the same error, but when I use cd to move to lib then it works. – Nalisarc Mar 04 '16 at 01:55
  • try fixing lib path to properly recognize that /dir/ – Emacs User Mar 04 '16 at 02:37