Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing my .java in package

 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gohan goku wrote:

I just sent you another private message
Could you please check it out?
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such file as src/com/*.java You need another directory name in between.
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read this.
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might also want to evaulate one jar
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.......

I finally created my jar file and converted it into a .bat file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic