calling java class from web page

G

Guest

ASP.NET 2.0 / Visual Studio 2005 / VB.Net 2.0

I have a web interface that needs to launch a java application.

What a long strange trip it has been...

I am using Process.Start process start info parameters, first to launch the
java app by itself with the call:

"C:\Program Files\Java\jdk1.5.0_12\bin\java.exe" javaAppName Arg1 Arg2

That didn't work so then I wrote a console app to call the java app, and I
call the console app from the web page by using Process.Start.

Now I get the following error reported from the console app:

java.lang.NoClassDefFoundError: javaAppName Exception in thread "main"

Please NOTE that when the console app is run through command prompt the java
app runs perfectly. I have checked and double checked permissions.

Console App code to launch java application:

Private Sub JavaJive()
My.Computer.FileSystem.CurrentDirectory = "C:\javaAppName\"
Try
Dim proc As Process = New Process()
Dim sjavaDir As String = "C:\Program Files\Java\jdk1.5.0_12\bin\"
Dim sjavaApp As String = "C:\javaAppName\"
Dim resourceDir As String = "C:\Inetpub\wwwroot\javaAppName\"
Dim pathArray() As String
pathArray = New String() {sjavaDir, sATradDir, resourceDir}
Dim fIOP As New FileIOPermission(PermissionState.Unrestricted)
fIOP.AddPathList(FileIOPermissionAccess.AllAccess, sjavaDir)
fIOP.AddPathList(FileIOPermissionAccess.AllAccess, sATradDir)
fIOP.AddPathList(FileIOPermissionAccess.AllAccess, resourceDir)
fIOP.SetPathList(FileIOPermissionAccess.AllAccess, pathArray)

With proc.StartInfo
.FileName = JAVAPath & CLASSPATH & " " & javaAppName & " " & _
ChrW(34) & Arg1 & ChrW(34) & " " & Arg2
.UseShellExecute = False
.RedirectStandardOutput = True
.RedirectStandardError = True
.WorkingDirectory = "C:\javaApp"
End With

proc.Start()
If proc.Responding Then proc.WaitForExit(120000) 'its a long
process...

Dim sReader As StreamReader = proc.StandardError
Console.WriteLine(String.Format("ProcErr: {0}{1}",
sReader.ReadToEnd, Environment.NewLine))
sReader = proc.StandardOutput
Console.WriteLine(String.Format("ProcOutPut: {0}{1}",
sReader.ReadToEnd, Environment.NewLine))
Catch ex As Exception
If Environment.UserInteractive Then
Console.WriteLine(String.Format("JavaCon {0}{1}Error: {2}", _
My.Application.Info.Version.ToString, _
Environment.NewLine, ex.Message))
End If
End Try
End Sub


Any suggestions greatly appreciated.
 
R

Roland Dick

Hi Jonnie,

VB said:
I am using Process.Start process start info parameters, first to launch the
java app by itself with the call:

"C:\Program Files\Java\jdk1.5.0_12\bin\java.exe" javaAppName Arg1 Arg2

I have no idea about Java, but your issues with the Process.Start
command sounds like a problem with the user account your web application
runs under. Try to create a new Application Pool that executes under an
Administrator account (hey, it's for testing only, right?) and let your
webapp run under that account. If you're on WinXP, set the identity of
the anonymous account to an administrative account.
If it works then, you're at least pointed in the direction where the
problem comes from.

Also, just as a wild guess, enter the command to start the java app in a
batch file and call just the batch file from your website. This is just
to make sure there are no problems with quotation marks or similar, and
you can also add some "tracing" into the batch file via the > pipe.

Hope this helps.

Roland
 
G

Guest

Thanks for the information, Sam. I will look into IKVM, at first glance it
looks promising, but probably for future projects. This particular project
involves using java code to interact with Pro/E (3D CAD application), and due
to project time constraints re-writing the entire app would be too costly.
 
P

Patrice

Have you check that the CLASSPATH environment variable is available ? You
could likely also add the -classpath option in the command line.

You could also try a Java group as this is IMO rleated to a Java
configuration (the classpath environment variable) rather than a problem
with .NET.
 
G

Guest

Patrice,

I have tried adding the -classpath to the command line call but it did not
help, unfortunately.

When I run either a batch file or .net console app from the command line the
java application launches correctly and runs the Pro/E program as desired. It
is only when I attempt to call either of these apps (batch file or console
app) from my ASP.Net page that the java application does not launch.

Thanks for the input, I am still looking into permissions and perhaps IIS
restrictions to accessing external files. My hope is that someone reading
this discussion will have come accross this type of issue before.

I have sucessfully used Process.Start through an ASP.Net web page to start
up an external application.
 
P

Patrice

The error message really make me think that some class is not found. Double
check perhaps that you don't depend on a class whose definition is not in
the classpath. (are you using the same value than the one found in the
environment variable, use SET to majke sure the environment variable hold
the same value than the one you tried).

Tools from sysinternals (redirects to MS) such as the "filemon" tool could
also help as you could see which classes are loaded when using the command
line and whihc file it doesn't find when running from an ASP.NET page (or if
perhaps the directory in whihc are Java classes doesn't have the appropriate
ACL).
 
G

Guest

Roland (and all that have replied) - Thank you so much for all of the
suggestions. I am still in battle with this crazy thing...

I set up a new application pool with full admin rights - no avail.

I can run the java app through the command line with the following call:

C:\JavaApp>"C:\Program Files\Java\jdk1.5.0_12\bin\java" JavaApp Arg1 Arg2

I put the same command into a batch file and call it from command promt, and
it works just swell. When I run same batch file from the ASP page
(process.start), however, I get the following output error:

Exception in thread "main" java.lang.NoClassDefFoundError: classpath
C:/Program Files/proeWildfire 3/0/text/java/pfcasync/jar

Please NOTE:
The classpath is:
C:/Program Files/proeWildfire 3.0/text/java/pfcasync.jar

The error is:
C:/Program Files/proeWildfire 3/0/text/java/pfcasync/jar (the dots are
replaced with slashes... argh!)

Using the -classpath switch in my batch file from command prompt produces
the same result.

Still searching and testing... again thanks for all of the great suggestions
and tips.
 
G

Guest

Patrice,

The tools from sysinternals are awesome, thanks for the heads up. I was able
to identify a couple of access denial errors and correct them using the
process monitor.

I posted a reply to Roland Dick with details of my adventures, and have
checked and double checked classpath variables and used the -classpath switch.

Thanks for the assistance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top