ta and running java classes

From: morchel <morc....at.hotmail.com>
Date: Sat, 20 Jun 2009 12:02:29 -0700 (PDT)

You may run java classes with ctrl-r, but only if they don't use
packages. Using packages you get a java.lang.NoClassDefFoundError. I
almost always use packages however.

My workaround:
In /usr/share/textadept/modules/textadept/run.lua I added the
following function which crafts the java command with the package
declaration of the java class:

        local function java_command()
          local buffer = buffer
          local buffer_text = buffer:get_text(buffer.length)
          local package = buffer_text:match('package%s+([^;]+)')
          --textadept.print('package = <'..package..'>')
          if not package then
            return 'java %(filename_noext)'
            local classpath = ''
            for dot in string.gmatch(package, '%.') do
              if WIN32 then classpath = classpath..'..\\'
              else classpath = classpath..'../' end
            local command = ''
            if WIN32 then
              command = 'java -cp %CLASSPATH%;'..classpath..'..\\ '..
              command = 'java -cp $CLASSPATH:'..classpath..'../ '..
            --textadept.print('command = <'..command..'>')
            return command

        local crafted_commands = {
          java = java_command

Then I commented out the java line in the 'go_for_ext' table and added
to the 'go' function:

    action = crafted_commands[buffer.filename:match('[^.]+$')]
    local command = action()
    --textadept.print('command ='..command)
    if command then execute(command) end

Works for me...
Received on Sat 20 Jun 2009 - 15:02:29 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:38:07 EST