• Post Reply Bookmark Topic Watch Topic
  • New Topic

generating class file without using javac command  RSS feed

 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am new here, so please be patient.

Is there any program that converts the .java file into .class instead of using javac command ???
I've started studying EJB technology from the Head First EJB book. They suggest to work with basic tools without heavy Eclipse or similar programs....ok. That's fine with me, but...
I need to compile three .java files to generate jar file with deployment tool (included to J2EE SDK) . I need for that class files. Javac command always shows some errors but eclipse not! That code for java files I copied from the book, it seems ok(Eclipse doesn't show errors).

QUESTION:

Is there any small program who works like javac command and creates class files or do you know how to take out class file from eclipse or similar GUI ???

Thanks in advance

PS. The question is about javac command not EJB, that's way I didin't link it to EJB
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's Ant and Maven and other build tools and, as you've seen, IDEs, like Eclipse and IntelliJ. Those are all pretty much just calling javac for you though.

Your problem as I understand it is that you get compile errors when using javac, but not when using Eclipse. The most likely problem is your classpath. Eclipse helps you define dependencies and then sets up a classpath for you, but from the command line, you're on your own. Your book probably tells you how to set the classpath, or you could post some code here, along with the compile error you're getting, and we could give you some advice.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is a minimal IDE i used to used called BlueJ
i was going to get it again but the website said JDK only(no EE or Netbeans)
anyway if didn't get java with EE you might want to check it out. i liked it.
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:
Your problem as I understand it is that you get compile errors when using javac, but not when using Eclipse.


Yes, so I thought I may use different program to generate class file.
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Charles wrote:... or you could post some code here, along with the compile error you're getting, and we could give you some advice.


As requested below.

First file Advice.java, no errors with Eclipse
javac errors:

Flickr





 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
second file AdviceHome.java

errors from javac
Flickr


no erros from eclipse

 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
third file AdviceBean.java

javac errors:

Flickr





Like I said. The code is copied from the book.

I just need CTRL+C and paste generated class files into deployment tool, but I can't do it through javac command.
I thought to find path where Eclipse keeps class files generated from java files and simple copy it :/

 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are missing neccessary Java EE bundle which contains "import javax.ejb.*;", " java.rmi.RemoteException" and other EE components(or jars). So download JDK with EE bundle and set the path and then compile with Javac. Search with the keyword "java ee sdk" and the first link will give you the download page. Hope it will help you.
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be exact, you will get a new JDK with EE packages, change your classpath to this new folder and just Javac(Compile) your code and also it will help you in learning EJB slowly but clearly as you will avoid using heavy tools like Eclipse or NetBeans which will provide much assist(which is not recommended for a beginner). Thanks.
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthikeyan Nadanasabapathy wrote:You are missing neccessary Java EE bundle which contains "import javax.ejb.*;", " java.rmi.RemoteException" and other EE components(or jars). So download JDK with EE bundle and set the path and then compile with Javac. Search with the keyword "java ee sdk" and the first link will give you the download page. Hope it will help you.


I installed JDK with SDK yesterday. Here is a screen shot.
http://flic.kr/p/aUNbhr
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthikeyan Nadanasabapathy wrote:So download JDK with EE bundle and set the path


How do I set the path ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Baba wrote:
Karthikeyan Nadanasabapathy wrote:So download JDK with EE bundle and set the path


How do I set the path ?

Karthikeyan probably meant the classpath. If javac doesn't give you an error something like 'is not recognized as an internal or external command, operable program or batch file' then your path is already set correctly
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sample : set path="D:\SOFTWARE\bea\jdk160_05\bin"; "D:\SOFTWARE\bea\jdk160_05\bin" is my path of jdk, similarly you just go to the bin folder of Java EE 6 SDK in your system and copy the path and just set it. It should work since you are having the correct sdk. Thanks
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Neal, Andrew please check Neal's comment and verify it.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Baba wrote:Yes, so I thought I may use different program to generate class file.

I don't think that's a very good problem-solving approach, no?

If your car breaks, would you rather find out why it's broken and fix it properly, or would you fill it up with water instead of gas and hope it works? That's precisely why you shouldn't use an IDE when you start out programming - it hides a whole bunch of things that you should know about. You learn more through trial and error than using an IDE that does everything for you.
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to set up few JAVA_HOME classpaths. Everywhere when I might have correct files

C:\Program Files\Java\jdk1.7.0_01\bin
C:\Program Files\Java\jdk1.6.0_29\bin
C:\Program Files\JDK\bin

2 errors again in advice.java. I asked friend of mine who is advanced programmer and sitting just beside me, he couldn't help me either. He told everything looks ok.

Just to clarify:

I am changing JAVA_HOME variable, is it ? If yes it didn't work out.
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riaan Nel wrote:
it hides a whole bunch of things that you should know about. You learn more through trial and error than using an IDE that does everything for you.


precisely the point, you open the editor, code some lines, then compile and run it and you got the output for the very first attempt without facing any problem then it implies you haven't learn t anything. But now you are learning some key concepts like what is classpath, what are the jars/packages and what packages required for ejb and where they present, it may be frustrating at times but will get proper end results. Enjoy coding
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riaan Nel wrote:
Andrew Baba wrote:Yes, so I thought I may use different program to generate class file.

I don't think that's a very good problem-solving approach, no?

If your car breaks, would you rather find out why it's broken and fix it properly, or would you fill it up with water instead of gas and hope it works? That's precisely why you shouldn't use an IDE when you start out programming - it hides a whole bunch of things that you should know about. You learn more through trial and error than using an IDE that does everything for you.

I know what are you talking about. I want to focus on EJB currently, that is way I want to find shortcut. You guys are right, but I am still in the same point before I posted this topic...
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAVA_HOME variable is the correct one, so you are able to compile properly and produce 2 errors but the problem is with your jdk which doesn't have EE support or EE packages or try this simple thing, just copy your headfirst folder (which contains Advice.java,AdviceHome.java and AdviceBean.java) into the bin folder of your sdk and then visit the bin folder and compile "javac headfirst.*" using command prompt (don't set any classpath or don't go inside headfirst and compile just be in bin). If it contains the appropriate ejb jars then you will get the proper result or else you are not having the necessary jars for ejb coding.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthikeyan Nadanasabapathy wrote:try this simple thing, just copy your headfirst folder (which contains Advice.java,AdviceHome.java and AdviceBean.java) into the bin folder of your sdk

No. Never put source code into your JDK installation directory, even if it's just to demonstrate something. Learn what the classpath is and how to use it. It will be of much more benefit in the long term.

Karthikeyan Nadanasabapathy wrote:the bin folder and compile "javac headfirst.*" using command prompt (don't set any classpath or don't go inside headfirst and compile just be in bin). If it contains the appropriate ejb jars then you will get the proper result or else you are not having the necessary jars for ejb coding.

This is just wrong for two reasons.
1. The bin directory does not contain jar files.
2. Even if it did, they would still need to be specified on the classpath. The java compiler does not check jar files just because they are in the current directory or a directory that is on the classpath.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Baba wrote:I know what are you talking about. I want to focus on EJB currently, that is way I want to find shortcut. You guys are right, but I am still in the same point before I posted this topic...

1. Learn what the classpath is and how to use it. This is something every java programmer should now. It will be explained in any introductory java book or tutorial and has probably been explained numerous times on this site. A search will show you these previous posts.
2. Once you know what the classpath is, the reason for your errors will be obvious and the fix fairly easy. You will just need to find out which jar file(s) the missing classes are in.
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joanne

Any ideas how to solve it Joanne ?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Baba wrote:@Joanne

Any ideas how to solve it Joanne ?

I assume you posted that before you saw my second post ?
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I am trying right now to set up classpath with http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html. I have no other ideas so far
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Baba wrote:No. I am trying right now to set up classpath with http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/classpath.html. I have no other ideas so far

Okay. Have you chosen to use the CLASSPATH environment variable or the -cp/-classpath parameter ? The latter is recommended, but the first will be okay whilst you are learning. What value are you using for the classpath ?
 
Andrew Baba
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Joanne

Please have a look on the picture

command line screen shot


I am not it is all what you asked for.
I used -cp and -classpath
 
Karthikeyan Nadanasabapathy
Greenhorn
Posts: 11
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
copying files to bin idea was to check whether Andrew is working on the correct jdk. but agreed completely with neal, wasn't a good technique, will avoid in future.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Replace the < and > with " and leave a space after cp/classpath

And post your error messages/command lines in the forum. Don't use links to flickr. If you're not sure how to copy and paste from a command prompt, just google it and there are plenty of explanations.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!