• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using CF to Out Parameters From Java

Explorer ,
Nov 17, 2006 Nov 17, 2006

Copy link to clipboard

Copied

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
TOPICS
Advanced techniques

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 23, 2006 Nov 23, 2006
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.




Votes

Translate

Translate
Advisor ,
Nov 17, 2006 Nov 17, 2006

Copy link to clipboard

Copied

Did you try cfexecute?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2006 Nov 20, 2006

Copy link to clipboard

Copied

I don't know where to start. Can you please point me in the right direction, please?

Thank you,

Sevor

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 20, 2006 Nov 20, 2006

Copy link to clipboard

Copied

You would use something like:

<cfexecute
name = "java"
arguments = "processfile"
outputFile = "C:\FinishProcess.txt"
timeout = 30 <!--- Zero timeouts will NOT work! --->
/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

I will try and let you know. Thank you very much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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"
/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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"
/>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 23, 2006 Nov 23, 2006

Copy link to clipboard

Copied

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.




Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 29, 2006 Nov 29, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 02, 2006 Dec 02, 2006

Copy link to clipboard

Copied

LATEST
!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 21, 2006 Nov 21, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 22, 2006 Nov 22, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation