Solved

Jar File Error: Could not find main class.

Posted on 2006-06-09
10
232 Views
Last Modified: 2013-11-23
I build my jar file using BENV.
It doesn't work in a directory with "src" in it.  I.E. C:views\ifd\src\copper
All other times it works.  
0
Comment
Question by:tjwallace05
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:hoomanv
ID: 16872789
how do you run it ? by double clicking ? or java -jar yourjar.jar ?
did you specified its main class in MANIFEST.MF
  Manifest-Version: 1.2
  Main-Class: DiveLog
and how do you create jar ? jar -cmf yourjar.jar MANIFEST.MF *.class
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16872816
typo --> jar -cmf should be jar -cfm
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16872912
0
 

Author Comment

by:tjwallace05
ID: 16873226
To make my jar, I use a program call BENV which is just a build enviroment.
I specified my main class in the Manifest file.
I run the jar file both by double clicking it and by running a batch file from the commandline.
It will not run (double clicking) in a directory with "src" in it but it will run anywhere else.
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16873422
please post the content of the manifest along with the batch file

> It will not run (double clicking) in a directory with "src" in it but it will run anywhere else.
you mean the existance of another folder named "src" near the jar, does impact on the execution ?
could you explain more in which circumstance(s) it fails to run
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.

 

Author Comment

by:tjwallace05
ID: 16873826
this is the batch file I use to create the jar file.
@echo off
:: This script is used to launch the make.  Type mk /? for help
::

:: Test if the environment is set
IF "/%BENV_LATEST_ROOT%"=="/" GOTO error
IF "%OS%"=="Windows_NT" which java.exe 2>NUL 1>NUL
IF NOT "%OS%"=="Windows_NT" which java.exe >NUL
if ERRORLEVEL 1 goto notfound
IF "%OS%"=="Windows_NT" which javac.exe 2>NUL 1>NUL
IF NOT "%OS%"=="Windows_NT" which javac.exe >NUL
if ERRORLEVEL 1 goto notfound

:: Launch make
call findroot
sh %BENV_WORKAREA_ROOT%\build\gnu\bin\unix\Mk -T win32 %1 %2 %3 %4 %5 %6 %7 %8 %9
goto exit
:notfound
echo:
echo:You must first set JAVA Development environment by updating your PATH
echo:to include the JVM, the JAVA compiler, and SDK tools.
echo:
goto exit
:error
echo:
echo:You must first set the variable: BENV_LATEST_ROOT.
echo:
:exit


Batch file to run jar file:
@echo off
:: Batch file to set alias for executing the java application
::

:: Name of the jarfile
set jarname=jxcodegui.jar

:: Set alias
doskey jxcodegui=java -jar %jarname% $*

echo:Alias 'jxcode' has been set.  Run the command again to execute
echo:the application.
echo:
echo:To update the 'jxcode' alias. Run jxcode.bat again
echo:

Manifest file:
Manifest-Version: 1.0
Created-By: 1.4.2_11 (Sun Microsystems Inc.)
Main-Class: JXCodeGuiMain

My program generates skeleton files in the folder from which it is executed.  So if I run the program from a folder like C:\views\codegen\projects it will run but if I place the jar file in C:\views\codegen\src it will not run.  If "src" is found anywhere in the path name, it will not run.  Could not find main class is displayed.
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16873930
> If "src" is found anywhere in the path name, it will not run
I cant understand what is the correlation of src in path with running of jar ?
I is more likely something that is thrown by the application not by the java runtime
what is the exact phrase of the error message ?
0
 

Author Comment

by:tjwallace05
ID: 16874011
Java Virtual Machine Launcher

Could not find the main class.  Program will exit
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 500 total points
ID: 16874193
this is definitively a classpath issue
can you run the code this way: java -cp jxcodegui.jar JXCodeGuiMain
you should first go to the directory where jxcodegui.jar is located otherwise the full path to jxcodegui.jar is needed
(I assumed JXCodeGuiMain is not in a package)
0
 

Author Comment

by:tjwallace05
ID: 16874319
Thanks a lot.  That did it.
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

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

895 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

15 Experts available now in Live!

Get 1:1 Help Now