jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Executing my .java in package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing my .java in package" Watch "Executing my .java in package" New topic
Author

Executing my .java in package

jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
I have got 5 packages.

My Main class is present in a package named com.mainclass.
Other packages are name com.controller,com.business and so on.

Now my main class depends on all the 5 packages.

How can i execute the main class from command prompt ?
I dont know how to set the right path to execute the MainClass.

Can any one help me out?

thanks in advance.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
JavaRanch has a policy regarding names which can be found here. Since we try to have real or real-sounding names here, I am inclined to asked if Gohan Goku is indeed your real name, as I know Gohan and Goku are characters in a popular cartoon. If that is indeed your name that is fine, but I couldn't help but ask.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
You don't use the PATH for that at all.

try java mypackage.otherpackage.MyClass

when in the folder "outside" the mypackage folder.
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
"gohan goku" are indeed cartoon characters.

And I am using them for the past 5years in my username mail ID and everything.

It doesnt mean I try to post spam messages with a fake name. Sorry, if this has offended your policy.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

gohan goku wrote:

I just sent you another private message
Could you please check it out?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
My package structure is as follows.

MyProject
src
com.database
com.mybean
com.mybusiness
com.mycontroller
com.mypackage
com.myutil
com.userinterface

build
classes
jar


My main class is located in
com.mypackage
. I created this project in eclipse and it compiles fine.

I tried compiling from command prompt using C:\Documents and settings\MyProject> javac -d build\classes src\com\*.java

And I got the error as error: cannot read: src\com\*.java
1 error


I dont know what went wrong. Can any one help me resolve this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36520
    
  16
There is no such file as src/com/*.java You need another directory name in between.
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
I used javac -d build\classes src\com\mypackage\*.java src\com\mycontroller\*.java src\com\userinterface\*.java src
\com\mybean\*.java src\com\mybusiness\*.java src\com\myutil\*.java src\com\database\*.java
for compiling and it worked.

Then I used echo Main-Class: com.mypackage.MyClass>manifest

Then jar cvf build\jar\gohan.jar manifest -C build\classes . .

I got a jar file. When I used java -jar build\jar\gohan.jar I get the following error

Failed to load Main-Class manifest attribute from
build\jar\gohan.jar


Please help me out. I want a executable jar file.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19545
    
  16

You must tell the jar command to use manifest as its manifest file by using the -m flag as well. Try changing cvf into cvfm.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
Yes, I also went through this.

But when i use jar cfm build\jar\gohan.jar manifest -C build\classes ., I get the following error

java.io.IOException: invalid header field
at java.util.jar.Attributes.read(Attributes.java:393)
at java.util.jar.Manifest.read(Manifest.java:182)
at java.util.jar.Manifest.<init>(Manifest.java:52)
at sun.tools.jar.Main.run(Main.java:132)
at sun.tools.jar.Main.main(Main.java:1022)


How to resolve this?
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Read this.


Vinod Tiwari | Twitter
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
Thanks.....

I have created a jar file now and it executes. Now how to add oracle driver jar to my jar for Database connectivity?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19545
    
  16

Put the Oracle JAR file in a location relative to your JAR file, then add a Class-Path entry in your manifest. This entry should point to that JAR file using the relative path. For instance, if the Oracle JAR file is located in a folder called lib which in turn is located in the same folder as your JAR file:
Or if your JAR file and the Oracle JAR file are located in the same folder:
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

You might also want to evaulate one jar
jagan raja
Ranch Hand

Joined: Jan 29, 2010
Posts: 54
Thank you all.......

I finally created my jar file and converted it into a .bat file.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing my .java in package
 
Similar Threads
how to jar a package?
How to call class from different package?
packages from KB
how to work with packages?
making/calling a package