Compiling and running files in a package

View previous topic View next topic 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.
So..

I decided to compile it using javac command.
Code:
javac MyJava.java
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.

Code:
javac -d . MyJava.java

Notice the . after -d

if the Myjava.java 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:
Code:
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|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

View previous topic View next topic Back to top


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