Solved

Run Java Class from DOS batch file

Posted on 2013-06-04
7
683 Views
Last Modified: 2013-11-13
I created a Java class from Eclipse and need to deploy it to another machine.

I tried creating a simple batch file to run it like this:

cmd /c java bliffo
pause

Open in new window


However, I get
Exception in thread "main" java.lang.NoClassDefFoundError: bliffo (wrong name: BliffoscopeDataAnalysis/bliffo)

I tried adding JAVA_HOME and PATH and CLASSPATH in various ways but keep getting the same error.

What should my batch file look like (and remember that I have to deploy on someone else's machine with unknown settings, but I'll assume that a jre is installed somewhere on it, such as mine: C:\Program Files\Java\jdk1.7.0_21
0
Comment
Question by:rspahitz
  • 3
  • 3
7 Comments
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 39221098
Firstly, you will need the following directory structure...

|
|--- run.bat
|
|--- BliffoscopeDataAnalysis     (Note: this is a directory)
                |
                |--- bliffo.class


And then change the batch file (run.bat in the above diagram) to this...

cmd /c java BliffoscopeDataAnalysis.bliffo
pause

Open in new window

0
 
LVL 22

Author Comment

by:rspahitz
ID: 39221147
Yay!  that got me started.

Now I'm getting this:
Exception in thread "main" java.lang.NoClassDefFoundError: BliffoscopeDataAnalys
is/bliffo$TargetType

and my code includes this:

enum TargetType

So I'm guessing this is related...

Any other thoughts?
0
 
LVL 35

Assisted Solution

by:mccarl
mccarl earned 500 total points
ID: 39221159
You need "bliffo$TargetType.class" and any other "bliffo$_______.class" files that Eclipse generated to be copied over to the other machine, not just "bliffo.class" and they go in the same place as "bliffo.class"
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 86

Expert Comment

by:CEHJ
ID: 39221424
You should export the app as an executable jar in Eclipse. That will ensure all dependencies are met and will make the batch file easier to run (see below). Make sure you set the correct main class when you export

cmd /c java -jar bliffo.jar
pause

Open in new window

0
 
LVL 22

Author Comment

by:rspahitz
ID: 39222413
Oddly, I thought those were temp files...that problem gone but now this:

Exception in thread "main" java.lang.NoClassDefFoundError: BliffoscopeDataAnalysis/bliffo$1

on this line:
switch (confidenceLevel)

Open in new window

which comes after
confidenceLevel = getConfidence(hitPct);

Open in new window

which is defined as
private static ConfidenceLevel getConfidence(double percentage)

Open in new window

and
I'll try the jar file idea too.
0
 
LVL 22

Author Closing Comment

by:rspahitz
ID: 39222524
I just realized that when I compiled the code separately, it created the $1 file so I'm ready to go...Thanks!
(I'll investigate the jar file next time.)
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39224392
Not a problem. Yeah, using a jar file will make your deployment MUCH easier.

However, this was probably still a useful exercise for you, so that you understand some of the intricacies of Java class loading and classpaths.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question