Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   How to make channel to run jar files (http://www.mirthcorp.com/community/forums/showthread.php?t=4297)

Dr. L 08-18-2010 09:28 AM

How to make channel to run jar files
 
HI there,


I'm consumed with this part of mirth.

Althout I've been researching on how to make a channel to run a jar file executing embebed a batchfile inside of them.



Is it possible to find any how to ?


Thanks in advanced.

bradd 08-18-2010 09:44 AM

1. put jar into Mirth 1.8.2\lib\custom directory
2. restart Mirth Service
3. use this code:

var object = new Packages.[fully-qualified name]();

example if we had a class dicom in the com.mirth.connectors package of a project:

var object = new Packages.com.mirth.connectors.dicom();
//Then you can call methods from the object
object.doStuff()

-Brad

Dr. L 08-18-2010 10:21 AM

Thanks
 
Hi there,

I've got some doubts where the fully qualified enters ?

And then when you do object.doStuff(); I'm assuming that do stuff could be doteste.


So if the code is :

package QR;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class qr {


public qr(){
final Runtime r = Runtime.getRuntime();
Process p;
try {
p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"},
null, new File("C:\\teste.bat"));
final PrintWriter writer = new PrintWriter(p.getOutputStream());
writer.println("help");
writer.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}


Then it would be something like this:

var object = new Packages.QR();
object.doStuff() or object.doQR()


Any help ?

Thanks once again

bradd 08-18-2010 11:33 AM

since your class is called qr do this:

var object = new Packages.qr();

rather than having all your logic in the constructor of the object why don't you put it in a public method called execute. So it would look like this:

Code:

public qr(){
}

public void execute(){
final Runtime r = Runtime.getRuntime();
Process p;
try {
p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"},
null, new File("C:\\teste.bat"));
final PrintWriter writer = new PrintWriter(p.getOutputStream());
writer.println("help");
writer.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}

since your class is called qr do this:

var object = new Packages.qr();
object.execute();

Generally you don't want to have too much logic in your constructor. The code may be poorly formatted, but I'm sure you can fix that up :)

Dr. L 08-18-2010 12:21 PM

Thanks
 
Thanks once again


I've tried the code that you post but when I try to run with eclipse is says IWAV0048I Java Bean qr.QR started with null constructor.

I think it could be

public qr (){
}

Any help ?

bradd 08-18-2010 03:09 PM

This should work. If you are having a lot of issues with Mirth and creating custom libraries consider purchasing support and we will walk you through the process.


Code:

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;


public class qr {

        public qr(){
               
        }
       
        public void execute(){
                final Runtime r = Runtime.getRuntime();
                Process p;
                try {
                p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"},
                null, new File("C:\\teste.bat"));
                final PrintWriter writer = new PrintWriter(p.getOutputStream());
                writer.println("help");
                writer.close();
                } catch (final IOException e) {
                e.printStackTrace();
                }
        }
}


Dr. L 08-18-2010 05:01 PM

Thanks Bradd
 
Hi

Thanks once again

the problem weren't the import or public class qr, but the bold field .This jar file is made on eclipse and then exporten with javabean.


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;


public class qr {

public qr(){

}


public void execute(){
final Runtime r = Runtime.getRuntime();
Process p;
try {
p = r.exec(new String[] {"cmd.exe", "/c", "start", "teste.bat"},
null, new File("C:\\teste.bat"));
final PrintWriter writer = new PrintWriter(p.getOutputStream());
writer.println("help");
writer.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}


The error is the same.

bradd 08-18-2010 05:36 PM

why not use the eclipse export? Works fine for me.

Dr. L 08-19-2010 04:27 AM

By eclipse
 
5 Attachment(s)
Hi bradd,

Thanks Once again

from the following I have made a screenshots from eclipse and the steps that I made till jar file is done.

Althoug I have one problem in the bottom of the first image I have the error that I've been posting.

Missing the last screenshot that contains the .jar file.

I will have another post to make step by step on how I create channel on mirth

Dr. L 08-19-2010 04:40 AM

For the mirth
 
4 Attachment(s)
Hi bradd,


Has made the steps on mirth channel.

Has the attachements.


All times are GMT -8. The time now is 05:55 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation