Announcement

Collapse
No announcement yet.

How to make channel to run jar files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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
    Last edited by bradd; 08-18-2010, 08:47 AM.

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


        • #5
          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 ?

          Comment


          • #6
            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();
            		}
            	}
            }

            Comment


            • #7
              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.

              Comment


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

                Comment


                • #9
                  By eclipse

                  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
                  Attached Files
                  Last edited by Dr. L; 08-19-2010, 03:32 AM.

                  Comment


                  • #10
                    For the mirth

                    Hi bradd,


                    Has made the steps on mirth channel.

                    Has the attachements.
                    Attached Files

                    Comment


                    • #11
                      What I do is:

                      1. right click on the project folder
                      2. hit export
                      3. use all of the defaults but choose a destination(of course).
                      4. hit finish

                      Try the above steps. I have attached a screenshot of my export settings. In this case my project was "called hello world".

                      -Brad
                      Attached Files

                      Comment


                      • #12
                        Hi man thanks

                        Hi Once again thanks,


                        Is the mirth channel ok or do you have any comment with that ?

                        I've tried to put it to run but gets me the error once again.

                        I feel that i'm near what I intented to do.

                        So in last effort could you please help me (once more)

                        Thanks

                        Comment


                        • #13
                          is the error coming from eclipse or mirth? and can you post it again

                          Also, your channel looks fine
                          Last edited by bradd; 08-19-2010, 09:26 AM.

                          Comment


                          • #14
                            Thanks Bradd

                            Hi there

                            With the code that you have posted we have an error on mirth.

                            On eclipse we have a slightly problem saying that

                            started with null constructor

                            Posted on eclipse post images (image1.jpg at bottom).

                            I think we solved that, then we exported like you said.

                            And then the problem remains on mirth. (posted screenshots on lastpost of the first page).

                            Did I understood well your question or isn't done anything like this ?

                            Thanks once agian.

                            Comment


                            • #15
                              your problem with Mirth is that the javascript reader needs to return the message. So if the input is xml you need to do a

                              return "<xml>data</xml>";

                              I'm not sure what you will need to do if the input is DICOM, it gets a bit tricky. I'm not sure what you are trying to do with DICOM messages so I can't advise you on what to do next.

                              Comment

                              Working...
                              X