21 Replies Latest reply on Dec 2, 2006 4:03 AM by BKBK

    Using CF to Out Parameters From Java

    primalx2003
      Can anyone please help me? I have a Java program that I need to pass some values into and output the result to, let's say, "FinishProcess.txt".

      I can do this by going to a command line, typing the following: java processfile > FinishProcess.txt

      This will spit the result into FinishProcess.txt but I need to automate it by using Coldfusion.

      Can someone help me please?

      Thank you,

      Sevor
        • 1. Re: Using CF to Out Parameters From Java
          MikerRoo Level 1
          Did you try cfexecute?
          • 2. Re: Using CF to Out Parameters From Java
            primalx2003 Level 1
            I don't know where to start. Can you please point me in the right direction, please?

            Thank you,

            Sevor
            • 3. Re: Using CF to Out Parameters From Java
              MikerRoo Level 1
              You would use something like:

              <cfexecute
              name = "java"
              arguments = "processfile"
              outputFile = "C:\FinishProcess.txt"
              timeout = 30 <!--- Zero timeouts will NOT work! --->
              />
              • 4. Re: Using CF to Out Parameters From Java
                primalx2003 Level 1
                I will try and let you know. Thank you very much.
                • 5. Re: Using CF to Out Parameters From Java
                  primalx2003 Level 1
                  This is the code:

                  <cfexecute
                  name = "PaperItems.java"
                  arguments = "java PaperItems"
                  outputFile = "C:\temp\paperitems.htm"
                  timeout = "30">
                  </cfexecute>

                  I get an error of: An exception occurred when invoking an external process.
                  The cause of this exception was that: java.io.IOException: CreateProcess: PaperItems.java java PaperItems error=2.

                  What does that mean??
                  • 6. Re: Using CF to Out Parameters From Java
                    Kronin555 Level 1
                    It means you did it wrong.

                    The executable name is "java". The argument is the name of the java file to execute. Look at what MikerRoo posted again.

                    <cfexecute
                    name = "java"
                    arguments = "PaperItems"
                    outputFile = "C:\temp\paperitems.htm"
                    timeout = "30"
                    />
                    • 7. Re: Using CF to Out Parameters From Java
                      primalx2003 Level 1
                      I copied and ran the same code you had. But It only produces an empty file paperitems.htm:

                      <cfexecute
                      name = "java"
                      arguments = "PaperItems"
                      outputFile = "C:\temp\paperitems.htm"
                      timeout = "30"
                      />

                      The code is suppose to output names and phones for submitted items. When I run the program using the cmd line - java PaperItems > paperitems.htm, I get all the listings of submitted items.

                      I even tried placing it in the argument section but it still produced a blank file. Please help:

                      The file is located on in my c:\temp\PaperItems.java --

                      • 8. Re: Using CF to Out Parameters From Java
                        Kronin555 Level 1
                        2 possibilities. Either it's not finding PaperItems.java, or it doesn't have permissions to write to C:\temp\paperitems.htm.

                        Is PaperItems.class in the classpath that Coldfusion is running within?

                        Does PaperItems.class exist? you keep referencing PaperItems.java...
                        • 9. Re: Using CF to Out Parameters From Java
                          Kronin555 Level 1
                          Try executing this in a DOS prompt:
                          java -classpath c:\temp\ PaperItems

                          If that works, then try:
                          <cfexecute
                          name = "java"
                          arguments = "-classpath c:\temp\ PaperItems"
                          outputFile = "C:\temp\paperitems.htm"
                          timeout = "30"
                          />

                          If that doesn't work, then coldfusion doesn't have write permissions to C:\temp
                          • 10. Re: Using CF to Out Parameters From Java
                            MikerRoo Level 1
                            Yes, the class path should do it.
                            I was expecting a different error, if that was needed, but apparently cfexecute does not pick up, process, or display java error streams.
                            • 11. Re: Using CF to Out Parameters From Java
                              primalx2003 Level 1
                              I ran the script again. This time it executed and placed the file where it needs to go but when I open the file it has the following error:

                              Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) where options include: -client to select the "client" VM -server to select the "server" VM -hotspot is a synonym for the "client" VM [deprecated] The default VM is client. -cp -classpath A ; separated list of directories, JAR archives, and ZIP archives to search for class files. -D= set a system property -verbose[:class|gc|jni] enable verbose output -version print product version and exit -version: require the specified version to run -showversion print product version and continue -jre-restrict-search | -jre-no-restrict-search include/exclude user private JREs in the version search -? -help print this help message -X print help on non-standard options -ea[:...|:] -enableassertions[:...|:] enable assertions -da[:...|:] -disableassertions[:...|:] disable assertions -esa | -enablesystemassertions enable system assertions -dsa | -disablesystemassertions disable system assertions -agentlib:[=] load native agent library , e.g. -agentlib:hprof see also, -agentlib:jdwp=help and -agentlib:hprof=help -agentpath:[=] load native agent library by full pathname -javaagent:[=] load Java programming language agent, see java.lang.instrument

                              What does this mean. I am totally confused now.

                              Please help.
                              • 12. Re: Using CF to Out Parameters From Java
                                cf_dev2 Level 1
                                primalx2003,

                                Did you try Kronin555's suggestion first? What were the results?

                                quote:

                                Try executing this in a DOS prompt:
                                java -classpath c:\temp\ PaperItems

                                • 13. Re: Using CF to Out Parameters From Java
                                  primalx2003 Level 1
                                  I tried that but it gave me this output:

                                  Usage: java [-options] class [args...]
                                  (to execute a class)
                                  or java [-options] -jar jarfile [args...]
                                  (to execute a jar file)

                                  where options include:
                                  -client to select the "client" VM
                                  -server to select the "server" VM
                                  -hotspot is a synonym for the "client" VM [deprecated]
                                  The default VM is client.

                                  -cp <class search path of directories and zip/jar files>
                                  -classpath <class search path of directories and zip/jar files>
                                  A ; separated list of directories, JAR archives,
                                  and ZIP archives to search for class files.
                                  -D<name>=<value>
                                  set a system property
                                  -verbose[:class|gc|jni]
                                  enable verbose output
                                  -version print product version and exit
                                  -version:<value>
                                  require the specified version to run
                                  -showversion print product version and continue
                                  -jre-restrict-search | -jre-no-restrict-search
                                  include/exclude user private JREs in the version search
                                  -? -help print this help message
                                  -X print help on non-standard options
                                  -ea[:<packagename>...|:<classname>]
                                  -enableassertions[:<packagename>...|:<classname>]
                                  enable assertions
                                  -da[:<packagename>...|:<classname>]
                                  -disableassertions[:<packagename>...|:<classname>]
                                  disable assertions
                                  -esa | -enablesystemassertions
                                  enable system assertions
                                  -dsa | -disablesystemassertions
                                  disable system assertions
                                  -agentlib:<libname>[=<options>]
                                  load native agent library <libname>, e.g. -agentlib:hprof
                                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
                                  -agentpath:<pathname>[=<options>]
                                  load native agent library by full pathname
                                  -javaagent:<jarpath>[=<options>]
                                  load Java programming language agent, see java.lang.instrument
                                  • 14. Re: Using CF to Out Parameters From Java
                                    cf_dev2 Level 1
                                    primalx2003,

                                    Did you put a space in between "c:\temp" and "PaperItems" like in Kronin555's example?

                                    java -classpath c:\temp\ (blank space here) PaperItems
                                    • 15. Re: Using CF to Out Parameters From Java
                                      Kronin555 Level 1
                                      Also, did you see my first suggestion?
                                      > Try executing this in a DOS prompt:
                                      > java -classpath c:\temp\ PaperItems

                                      Get it running in a DOS prompt first, then you can cut it up and put it in a cfexecute statement.

                                      And yes, there's a space in between C:\temp\ and PaperItems.

                                      Are you sure PaperItems.class exists in C:\temp\??

                                      Post the _EXACT_ code and/or command you have tested that has failed.
                                      • 16. Re: Using CF to Out Parameters From Java
                                        BKBK Adobe Community Professional & MVP
                                        So close. Assuming the class file PaperItems.class is in the directory C:\temp\ then the following should work

                                        <cfexecute
                                        name = "java"
                                        arguments = "-classpath c:\temp\ PaperItems"
                                        outputFile = "C:\temp\paperitems.htm"
                                        timeout = "30"
                                        />

                                        • 17. Re: Using CF to Out Parameters From Java
                                          cf_dev2 Level 1
                                          BKBK,

                                          The file c:\temp\PaperItems.class probably does exist or java.exe would return a NoClassDefFoundError.

                                          My guess is primalx2003 overlooked the space in between the -classpath and class name. Without the space -classpath becomes "c:\temp\PaperItems" and the command fails because it does not contain a class name.

                                          Both Kronin555's example and yours work fine for me .. so my vote is for a missing space.




                                          • 18. Using CF to Out Parameters From Java
                                            primalx2003 Level 1
                                            It was the spacing issue. It works fine now. Thank you all for your help.


                                            I had the following:
                                            <cfexecute
                                            name = "java"
                                            arguments = "- classpath c:\temp\PaperItems"
                                            outputFile = "C:\temp\paperitems.htm"
                                            timeout = "30"
                                            />

                                            Where it should have been:
                                            <cfexecute
                                            name = "java"
                                            arguments = "-classpath c:\temp\ PaperItems"
                                            outputFile = "C:\temp\paperitems.htm"
                                            timeout = "30"
                                            />

                                            Thank you so much.
                                            • 19. Re: Using CF to Out Parameters From Java
                                              BKBK Adobe Community Professional & MVP
                                              BKBK,
                                              The file c:\temp\PaperItems.class probably does exist or java.exe would return a NoClassDefFoundError.


                                              Yes, of course, Java would. However, would Coldfusion's cfexecute, too. Even with try-catch? (Haven't tested it). In any case, by Assuming the class file PaperItems.class is in the directory C:\temp\ I simply meant "Given that the class file PaperItems.class is in the directory C:\temp\ ".

                                              It's reassuring that all the suggestions work. I think this writing mechanism quite handy. No java.io in sight.

                                              • 20. Re: Using CF to Out Parameters From Java
                                                cf_dev2 Level 1
                                                BKBK,

                                                Yeh, I hear you. But I wasn't talking about the results from cfexecute. primalx2006's said he ran the command at a DOS prompt and java.exe returned a Usage error instead of NoClassDefFoundError, suggesting a syntax problem rather than a missing class.