-
Need help compiling .java -> .class file
Hello,
I'm an experienced asp/php programmer with only some java experience. I need to change a line of code from a Java programmer who is not longer with our agency. I edited what I need to do in the .java file, however when I attempt to compile it, here is what happens:
Code:
C:\SUN\APPSER~1\JDK\BIN>javac C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\Qu
estionMover.java
I get this error:
Code:
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:17: cannot fi
nd symbol
symbol : class QuestionMoverProgressDialog
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
private QuestionMoverProgressDialog dlg;
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:48: cannot fi
nd symbol
symbol : class SessionFrame
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
public void execute(Connection con, SessionFrame sf ) throws Exception {
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:139: cannot f
ind symbol
symbol : class SimpleQuestion
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
public void getCurrentQuestions(Connection con, SimpleQuestion[] questio
ns, Map questionMap) throws SQLException {
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:49: cannot fi
nd symbol
symbol : class SimpleQuestion
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
SimpleQuestion[] questions = sf.getSelectedQuestions();
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:50: cannot fi
nd symbol
symbol : class QuestionMoveDetailDialog
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
QuestionMoveDetailDialog detailDlg = new QuestionMoveDetailDialo
g( con, questions.length );
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:50: cannot fi
nd symbol
symbol : class QuestionMoveDetailDialog
location: class us.mn.state.mhfa.mf.ss.question.mover.QuestionMover
QuestionMoveDetailDialog detailDlg = new QuestionMoveDetailDialo
g( con, questions.length );
^
C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:56: cannot fi
nd symbol
symbol: class QuestionMoverProgressDialog
dlg = new QuestionMoverProgressDialog();
^
Note: C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java uses un
checked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
7 errors
Anyone care to take a stab at what I need to do to compile this into a .class file? Do I need to post some of the contents of the .java first?
All help is appreciated.
-
It looks like the java file is out of scope. I know this seems strange, but you need to be in the correct directory to compile the java file.
1. Check to see if there is a package declaration at the beginning of your java file, e.g.
Code:
package question.mover;
If so you need to cd to the parent folder of 'question', in this example, 'ss'. If there is no package declaration, cd to the 'mover' folder.
2. If your java file is in a package (e.g. question.mover, you are in folder ss) you compile with:
Code:
javac question.mover.QuestionMover.java
If not (in which case you are in the mover folder), just use
Code:
javac QuestionMover.java
If you get an error saying javac cannot be found, you will need to add the path to javac to the PATH environment variable.
Kind regards,
Noel
Efficiency is intelligent laziness
-
Thanks for the reply noelob. Here is how the package is declared in the java file:
Code:
package us.mn.state.mhfa.mf.ss.question.mover;
The complete directory that I'm working in is as follows: C:\qm\src\us\mn\state\mhfa\mf\ss\question\mover
So, following your advice, I tried compiling QuestionMover.java from the "src" directory... when I followed your advice and typed this:
Code:
javac us.mn.state.mhfa.mf.ss.question.mover.QuestionMover.java
I got this error:
Code:
error: cannot read: us.mn.state.mhfa.mf.ss.question.mover.QuestionMover.java
And when I use slashes instead of periods:
Code:
javac us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java
Here is the response I get:
Code:
.\us\mn\state\mhfa\mf\ss\question\mover\QuestionMoverProgressDialog.java:11: pac
kage us.mn.state.mhfa.app does not exist
import us.mn.state.mhfa.app.*;
^
.\us\mn\state\mhfa\mf\ss\question\mover\QuestionMoverProgressDialog.java:12: pac
kage us.mn.state.mhfa.gui does not exist
import us.mn.state.mhfa.gui.*;
^
.\us\mn\state\mhfa\mf\ss\question\mover\SessionFrame.java:10: package us.mn.stat
e.mhfa.db does not exist
import us.mn.state.mhfa.db.*;
^
.\us\mn\state\mhfa\mf\ss\question\mover\SessionFrame.java:11: package us.mn.stat
e.mhfa.gui does not exist
import us.mn.state.mhfa.gui.*;
^
.\us\mn\state\mhfa\mf\ss\question\mover\SessionFrame.java:12: package us.mn.stat
e.mhfa.app does not exist
import us.mn.state.mhfa.app.*;
^
us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:139: cannot access us.m
n.state.mhfa.mf.ss.question.mover.SimpleQuestion
bad class file: .\us\mn\state\mhfa\mf\ss\question\mover\SimpleQuestion.java
file does not contain class us.mn.state.mhfa.mf.ss.question.mover.SimpleQuestion
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public void getCurrentQuestions(Connection con, SimpleQuestion[] questio
ns, Map questionMap) throws SQLException {
^
6 errors
I believe you have sent me in the right direction, however, because the mhfa.gui/app/db folders don't even exist right now. At this point I'll have to extract some old .jar files to try and find these directories correct? Do you see anything else that I might need to go after right away
Thanks for your help on this.
-
I made it down to only one compile error:
Code:
C:\QM\SRC>javac us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java
us\mn\state\mhfa\mf\ss\question\mover\QuestionMover.java:139: cannot access us.m
n.state.mhfa.mf.ss.question.mover.SimpleQuestion
bad class file: .\us\mn\state\mhfa\mf\ss\question\mover\SimpleQuestion.java
file does not contain class us.mn.state.mhfa.mf.ss.question.mover.SimpleQuestion
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public void getCurrentQuestions(Connection con, SimpleQuestion[] questio
ns, Map questionMap) throws SQLException {
^
1 error
Also, this is the package at the top of the header in SimpleQuestion.java:
Code:
package us.mn.state.mhfa.mf.ss.question;
Any idea what I need to do hear? Thanks in advance!
-
Yay - I figured it out, all my .class files are created.
Now that my .class files are created, I need to put them all in a .jar archive - and there are many directories that these .class files are located in; is there some sort of windows-based .jar creator that I can just drag/drop .class files, rather than figuring how how to create the .jar file with the "jar c" command? I'm thinking that, due to the mulitple directories and all the files that will be in the .jar, it would be easier to just click-and-add or drag and drop, something with a GUI. Anythign like that exist?
-
Is your collection of code an application (one of the classes will have a 'public static void main(String args[])' function) ? In this case you will need to create a manifest file, which is a simple text file which is put into the jar file and tells the JVM which class is the entry point of the application. Assuming your code is an application, follow the following steps:
1. Go to the folder which you compiled the code from (i think you said it was C:\QM\SRC). Create a new text file there and name it manifest.txt (the name isnt important) and put the following info into it. Make sure you leave a blank line at the end:
Code:
Manifest-Version: 1.0
Created-By: YourNameHere
Main-Class: MyPackage.MyClass
Substitute MyPackage.MyClass for the fully qualified package name for class containing the main method (e.g. if it were QuestionMover then use us.mn.state.mhfa.mf.ss.question.mover.QuestionMover Note that there is no .java extension) Also, according to the Sun's tutorial, the manifest file needs to be in Unicode (UTF-8)
2. Open a DOS prompt and cd to the folder containing the manifest file (which is aslo the location from which you compiled everything). Run the following command:
Code:
jar cvfm MyJarName.jar manifest.txt *.class
This should leave you with a jar file in the current directory which contains you're application. To run it all you need to do is double click it. I cant remember if my syntax for the jar command is correct and I cant test it as I'm in work and dont have access to java. Try it and see and let me know if it works.
Kind regards,
Noel
PS. If you want to explore Jar file creation, Sun's tutorial on java is a good spot;
http://java.sun.com/docs/books/tutor...jar/index.html
Efficiency is intelligent laziness
-
I created the manifest.txt file for signing, and I tried the the jar file command as you advised, and here is the response I get:
Code:
C:\QM\SRC>jar cvfm QuestionMover.jar manifest.txt *.class
*.class: no such file or directory
Noelob- You have been a huge help so far, I really appreciate it.
I will read a bit more into the .jar file creation.
-
try
Code:
jar cvfm MyJarName.jar manifest.txt us/
I could figure it out if I had java on my work pc, but unfortunately I dont!
kind regards,
Noel
Efficiency is intelligent laziness
-
Thanks! I got everything working the way it's supposed to. Well, not like it's supposed to, but at least now I know how to edit the code -> compile to class files -> archive to .jar file and then run via the jnlp file.
You've been a huge help to me, I really appreciate it. I might be parusing these forums quite a bit, as it seems I'll be doing more Java work in the near future.
Thanks again for your help.
Similar Threads
-
By jase_dukerider in forum C++
Replies: 2
Last Post: 04-14-2005, 07:48 PM
-
By Yuri in forum VB Classic
Replies: 12
Last Post: 05-18-2001, 04:05 AM
-
By Andrew McLellan in forum Java
Replies: 3
Last Post: 05-09-2001, 05:34 PM
-
Replies: 1
Last Post: 03-17-2001, 07:33 PM
-
Replies: 2
Last Post: 01-03-2001, 10:40 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks