Solved

Run Java Class from DOS batch file

Posted on 2013-06-04
7
676 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now