IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Compiling and running files in a package

Go down

Compiling and running files in a package Empty Compiling and running files in a package

Post by BIT0122-Amit 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
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Back to top

- Similar topics

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