Hi Erando,

Java files aren't like JSP-Files. Tomcat won't compile them automatically.

You need to compile the Java file into a .class file, and put the .class file 
into your WEB-INF/classes folder (within subfolders representing the package 
declaration of your class).

Explaining how to do this properly would be quite a big subject for an email. 
You might need to go through a few Java tutorials to get comfortable with Java 
first.

But as a "quick and dirty" solution you could do the following:

Download and install eclipse.
Create a new Java Project.
Edit your Project's "Build Path" and add all the libraries from Magnolia's 
WEB-INF/lib folder using the "Add external JARs" button.
Add your class to the project.
Your class should now compile.
Find the .class file within the project folder (usually in a folder called 
"bin") and copy it to WEB-INF/classes.
Restart tomcat.

Note also you can use groovy to do all this, by creating a groovy class (rather 
than a script). That might be a better solution for you as it will save you 
messing around with Java and Eclipse...

Regards from Vienna,

Richard



-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Erando (via Magnolia Forums)
Gesendet: Dienstag, 08. Oktober 2013 12:39
An: Magnolia User List
Betreff: [magnolia-user] Running custom command

Hi guys,

I need your help here. Can you tell me how to run a single command which is not 
part of a module?
I created a Java class TestCommand.java:

[code]public class TestCommand extends MgnlCommand {
  public execute(Context ctx) {
    System.out.println("TEST COMMAND");
  }
}[/code]

I copied this file into WEB-INF/classes and registered it like this:
[img]http://i12.photobucket.com/albums/a235/mhbgif/command.jpg[/img]

Then I wanted to run it in the Groovy console:

[code]Welcome to the Magnolia Groovy Interactive Console! Type 'help' for more 
info and a list of available commands. [Using Groovy version 1.7.10].
mgnl> cm = info.magnolia.commands.CommandsManager.getInstance()
===>
info.magnolia.commands.CommandsManager@1f701045
mgnl> command = cm.getCommand('myCommand')
===>
null
mgnl> command.execute(ctx)
NullPointerException: Cannot invoke method execute() on null object[/code]

But after the second line it doesn't return an object but null. I guess this is 
because the java class hasn't been compiled yet. Is that true? How do I do this?

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=487971f2-483f-4373-a929-b5f1f50edc05


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to