Compiling and running files in a package

Go down

Compiling and running files in a package

Post by BIT0122-Amit on Sun Apr 11, 2010 2:45 am

Story(Skip this part and continue to main part if you have a short time):

Today I wrote a program in Java that takes String arguments in main method.
Big deal.
And I was successful executing it using eclipse as well.

However, I faced a new problem now. Neutral I don't know how to give runtime arguments in main method using eclipse.

I decided to compile it using javac command.
But wait, the file included package description.
And it was sending me errors saying that it can't find main method when I tried
java MyJava

Main Part

Actually, you have to insert package description in Javac command like this.

javac -d .

Notice the . after -d

if the has package ios; at its starting, the MyJava.class file will be created in ios folder.
Now you have to execute the class file like this:
java ios/MyJava

and voila Very Happy You have learnt how to execute java file using package!! Very Happy

Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile

Back to top Go down

Back to top

Permissions in this forum:
You cannot reply to topics in this forum