Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Run Java Class from DOS batch file

Posted on 2013-06-04
7
Medium Priority
?
702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 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 36

Assisted Solution

by:mccarl
mccarl earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 36

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

609 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