Solved

Jar File Error: Could not find main class.

Posted on 2006-06-09
10
234 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
Java Jpanels and Jframe 8 33
Basic Java Case or If-Else statement... 3 50
servlet example 11 40
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 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