Solved

Jar File Error: Could not find main class.

Posted on 2006-06-09
10
236 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
Industry Leaders: 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!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

685 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