Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jar File Error: Could not find main class.

Posted on 2006-06-09
10
Medium Priority
?
245 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
[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
  • 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

688 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