Compiling classes in different folders
big-time newby question...
I have a class compiled in a given folder. I am creating another class in a subfolder to do the test of the other class. When I compile the class in the subfolder, I get compile errors indicating the class is not found...
here is the folder hierarchy...
projects
.. phone (holds the Phone.class file)
.... phonetest (holds the PhoneTest.java file)
PhoneTest.java instantiates objects of class Phone but compiler cannot find the Phone class.
Q: how do I tell the compiler to look up one step in the tree?
(I know that I can make it compile by placing both .java files in the same folder)
all advice appreciated. Thx
Would you mind elaborating on the advantages you see
in keeping the source code separate from the compiled
code? I've read other posts from people who say
separate directories is the only way to go, but I've
never felt a need to or noticed any difficulties with
source and compiled in the same directory.
If you work on the command line which is what many people do, having Foo.class and Foo.java files in the same directory makes your work slightly slower and a bit more annoying because you cannot efficiently use the shell's automatic file name completion features.
Consider the class Foo is the only class the name of which starts with an F and you want to edit its source code. If the directory has both Foo.java and Foo.class, this is what you will need to type in minimum to edit the file:
vi F<tab>j<tab><enter>
(<tab> is commonly the key that invokes the shell's autocompletion) If the directory has got only source files you can edit it with:
vi F<tab><enter>
3 key strokes less is not much, especially compared to actually writing the source code, but makes the work maybe just a little bit more seamless.
Also, in my personal opinion it is "cleaner" to have the source code in one place and the binaries in another -- e.g the binaries directory can simply be removed if you want to recompile everything and be sure no old binary code is left.
Similar Messages
-
Need help using multiple classes in different folders.
Hey everyone.
Im trying to make a trading card game, in Java. Each card is going to be a class derived from a main card class (called card). The problem is that each card is going to be in a different folder based on the set and card number. (ex. card 001 from set 02 would be in "game/02/001/")
I found this is a real good way to organize the game since there will be new cards all the time and players wont have all of them. Is it posible to call classes from different folders, and if it is how do I do it?
-Thanks to anyone who answersThe problem is that each card is going to be in a different folder based on the set and card number.Why don't you simply add two attributes to your Card class:
cardNumber
setNumber
Or better, have a Set class with attribute:
number
and a Card class with two attributes:
number
set -
UNABLE TO USE COMPILED CLASSES STORED IN DIFFERENT FOLDERS
Can you help me out
i have a problem i have been creating various modules and the compiled classes files are stored in different folders and i want the module to access the compiles classes file from the respective folders can any one give me some idea how to get it working.
thankyouYou need to make the folders into packages. Say you have 2 folders, one with your core classes named "core", and one with your GUI classes named "gui". These folders are in a folder called "myprogram". You then put a statement at the top of each file in the "core" folder like this: package myprogram.core; Do the same with all the java files in the "gui" folder as well, but replace .core with .gui. Then, you import your own package the same way you do normal java packages: import myprogram.core.*;
I hope that makes sense, for more info here is the Java tutorial: http://java.sun.com/docs/books/tutorial/java/interpack/packages.html -
Unable to compil class for jsp
error is
HTTP Status 500 -
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Syntax error on token ".", Identifier expected after this token
An error occurred at line: 7 in the generated java file
Syntax error on token ".", Identifier expected after this token
An error occurred at line: 9 in the jsp file: /travel/issue.jsp
LibraryStudent cannot be resolved to a type
6: <BODY>
7: <H1>issue books</H1>
8: <CENTER>
9: <jsp:useBean id="student"
10: type="LibraryStudent"
11: scope="session" />
12: student name:
An error occurred at line: 9 in the jsp file: /travel/issue.jsp
LibraryStudent cannot be resolved to a type
6: <BODY>
7: <H1>issue books</H1>
8: <CENTER>
9: <jsp:useBean id="student"
10: type="LibraryStudent"
11: scope="session" />
12: student name:
An error occurred at line: 13 in the jsp file: /travel/issue.jsp
LibraryStudent cannot be resolved to a type
10: type="LibraryStudent"
11: scope="session" />
12: student name:
13: <jsp:getProperty name="student" property="studentName" />
14:
15: book name:
16: <jsp:getProperty name="student" property="bookName" />
An error occurred at line: 16 in the jsp file: /travel/issue.jsp
LibraryStudent cannot be resolved to a type
13: <jsp:getProperty name="student" property="studentName" />
14:
15: book name:
16: <jsp:getProperty name="student" property="bookName" />
17:
18: <jsp:getProperty name="student"
19: property="issueData" />
An error occurred at line: 18 in the jsp file: /travel/issue.jsp
LibraryStudent cannot be resolved to a type
15: book name:
16: <jsp:getProperty name="student" property="bookName" />
17:
18: <jsp:getProperty name="student"
19: property="issueData" />
20: </FORM>
21: </CENTER>LibraryStudent.java is
import java.util.*;
import java.text.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class LibraryStudent {
private String emailAddress, s,password, sname,bname;
private String date,value;
public String getStudentName() {
return(sname);
public void setStudentName(String sname) {
this.sname = sname;
public String getEmailAddress() {
return(emailAddress);
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
public String getPassword() {
return(password);
public void setPassword(String password) {
this.password = password;
public String getBookName() {
return(bname);
public void setBookName(String bname) {
this.bname = bname;
public String getDate() {
return(date);
public void setDate(String date) {
this.date = date;
public String getIssueData() //method that create connection withh database
throws ServletException,IOException{
try{
getDate(); //and add a entry in database
getBookName();
getStudentName();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:db2");
Statement st=con.createStatement();
String sql =
"insert into table1 (bookname,studentname,date) values(bname,sname,date)";
st.executeUpdate(sql);
System.out.println(sql);
String s= "your book has been issued ";
return(s);
catch(Exception e)
e.printStackTrace();
return "failed";
public String getSumbitData()
throws ServletException,IOException{
try
getBookName();
getStudentName();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:db2");
Statement st=con.createStatement();
String sql =
"delete from db2 where bookname='bname' and studentname=sname";
st.executeUpdate(sql);
System.out.println(sql);
String s="your book has been sumbitted ";
return(s) ;
catch(Exception e)
e.printStackTrace();
return "failed";
public static int findStudent //to validate customer
(String emailAddress,
String password) throws ServletException,IOException{
try
if (emailAddress == null) {
return(0);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:user");
Statement st=con.createStatement();
String sql="select * from user where name='"+emailAddress+"' and password='"+password+"'";
System.out.println(sql);
ResultSet rs=st.executeQuery(sql);
if(rs.next())
return(1);
else
return(0);
}catch(Exception e)
e.printStackTrace();
return (0);}
to be continued.............and Library.java is import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Library extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String emailAddress = request.getParameter("emailAddress");//use to email&pass
String password = request.getParameter("password");//from html page
LibraryStudent student = new LibraryStudent();//Make a student Object
int a=LibraryStudent.findStudent(emailAddress, password);//to validate student
if (a==0) {
gotoPage("/library/accounts.jsp", request, response);
else
student.setStudentName(request.getParameter("sname"));//use to sent other textbox
student.setBookName(request.getParameter("bname"));//data in librarystudent
student.setDate(request.getParameter("date"));//class after validation
HttpSession session = request.getSession(true);
session.putValue("student", student);
//for moving different page
if (request.getParameter("issue") != null) {
gotoPage("/travel/issue.jsp",
request, response);
} else if (request.getParameter("sumbit") != null) {
gotoPage("/travel/sumbit.jsp",
request, response);
} else if (request.getParameter("search") != null) {
gotoPage("/travel/search.jsp",
request, response);
} else if (request.getParameter("account") != null) {
gotoPage("/travel/EditAccounts.jsp",
request, response);
} else {
gotoPage("/travel/IllegalRequest.jsp",
request, response);
private void gotoPage(String address,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
} issue.jsp is
<%@page import="java.io.,java.util.,java.sql.*"%>
<HTML>
<HEAD>
<TITLE>issue books</TITLE>
</HEAD>
<BODY>
<H1>issue books</H1>
<CENTER>
<jsp:useBean id="student"
type="LibraryStudent"
scope="session" />
student name:
<jsp:getProperty name="student" property="studentName" />
book name:
<jsp:getProperty name="student" property="bookName" />
<jsp:getProperty name="student"
property="issueData" />
</FORM>
</CENTER>
</BODY>
</HTML> plz solve my problem .i m new to servlet and jsp and i have keen desire to learn this topic -
JasperException: Unable to compile class for JSP HELP
I added couple of extra class files into the jar file.. and now its not able to find it! I am running JBoss latest version and using eclipse... any help wud be nice
org.apache.jasper.JasperException: Unable to compile class for JSP
Generated servlet error:
Only a type can be imported. org.jfree.chart.servlet.WebHitChart resolves to a package
Generated servlet error:
Only a type can be imported. org.jfree.chart.servlet.WebHitDataSet resolves to a package
An error occurred at line: 10 in the jsp file: /bar_chart.jsp
Generated servlet error:
WebHitChart cannot be resolved
An error occurred at line: 10 in the jsp file: /bar_chart.jsp
Generated servlet error:
WebHitDataSet cannot be resolved
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)just a random guess...
I had a ton of issues with JBoss and jfreechart. JBoss uses a different classloader, and its internal versions of the jfreechart classes will be loaded before yours, causing all sorts of issues. Dig through the jboss directories and you'll find a different, older version of jfreechart of one of its classes. Remove them and you'll be in better shape.
Alternatively, look around the JBoss docs for how to disable/turn off the unified classloader for your app (its a directive in jboss-web.xml IIRC). This should make the classloader for your webapp perform to spec, getting rid of the class colission issues. -
Sample CLASSES for different types of OIM components!!!
Hi Experts
Can any one provide me sample classes for different types of OIM components, adapters, scheduled tasks, etc. with your best practices for OIM java development and documentation? It would Help me lot.
Please let us know Links/Documentations.
Thanks
\oim_userfor schedulers
1. Create a java class that extends the SchedulerBaseTask (see example below)
2. Write your business logic
3. Compile and jar
4. Place the jar in the ScheduleTask directory in your OIM install
5. Create a new scheduled task using the OIM developer console
6. link in the new class into your new scheduled task.
7. Done!
Example code for a scheduled task:
import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;
public class ScheduledtaskExample extends SchedulerBaseTask {
public void init()
//this method is run before execute by the scheduler
public void execute() {
//is executed by the scheduler
runMyBusinessLogic();
private void runMyBusinessLogic(){
//place your business logic here
} -
Possible to access classes in other folders without the use of packages?
Hi,
I'm trying to write a kind of connector application, and I have come across this stumbling block.
I have a folder for my main program classes, which will not change. External to that folder( either in a subdirectory or another directory on the same level) I want to have my classes to "connect". The connected classes will be compiled dynamically, as they depend on something in the main classes folder for complilation... I trust I can satisfy that using javac -classpath...
The problem is that I would like one of the main classes to be able to access the connected classes at runtime, from the other folder. The collection of connected classes will be changing, so that, coupled with the fact that one of the main classes will be required to compile each connected class seems to rule out the use of packages for the connected classes.
Is there a way to get around this?
Thank you,
JesseAre you trying to dynamically compile Java classes (in external folders
without packages) via Java? Yes, I will be (hopefully) using com.sun.tools.javac. I haven't done that part yet, as I don't want to waste my time on a design that is fundamentally flawed :)
Does each new 'application' get placed into its ownfolder? No. I will be building a collection of new apps that will all be contained in one folder.
Once an application is compiled, must it beimmediately available to the process that compiled
it? Yes. Once an application is compiled I need it to be accessable from that point on.
Thanks,
Jesse -
Unable to compile class for JSPNote
I am getting the following error when trying to run an application on an iSeries (AS/400) running Tomcat 4.0.4 and Java 1.3. The application runs fine on a different installation of Tomcat (same version) on the same box. I am currently looking for differences between the two Tomcat installations but was wondering if any one had any ideas as to the problem.
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
error: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
1 error, 1 warning
java/lang/Throwable.(Ljava/lang/String;)V+4 (Throwable.java:85)
java/lang/Exception.(Ljava/lang/String;)V+1 (Exception.java:33)
org/apache/jasper/compiler/Compiler.compile()Z+667 (Compiler.java:285)
org/apache/jasper/servlet/JspServlet.loadJSP(Ljava/lang/String;Ljava/lang/String;ZLjavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Z+304 (JspServlet.java:548)
org/apache/jasper/servlet/JspServlet$JspServletWrapper.loadIfNecessary(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+96 (JspServlet.java:176)
org/apache/jasper/servlet/JspServlet$JspServletWrapper.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Z)V+1 (JspServlet.java:188)
org/apache/jasper/servlet/JspServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V+318 (JspServlet.java:473)
javax/servlet/http/HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+26 (HttpServlet.java:853)
org/apache/catalina/core/ApplicationFilterChain.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)V+95 (ApplicationFilterChain.java:193)
org/apache/catalina/core/StandardWrapperValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+346 (StandardWrapperValve.java:243)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+84 (StandardPipeline.java:566)
org/apache/catalina/core/StandardPipeline.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+15 (StandardPipeline.java:472)
org/apache/catalina/core/ContainerBase.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+4 (ContainerBase.java:943)
org/apache/catalina/core/StandardContextValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+200 (StandardContextValve.java:190)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+84 (StandardPipeline.java:566)
org/apache/catalina/valves/CertificatesValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+45 (CertificatesValve.java:246)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+52 (StandardPipeline.java:564)
org/apache/catalina/core/StandardPipeline.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+15 (StandardPipeline.java:472)
org/apache/catalina/core/StandardContext.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+23 (StandardContext.java:2347)
org/apache/catalina/core/StandardHostValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+167 (StandardHostValve.java:180)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+84 (StandardPipeline.java:566)
org/apache/catalina/valves/ErrorDispatcherValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+1 (ErrorDispatcherValve.java:170)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+52 (StandardPipeline.java:564)
org/apache/catalina/valves/ErrorReportValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+1 (ErrorReportValve.java:170)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+52 (StandardPipeline.java:564)
org/apache/catalina/valves/AccessLogValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+1 (AccessLogValve.java:468)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+52 (StandardPipeline.java:564)
org/apache/catalina/core/StandardPipeline.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+15 (StandardPipeline.java:472)
org/apache/catalina/core/ContainerBase.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+4 (ContainerBase.java:943)
org/apache/catalina/core/StandardEngineValve.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;Lorg/apache/catalina/ValveContext;)V+156 (StandardEngineValve.java:174)
org/apache/catalina/core/StandardPipeline.invokeNext(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+84 (StandardPipeline.java:566)
org/apache/catalina/core/StandardPipeline.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+15 (StandardPipeline.java:472)
org/apache/catalina/core/ContainerBase.invoke(Lorg/apache/catalina/Request;Lorg/apache/catalina/Response;)V+4 (ContainerBase.java:943)
org/apache/ajp/tomcat4/Ajp13Processor.run()V+44 (Ajp13Processor.java:551)
java/lang/Thread.run()V+11 (Thread.java:479)I think that you have not set your Java Home correctly. Correctly specify the Java Home in the config and the startup scripts.
-
EJB was compiled by a different version of the Weblogic Server
I got the following error message when attempt to startup weblogic server to deploy my ejb.
<The EJB deployment named: ejb_test was compiled by a different version of the WebLogic Server.>
<... cannot be redeployed while the server is running ...>
Anybody has any clue about this? TIA.
Cheers. KokHwa.See inline:
KokHwa wrote:
I got the following error message when attempt to startup weblogic server to deploy my ejb.
<The EJB deployment named: ejb_test was compiled by a different version of the WebLogic Server.>
Exactly what is says. You are deploying an EJB that was compiled with a
different Weblogic version (might be a different SP or a previous
version) that the one you are deploying on. Recompile with the same
version as the deployment and it should be fixed.
<... cannot be redeployed while the server is running ...>
This message is the same. Because you have some of the classes of the EJB
in your server classpath you will not be able to redeploy that EJB but apart
from that it's harmless. To redeploy after changing the EJB you'll have to
restart the server.
>
Anybody has any clue about this? TIA.
Cheers. KokHwa.
--dejan -
Presets in different folders MUST have unique name? WHY?
You cannot have the same name on a preset, even though they reside in separate folders. At the filesystem level they are in different directories.
OS file systems allow you to have the same file name as long as it is NOT in the same folder.
To get around this, you must make each preset name different by one char, even though they are in different folders both in LR and on the OS FS.
Why is this important to me?
When shooting youth baseball, I would like to have five different folders of presets that represent a certain time of the day, as great preset for noon does not work for a picture take at 5pm in the evening..
So 5 folders, 9a-12p, 12p-3p, 3p-5p, so on..
Each folder would have 10-15 presets for quick develop settings based on where on the field I am shooting.
Open up a game shot in the morning, open the preset folder of 9a-12p, the presets are the same name, but adjusted for the time of the day..
.*Sigh*.
Mac Pro 2.66, OS 10.4.10, LR 1.1In Lion and Mountain Lion the Home/Library folder is now invisible. To make it permanently visible enter the following in the Terminal application window: chflags nohidden ~/Library and hit the Enter button - 10.7: Un-hide the User Library folder.
To open your domain file in Lion or Mountain Lion or to switch between multiple domain files Cyclosaurus has provided us with the following script that you can make into an Applescript application with Script Editor. Open Script Editor, copy and paste the script below into Script Editor's window and save as an application.
do shell script "/usr/bin/defaults write com.apple.iWeb iWebDefaultsDocumentPath -boolean no"delay 1
tell application "iWeb" to activate
You can download an already compiled version with this link: iWeb Switch Domain.
Just launch the application, find and select the domain file in your Home/Library/Application Support/iWeb folder that you want to open and it will open with iWeb. It modifies the iWeb preference file each time it's launched so one can switch between domain files.
WARNING: iWeb Switch Domain will overwrite an existing Domain.sites2 file if you select to create a new domain in the same folder. So rename your domain files once they've been created to something other than the default name.
OT -
When I import a CD into my iTunes, if there are songs by multiple artists they appear in different folders. Can I prevent this from happening or can I fix it afterwards?
Steve MacGuire aka turingtest2 - iTunes & iPod Hints & Tips - Grouping Tracks Into Albums - http://www.samsoft.org.uk/iTunes/grouping.asp (older post on Apple Discussions http://discussions.apple.com/message/9910895)
Quick answer: Select all the tracks on the album, File > get info, and either give them all a single "album artist", or check the "compilation" flag (as in https://discussions.apple.com/message/17670085).
If these are from multiple-CD sets you may also need to enter the appropriate information in the disc number fields. -
When I put some new CD in my computer iTunes record it in different folders
Sometimes when I put some new CD in my computer iTunes record it in different folders instead of placing all the songs in one folders. It does that when songs are writen by diffrent people even if it's not a compilation. It happens to old albums or brand new that I just got the shrinkwrap out.
After that, seeming to be random, he sometimes forget where some songs are and I have to guess where he could have put it, it can record an album in 5 different folders on my hard disk. Is there a way to keep all the songs of the album together? This seems to be a major flaw from my point of view.Generally all you need to do is fill in an appropriate Album Artist. For more details see my article on Grouping Tracks Into Albums, in particular the topic One album, too many covers.
tt2 -
Compiled classes caching constant values?
I have a question about switching the version of a library at runtime. Specifically, if I compile a class against a particular version of a library, then use a different version at runtime, what behaviour should I expect? What I'm seeing is very unintuitive, and I'm hoping someone can shed some light.
I have a class which defines constant values:
public class LibraryClass {
public static final String CONST_STRING = "11111";
public static final Integer CONST_INTEGER = new Integer(11111);
public static final int CONST_INT = 11111;
}Let's say I compile this class and package it in a jar called library.jar.
Then I create another class that uses this library:
public class MyTest {
public static void main(String[] args) throws Exception {
System.out.println(LibraryClass.CONST_STRING);
System.out.println(LibraryClass.CONST_INTEGER);
System.out.println(LibraryClass.CONST_INT);
}With library.jar in the classpath, I compile MyTest.java and then run it, and I see what I would expect:
11111
11111
11111Then I create a second version of my library, with different values:
public class LibraryClass {
public static final String CONST_STRING = "22222";
public static final Integer CONST_INTEGER = new Integer(22222);
public static final int CONST_INT = 22222;
}I compile this new class and package it in library2.jar.
Now, without recompiling MyTest, I run MyTest with library2.jar in the classpath, and get the output:
11111
22222
11111The String and int values seem to be cached in the compiled class (MyTest), which I find strange. When I add accessor methods to LibraryClass and call these from MyTest, it works as I would expect - i.e. it always prints the values from the version of the library included at runtime, regardless of the version used at compile time.
It seems like these values are stored in the binary class file of MyTest - why is this? And why does the Integer value work correctly when the others don't?
Thanks,
Stevestevej wrote:
jschell wrote:
Because that is an expresson not a constant.
You can make the other two work the same with the following code (pseudo)
public static final String CONST_STRING = "11111".toString();
public static final int CONST_INT = new Integer(11111).intValue();Hmm it works... So it depends how the constants are defined? I don't see why the compiler would make the distinction... well I do sort of. But since the constants I'm working with are defined in a 3rd party library I can't change the way they are defined anyway.They are expressions. They are not set until the code runs.
The original way they are literals. The compiler knows they are literals so it can optimize for it. -
Unable to compile class for JSP
Please can anyone help me to solve this.
Actually,this is the condition.
In my db,there is a table called UserPassword, which has 4
fields(empNo,UserName,password,level). Now I want to do these things:
When the user submits the data to create a new account via HTML form, it submits the data to the file called CreateAcc.jsp. In this file it perform some logic,here are they.
1)To check the empNo,if it is already exist in the DB,
if empNo =exist then display error.(record already exist)
if empNo =notexist then do task 2).
2)check the UserName,if it is already exist in the db,
if UserName=exist then display error.(because it's a primary key)
if UserName=notexist then do task 3).
3)Create a new user account and save it to the db.
To do these tasks,I never create a new objects for the tasks 1) and 2).
only for task 3)create an object.
Is it the right way?
Here is the file CreateAcc.jsp
<%@ page language="java" %>
<%@ page import="core.UserAccManager" %>
<%@ page import="data.UserPassword" %>
<jsp:useBean id="UserAccManager" class="core.UserAccManager" scope="session"/>
<jsp:setProperty name="UserAccManager" property="*"/>
<jsp:useBean id="UserPassword" class="data.UserPassword" scope="session"/>
<jsp:setProperty name="UserPassword" property="*"/>
<%
String nextPage ="MainForm.jsp";
if(UserPassword.verifyEmpno()){
if(UserPassword.verifyUsername()){
if(UserPassword.createAcc()) nextPage ="MsgAcc.jsp";
}else{
nextPage="UserNameExist.jsp";
else{
nextPage="UserAccError.jsp";
%>
<jsp:forward page="<%=nextPage%>"/>The directory structure:
UserPassword.java- F:/Project/core/data/UserPassword.java
UserAccManager.java - F:/Project/core/UserAccManager.java
Now both are compiling.I put the class files into the TOMCAT,as follows.
UserAccManager.class - webapps/mySystemName/WEB-INF/classes/core/
UserPassword.class - webapps/mySystemName/WEB-INF/classes/core/data/
Here is the full code of the file UserAccManager.java.
package core; //Is this right?
import data.UserPassword; //Is this right?
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public final class UserAccManager{
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/superfine";
private static Connection connection;
private static PreparedStatement pstmt1;
private static PreparedStatement pstmt2;
private static PreparedStatement pstmt3;
private UserAccManager(){
// Initializes the connection and statements
public static void initConnection() {
if (connection == null) {
try {
String sql;
// Open the database
Class.forName(DRIVER).newInstance();
connection = DriverManager.getConnection(URL);
// Prepare the statements
sql = "SELECT * FROM UserPassword where empNo= ?";
pstmt1 = connection.prepareStatement(sql);
sql = "SELECT UserName FROM UserPassword where UserName= ?";
pstmt2 = connection.prepareStatement(sql);
sql ="INSERT INTO UserPassword VALUES(?,?,?,?)";
pstmt3 = connection.prepareStatement(sql);
catch (Exception ex) {
System.err.println(ex.getMessage());
// Closes the connection and statements
// Method to be called by main class when finished with DB
public void closeConnection() {
//same as previous
public static boolean verifyEmpno(int empno) {
boolean emp_no_select_ok = false;
int emp = -1;
initConnection();
try {
pstmt1.setInt(1, empno);
ResultSet rs1 = pstmt1.executeQuery();
while(rs1.next()){
emp=rs1.getInt("empNo");
if(emp>0)
emp_no_select_ok = false;
} else{
emp_no_select_ok = true;
rs1.close();
pstmt1.close();
catch (Exception ex) {
System.err.println(ex.getMessage());
return emp_no_select_ok;
public static boolean verifyUsername(String username) {
boolean user_name_select_ok = false;
String user = "xxxx";
initConnection();
try {
pstmt2.setString(1, username);
ResultSet rs2 = pstmt2.executeQuery();
while(rs2.next()){
user=rs2.getString("UserName");
if(!user.equals("xxxx"))
user_name_select_ok = false;
} else{
user_name_select_ok = true;
rs2.close();
catch (Exception ex) {
System.err.println(ex.getMessage());
return user_name_select_ok;
public static boolean createAcc(int empno, String username, String password, int
level){
boolean create_acc_ok = false;
initConnection();
try{
//create a new object,from the UserPassword table.
UserPassword useraccount = new UserPassword();
useraccount.setEmpno(empno);
useraccount.setUsername(username);
useraccount.setPassword(password);
useraccount.setLevel(level);
//assign value for ???
pstmt3.setInt(1, useraccount.getEmpno());
pstmt3.setString(2, useraccount.getUsername());
pstmt3.setString(3, useraccount.getPassword());
pstmt3.setInt(4, useraccount.getLevel());
if(pstmt3.executeUpdate()==1) create_acc_ok=true;
pstmt3.close();
//con.close();
catch(SQLException e2){
System.err.println(e2.getMessage());
return create_acc_ok;
}here is the bean (part of it)
package data; //is it right?
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UserPassword
private int empno;
private String username;
private String password;
private int level;
// Constructor
public UserPassword()
this.empno = empno;
this.username = username;
this.password = password;
this.level = level;
// setters and getters are here.
// public boolean verifyEmpno() {
// return UserAccManager.verifyEmpno(empno);
// public boolean verifyUsername(String username) {
// return UserAccManager.verifyUsername(username);
// These 2 methods not compile with or without para's.So I leave that job for the
//controll class UserAccManager.java.
Now my problem is this: When I submit data, there is an error;org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:8:
cannot access core.data.UserPassword
bad class file: C:\Program Files\Apache Group\Tomcat
4.1\webapps\HRM\WEB-INF\classes\core\data\UserPassword.class
class file contains wrong class: data.UserPassword
Please remove or make sure it appears in the correct subdirectory of the classpath.
import core.data.UserPassword;
^
1 error
Are there any mistakes? If so tell me where is it and how to change them.Please help.I try it that way, but it don't compile.
Error:core\data\UserPassword.java:package javax.servlet does not exist
import javax.servlet.*;
core\data\UserPassword.java:package javax.servlet.http does not exist
import javax.servlet.http.*;
So,I comment them only in the UserPassword.java file,and compile it again.
Then it compile well.I goto the directory to get the .class files.
But there is only UserPassword.class inside the data folder. There is not
UserAccManager.class in the core folder.
Then I try this way,I put my 2 java files in to a new folder,
F:\SystemName\com
When I try it that way, but it don't compile.
javac -classpath . -d . com\*.javaError:com\UserPassword.java:package javax.servlet does not exist
import javax.servlet.*;
com\UserPassword.java:package javax.servlet.http does not exist
import javax.servlet.http.*;
So,I comment them only in the UserPassword.java file,and compile it again.
Now both are compiling well.There was 2 class files.
I put them in to the WEB-INF/classes/com directory.
Start the server.But it gave errors:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:68: cannot resolve symbol
symbol : variable empno
location: class org.apache.jsp.CreateAcc_jsp
if(UserPassword.verifyEmpno(empno)){
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:69: cannot resolve symbol
symbol : variable username
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.verifyUsername(username)){
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:69: non-static method
verifyUsername(java.lang.String) cannot be referenced from a static context
if(UserAccManager.verifyUsername(username)){
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable empno
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable username
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable password
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable level
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: non-static method
createAcc(int,java.lang.String,java.lang.String,int) cannot be referenced from a static
context
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
8 errorsTo solve the problem non-static method,I goto the UserAccManager.java file and do these
things.
package com;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
//import javax.servlet.*; //otherwise it tells an error.(package
//javax.servlet does not exist)
//import javax.servlet.http.*;
public class UserAccManager {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost:3306/superfine";
private static Connection connection;
private static PreparedStatement pstmt1;
private static PreparedStatement pstmt2;
private static PreparedStatement pstmt3;
private UserAccManager() {
// Initializes the connection and statements
private static void initConnection() {
//same
// Closes the connection and statements
// Method to be called by main class when finished with DB
public static void closeConnection() {
//same
public static boolean verifyEmpno(int empno) {
// same.
public static boolean verifyUsername(String username) {
//same.
public static boolean createAcc(int empno, String username, String password, int
level){
//same
package com;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
//import javax.servlet.*;
//import javax.servlet.http.*;
public class UserPassword {
// same
Again compile those files and put .class filses into the WEB-INF/classes/com directory.
When i submits the data via the form it generates an error:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:68: cannot resolve symbol
symbol : variable empno
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.verifyEmpno(empno)){
^
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:69: cannot resolve symbol
symbol : variable username
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.verifyUsername(username)){
^
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable empno
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable username
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable password
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
An error occurred at line: 9 in the jsp file: /CreateAcc.jsp
Generated servlet error:
C:\Program Files\Apache Group\Tomcat
4.1\work\Standalone\localhost\HRM\CreateAcc_jsp.java:70: cannot resolve symbol
symbol : variable level
location: class org.apache.jsp.CreateAcc_jsp
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
^
6 errorshere is the CreateAcc.jsp file
<%@ page language="java" %>
<%@ page import="com.UserAccManager" %>
<%@ page import="com.UserPassword" %>
<jsp:useBean id="userPassword" class="com.UserPassword" scope="request"/>
<jsp:setProperty name="userPassword" property="*" />
<%
String nextPage ="MainForm.jsp";
if(UserAccManager.verifyEmpno(empno)){
if(UserAccManager.verifyUsername(username)){
if(UserAccManager.createAcc(empno, username,password,level)) nextPage
="MsgAcc.jsp";
}else{
nextPage="UserNameExist.jsp";
else{
nextPage="UserAccError.jsp";
%>
<jsp:forward page="<%=nextPage%>"/>Please, anyone know how to send these parameters to the java file.
Thanks. -
HOW CAN I TRANSFER PHOTOS FROM MY IPOD TOUCH TO MY PC BUT THESE PHOTOS ARE NOT IN THE SAVED POTHOS FOLDER. THEY ARE IN SEPARATE AND DIFFERENT FOLDERS THAT MY DAUGTHER SAVED FROM HER PC. IS THERE ANY FREE WAY TO DO IT. PLEASE REPLY TO JUMACAVA07@HOTMAIL.
THANKSIf you need to Transfer photos from iPod to PC,I have a method for your reference,I suggest you use iStonsoft iPod to Mac Transfer software to copy photos from iPod to Mac,a professional software,Not only can you quickly Copy pictures from iPod to Computer,but also can save a lot of trouble and time
[B]Follow these steps to Transfer photos from iPod to Mac[/B]
Step 1. Download and run the iStonsoft iPod to Mac Transfer software on your Mac computer
Step 2. Connect iPhone with Mac
Step 3. Hit "Photos" to scan photos from iPod to Mac
Step 4. Click "Photos" button to transfer photos from iPod to Mac
Step 5. Wait a while,you will success Transfer these photos from iPod to Mac
How to Transfer/Copy Photos/Pictures from iPod to Mac computer
Maybe you are looking for
-
Pictures and Music on SD is not showing in Music or Pictures applications
I just transferred my 32GB microSD from my 9900 to my Z30, non of my existing music or pictures are showing up in respective apps. They are available through file browser app in BB10, but do not show up in player apps. Also when I put the SD card in,
-
Podcasts show up as on ipad, but won't open on ipad
When I sync my ipad, my podcasts show up in my library, and on the computer as being on the ipad, however when I go to the ipad, the icons are there, but when I tap them, they won't open.
-
Security Inheritance breaking in nested folder does not work
I have a scenario where I have to break the inheritance twice within the document library folders. I appreciate if you provide me any suggestions on how to achieve this? Document library contains "employee folder1", "employee folder2", "employee fold
-
Help me please))
-
SIDs are written in a Fact Table?
Hi, Some experts told me that SIDs are written in a fact table in extended star schema model . I am not able to understand how SIDs can be written in a fact table. As per my understing fact table contains only keyfigure and Dimids ( foreign key). Ple