Saving a key in a class file

Hi
i have an app that creates a key, needs to store it and read in again later on. I know how to save the key to file using the ObjectOutputStream and how to read in the key again from file.
For security reasons i now want to store the Key in a class file (create a class file where the key is placed in as a String or something like that and than compile it [and obfuscate it}) instead of saving it to a file (because in a file everybody is able to read the key). How can i do that? I thought of a kind of "Wrapper Class" but i don't get the starting point how to do it.
Can please somebody show me how this is done?
Thanks a lot for your help.

try {
               FileOutputStream fo = new FileOutputStream(f);
               ObjectOutputStream so = new ObjectOutputStream(fo);
               so.writeObject(key);
               so.flush();
          catch (IOException e) {
               System.out.println("Serialization IOException: " + e.getMessage());
               e.printStackTrace();
          catch (Exception e) {
               System.out.println("Serialization Exception: " + e.getMessage());
               e.printStackTrace();
          }the keys themselves are serializable so you can use code like this o write the key to a file. You can use FileInputStream to read the object back into your program.

Similar Messages

  • How do I make a batch file if the .class file uses a foreign package?

    I am trying to make an MS-DOS batch file using the bytecode file from the Java source file, called AddFields.java. This program uses the package BreezySwing; which is not standard with the JDK. I had to download it seperately. I will come back to this batch file later.
    But first, in order to prove the concept, I created a Java file called Soap.java in JCreator. It is a very simple GUI program that uses the javax.swing package; which does come with the JDK. The JDK is currently stored in the following directory: C:\Program Files\Java\jdk1.6.0_07. I have the PATH environment variable set to the 'bin' folder of the JDK. I believe that it is important that this variable stay this way because C:\Program Files\Java\jdk1.6.0_07\bin is where the file 'java.exe' and 'javac.exe' are stored. Here is my batch file so far for Soap:
    @echo off
    cd \acorn
    set path=C:\Program Files\Java\jdk1.6.0_07\bin
    set classpath=.
    java Soap
    pause
    Before I ran this file, I compiled Soap.java in my IDE and then ran it successfully. Then I moved the .class file to the directory C:\acorn. I put NOTHING ELSE in this folder. then I told the computer where to find the file 'java.exe' which I know is needed for execution of the .class file. I put the above text in Notepad and then saved it as Soap.bat onto my desktop. When I double click on it, the command prompt comes up in a little green box for a few seconds, and then the GUI opens and says "It Works!". Now that I know the concept of batch files, I tried creating another one that used the BreezySwing package.
    After I installed my JDK, I installed BreezySwing and TerminalIO which are two foreign packages that make building code much easier. I downloaded the .zip file from Lambert and Osborne called BreezySwingAndTerminalIO.zip. I extracted the files to the 'bin' folder of my JDK. Once I did this, and set the PATH environment variable to the 'bin' folder of my JDK, all BreezySwing and TerminalIO programs that I made worked. Now I wanted to make a batch file from the program AddFields.java. It is a GUI program that imports two packages, the traditional GUI javax.swing package and the foreign package BreezySwing. The user enters two numbers in two DoubleField objects and then selects one of four buttons; one for each arithmetic operation (add, subtract, multiply, or divide). Then the program displays the solution in a third DoubleField object. This program both compiles and runs successfully in JCreator. So, next I moved the .class file from the MyProjects folder that JCreator uses to C:\acorn. I put nothing else in this folder. The file Soap.class was still in there, but I did not think it would matter. Then I created the batch file:
    @echo off
    cd \acorn
    set path=C:\Program Files\Java\jdk1.6.0_07\bin
    set classpath=.
    java AddFields
    pause
    As you can see, it is exactly the same as the one for Soap. I made this file in Notepad and called it AddFields.bat. Upon double clicking on the file, I got this error message from command prompt:
    Exception in thread "main" java.lang.NoClassDefFoundError: BreezySwing/GBFrame
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    4)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    Caused by: java.lang.ClassNotFoundException: BreezySwing.GBFrame
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    ... 12 more
    Press any key to continue . . .
    I know that most of this makes no sense; but that it only means that it cannot find the class BreezySwing or GBFrame (which AddFields extends). Notice, however that it does not give an error for javax.swing. If I change the "set path..." command to anything other than the 'bin' folder of my JDK, I get this error:
    'java' is not recognized as an internal or external command,
    operable program or batch file.
    Press any key to continue . . .
    I know this means that the computer cannot find the file 'java.exe' which I believe holds all of the java.x.y.z style packages (native packages); but not BreezySwing or any other foreign packages. Remember, I do not get this error for any of the native Java packages. I decided to compare the java.x.y.z packages with BreezySwing:
    I see that all of the native packages are not actually visible in the JDK's bin folder. I think that they are all stored in one of the .exe files in there because there are no .class files in the JDK's bin folder.
    However, BreezySwing is different, there is no such file called "BreezySwing.exe"; there are just about 20 .class files all with names like "GBFrame.class", and "GBActionListener.class". As a last effort, I moved all of these .class files directly into the bin folder (they were originally in a seperate folder called BreezySwingAndTerminalIO). This did nothing; even with all of the files in the same folder as java.exe.
    So my question is: What do I need to do to get the BreezySwing package recognized on my computer? Is there possibly a download for a file called "BreezySwing.exe" somewhere that would be similar to "java.exe" and contain all of the BreezySwing packages?

    There is a lot of detail in your posts. I won't properly quote everything you put (too laborious). Instead I'll just put your words inside quotes (").
    "..there are some things about the interface that I do not like."
    Like +what?+ This is not a help desk, and I would appreciate you participating in this discussion by providing details of what it is about the 'interface' of webstart that you 'do not like'. They are probably misunderstandings on your part.
    "Some of the .jar files I made were so dangerously corrupt, that I had to restart my computer before I could delete them."
    Corrupt?! I have never once had the Java tools produce a corrupt Jar. OTOH, the 'cannot delete' problem might relate to the JRE gaining a file lock on the archive at run-time. If the file lock persisted after ending the app., it suggests that the JRE was not properly shut down. This is a bug in the code and should be fixed. Deploying as .class files will only 'hide' the problem (from casual inspection - though the Task Manager should show the orphaned 'java' process).
    "I then turned to batch files for their simple structure and portability (I managed to successfully transport a java.util containing batch file from my computer to another). This was what I did:
    - I created a folder called Task
    - Then I copied three things into this folder: 1. The file "java.exe" from my JDK. 2. The program's .class file (Count.class). and 3. The original batch file.
    - Then I moved the folder from a removable disk to the second computer's C drive (C:\Task).
    - Last, I changed the code in the batch file...:"
    That is the +funniest+ thing I've heard on the forums in the last 72 hours. You say that is easy?! Some points.
    - editing batch files is not scalable to 100+ machines, let alone 10000+.
    - The fact that Java worked on the target machine was because it was +already installed.+ Dragging the 'java.exe' onto a Windows PC which has no Java will not magically make it 'Java enabled'.
    And speaking of Java on the client machine. Webstart has in-built mechanisms to ensure that the end user has the minimum required Java version to run the app. - we can also use the [deployJava.js|http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit] on the original web page, to check for minimum Java before it puts the link to download/install the app. - if the user does not have the required Java, the script should guide them through installing it.
    Those nice features in deployJava.js are available to applets and apps. launched using webstart, but they are not available for (plain) Jar's or loose class files. So if 'ensuring the user has Java' is one of the requirements for your launch, you are barking up the wrong tree by deploying loose class files.
    Note also that if you abandon webstart, but have your app. set up to work from a Jar, the installation process would be similar to above (though it would not need a .bat file, or editing it). This basic strategy is one way that I provide [Appleteer (as a downloadable ZIP archive)|http://pscode.org/appleteer/#download]. Though I side-step your part 1 by putting the stuff into a Jar with the path Appleteer/ - when the user expands the ZIP, the parts of the app. are already in the Appleteer directory.
    Appleteer is also provided as a webstart launched application (and as an applet). Either of those are 'easier' to use than the downloadable ZIP, but I thought I would provide it in case the end user wants to save it to disk and transport the app. to a machine with no internet connection, but with Java (why they would be testing applets on a PC with no internet connection, I am not sure - but the option is there).
    "I know that .jar and .exe files are out because I always get errors and I do not like their interfaces. "
    What on earth are you talking about? Once the app. is on-screen, the end user would not be able to distinguish between
    1) A Jar launched using a manifest.
    2) A Jar launched using webstart.
    3) Loose class files.
    Your fixation on .bat files sounds much like the adage that 'If the only tool you have is a hammer, every job starts to look like a nail'.
    Get over them, will you? +Using .bat files is not a practical way to provide a Java app. to the end user+ (and launching an app. from a .bat looks quite crappy and 'second hand' to +this+ user).
    Edit 1:
    The instructions for running Appleteer as a Jar are further up the page, in the [Running Appleteer: Application|http://pscode.org/appleteer/#application] section.
    Edited by: AndrewThompson64 on May 19, 2009 12:06 PM

  • Multiple palette files in a library/class file causes problems

    While developing a labview class, I wanted to set the default palette, so I added the relevant dir.mnu file to the class. Unfortunately, the class already had a dir.mnu file in it. On adding the file, I got some error message about a dependency change*(which makes no sesne, how can a palette file have any dependencies !). On saving the class and then attempting to reopen it, LabVIEW claims it is corrupt. Inspecting the xml .lvclass files reveals that when I added the new paletee file, LabVIEW actually just added a second reference to the palette file already in the project, which it then considers to be a problem when it tries loading the class. This is clearly a bug on a number of levels:
    It should not be possible for the user to induce LabVIEW to create corrupt xml files through such simple attempts to use documented features.
    The underlying problem is that LabVIEW appears to be using the conventional search/linking rules to load library items irrespective of whether they are a vi (which should ahve a unique name) or other file (which might well be legitimately non-unique).
    Given the near impossibility of renaming a palette file without breaking palette links this particular bug is extra annoying.
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/
    Solved!
    Go to Solution.

    Sorry for the delay, it took me a little longer to reproduce the problem systematically. Attached are three zip files of the same trivial class. The only difference between them is the contents of the class file itself.
    The key point is that I have two folders in my class - Public and Protected (although I haven't actually set the access scope I realise). Each folder has a dir.mnu file in it and there is also a dir.mnu file in the main class folder. The class virtual folder structure maps directly to the on disc version.
    In the first zip file the dir.mnu files are not added to the class.
    In the second zip dile I added the dir.mnu by right clicking and doing Add file...  This is allowed because each dir.mnu has a distinct path. I then save the class file and close it.
    To get the third zip file, I reopen the class file. I  get a single dependency warning about dir.mnu in one of the sub folders. So I think "fine ok, somethign funny about that dir.mnu file" - note if I'm loading a whole heirarchy of classes I may be told LabVIEW is laoding the dir.mnu file from somewhere completely different in my class structure. I then save the class file to give the thrid zip file.
    The lvclass file in the third zip file is corrupt because it has multiple entries for the same file, because it didn't handle having more than 2 items conflicting.
    The correct behaviour would be not to invoke the conflicting item names for non vi/ctl document types. I could imagine that there would be similar problems if I had a say a whole range of say README.html files strewn over the place.
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/
    Attachments:
    Break Class File-1.zip ‏21 KB
    Break Class File-2.zip ‏21 KB
    Break Class File-3.zip ‏21 KB

  • How to convert class file

    Hi all, I am new in java card development.
    This is my environment setting:
    @echo off
    set JC_HOME=C:\JavaCard\java_card_kit-2_2
    set JAVA_HOME=C:\j2sdk14103
    set PATH=.;%JC_HOME%\bin;%PATH%
    I have created the Wallet applet according to 'Zhiqun Chen" text book and named it WalletApp.java.
    I have compiled this file to a class file.
    This is where is I saved my file
    C:\JavaCard\java_card_kit-2_2\samples\src\com\sun\javacard\samples\WalletApp\WalletApp.java.
    But I don't really understand how to convert the class file.
    May I know what is this for?
    -out EXP JCA CAP
    -exportpath
    -applet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1:0x1
    com.sun.javacard.samples.HelloWorld.HelloWorld
    com.sun.javacard.samples.HelloWorld
    0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x1 1.0
    must save this in what file?
    I tried to type in the command line below (and the result):
    C:\JavaCard\java_card_kit-2_2\samples>converter -config scr\com\sun\javacard\sap
    les\Wallet\Wallet.opt
    error: file scr\com\sun\javacard\saples\Wallet\Wallet.opt could not be found
    Usage: converter <options> package_name package_aid major_version.minor_ver
    sion
    OR
    converter -config <filename>
    use file for all options and parameters to converter
    Where options include:
    -classdir <the root directory of the class hierarchy>
    set the root directory where the Converter
    will look for classes
    -i support the 32-bit integer type
    -exportpath <list of directories>
    list the root directories where the Converter
    will look for export files
    -exportmap use the token mapping from the pre-defined export
    file of the package being converted. The converter
    will look for the export file in the exportpath
    -applet <AID class_name>
    set the applet AID and the class that defines the
    install method for the applet
    -d <the root directory for output>
    -out [CAP] [EXP] [JCA]
    tell the Converter to output the CAP file,
    and/or the JCA file, and/or the export file
    -V, -version print the Converter version string
    -v, -verbose enable verbose output
    -help print out this message
    -nowarn instruct the Converter to not report warning messages
    -mask indicate this package is for mask, so restrictions on
    native methods are relaxed
    -debug enable generation of debugging information
    -nobanner suppress all standard output messages
    -noverify turn off verification. Verification is default
    *********************************************************May I know What is the correct command line to convert the class file and what must I do to before converting the class file?
    I saw some article saying we must use JDK1.3, is it a must?
    Your solution is highly appreciated.
    Thank you!

    Hi Ricardo,
    I saved the file below as WalletApp.opt in the directory of scr\com\sun\javacard\samples\WalletApp
    -out EXP JCA CAP
    -exportpath c:\javacard\java_card_kit-2_2\api_export_files
    -applet 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2:0x1 WalletApp.WalletApp
    WalletApp 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2 1.0
    But I still have the problem below:
    C:\JavaCard\java_card_kit-2_2\samples>converter -config scr\com\sun\javacard\sam
    ples\WalletApp\WalletApp.opt
    error: file scr\com\sun\javacard\samples\WalletApp\WalletApp.opt could not be fo
    und
    Usage: converter <options> package_name package_aid major_version.minor_ver
    sion
    OR
    converter -config <filename>
    May I know What's wrong with my command or file?
    Where can I download JDK because what I can find is J2SDK.
    Thank you!

  • How to convert a .jad file to .class file in JAVA Swings.

    Hi all,
    Sorry for the interruption.I am also facing the same problem.I am using DEJDecompiler.But my application is not J2ME But J2EE.( a Swing application).I opened .class file and made some changes but I dont know how to convert into a .class file again.
    I tried saving .jad file to .java file.Then it is showing lot of errors in Eclipse Platform.I doubt if there are any errors in the .class file already,then how could the program would run.I put all the programs in the respective platforms only and then testing.It fails.
    (2) one more question,is if I do not need to disturb any existing coding and need to create a seperate java file which will do my customisation,then what should I do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.
    Thanks in advance
    With regds
    Satheesh.K

    I tried saving .jad file to .java file.Then it is
    showing lot of errors in Eclipse Platform.I doubt if
    there are any errors in the .class file already,then
    how could the program would run.I put all the programs
    in the respective platforms only and then testing.It
    fails.So who's Java program/library are you trying to steal?
    (2) one more question,is if I do not need to disturb
    any existing coding and need to create a seperate java
    file which will do my customisation,then what should I
    do.I could not get any interfaces in the program.
    Please help me as the matter is most urgent.Wow, you urgently need to steal someones program/library. The best person to give you advice urgently is the owner of the program/library you are trying to steal.
    Thanks in advancePlease don't thank me because I'm not going to help you!
    With regds
    Satheesh.K

  • How to load a .class file dynamically?

    Hello World ;)
    Does anyone know, how I can create an object of a class, that was compiled during the runtime?
    The facts:
    - The user puts a grammar in. Saved to file. ANTLR generates Scanner and Parser (Java Code .java)
    - I compile these file, so XYScanner.class and XYParser.class are available.
    - Now I want to create an object of XYScanner (the classnames are not fixed, but I know the filename). I tried to call the constructor of XYScanner (using reflection) but nothing works and now I am really despaired!
    Isn't there any way to instantiate the class in a way like
    Class c = Class.forName("/home/mark/XYScanner");
    c scan = new c("input.txt");
    The normal call would be:
    XYLexer lex = new XYLexer(new ANTLRFileStream("input.txt"));The problem using reflection is now that the parameter is a ANTLRFileStream, not only an Integer, as in this example shown:
    Class cls = Class.forName("method2");
    Class partypes[] = new Class[2];
    partypes[0] = Integer.TYPE;
    partypes[1] = Integer.TYPE;
    Method meth = cls.getMethod("add", partypes);
    method2 methobj = new method2();
    Object arglist[] = new Object[2];
    arglist[0] = new Integer(37);
    arglist[1] = new Integer(47);
    Object retobj = meth.invoke(methobj, arglist);
    Integer retval = (Integer)retobj;
    System.out.println(retval.intValue());Has anyone an idea? Thanks for each comment in advance!!!

    Dump all of your class files into a directory.
    Use the File class to list all files and iterateover
    the files.NastyNot really, when you are dynamically creating code, I would expect the output to be centralized, not spread out all over the place.
    >
    Use a URLClassloader to load the URL that isobtained
    for each file with file.toURI().toURL()(file.toURL()
    is depricated in 1.6)Wrong, the URL you give it must be that of the
    directory, not the class file.No, I did this quite recently, you can give it a specific class file to load.
    >
    Load all of the classes in this directory, thatway
    any anonymous classes are loaded as well.Anonymous classes automatically loaded when the real
    one isIt can't load it if it doesn't know where the code is. Since you haven't used a URL classloader to load once class file at a time, you would never encounter this. But if you loaded a class file that had an anonymous classfile it needed, would it know where to look for it?
    >
    From this point you should be able to just get a
    class with Class.forName(name)No. Class.forName uses the classloader of the class
    it's called in, which will be the system classloader.
    It won't find classes loaded by a URLClassLoader.got me there.

  • Se development kit (jdk 6) problem creating class file with HelloWorldApp

    I downloaded the java SE Development kit (JDK 6) with Java FX SDK and used the download manager from Java web site, the program downloaded the
    jdk-6u13-javafx-1_1_1-windows-i586 icon to my desktop and the java program to
    C\Program Files\Java\jdk1.6.0_13
         Jre1.5.0_05
         Jre1.6.0_03
         Jre6
    I then created a Java source file which was HelloWorldApp.java. and typed in the Hello World Code as requested I saved it to
    C\Documents and Settings\Compaq_owner\Java.
    Then I try to compile my source file into a .class file and get stuck as I am told to open a command window which I do through, start\allprograms\accessories\command promt.
    My command window says C:\Documents and Setting\Compaq_Owner>
    I am told to compile my source file and I must change my directory in the command window to the directory where my file is located.
    I type after the existing promt, cd C:\java and also tried, cd C:\Documents and Settings\Compaq_Owner\Java\HelloWorldApp. And was told both times the system cannot find the path specified
    I typed dir after the promt and can see the java directory there in the list, but have I placed my HelloWorldApp File in the wrong place what is wrong please help I cannot get off the ground
    Kind regards pete

    petefizz wrote:
    I then created a Java source file which was HelloWorldApp.java. and typed in the Hello World Code as requested I saved it to
    C\Documents and Settings\Compaq_owner\Java.Then the full path to your HelloWorldApp.java file is: C\Documents and Settings\Compaq_owner\Java\HelloWorldApp.java.
    Then I try to compile my source file into a .class file and get stuck as I am told to open a command window which I do through, start\allprograms\accessories\command promt.
    My command window says C:\Documents and Setting\Compaq_Owner>
    I am told to compile my source file and I must change my directory in the command window to the directory where my file is located. You file is located in the directory, C\Documents and Settings\Compaq_owner\Java
    I type after the existing promt, cd C:\java and also tried, cd C:\Documents and Settings\Compaq_Owner\Java\HelloWorldApp. And was told both times the system cannot find the path specifiedcd stands for Change Directory. You want to change to the directory where your .java file is. You can not use a path that ends in a file because a file is not a directory.
    You may need to put C\Documents and Settings\Compaq_owner\Java inside double quotes, "C\Documents and Settings\Compaq_owner\Java" I think newer versions of Windows will not require the double quotes.

  • String.format()   error (works in a class file , not in jsp)

    Hello all,
    I am using Java 5 and am trying to use the String.format() method in a jsp but am getting the following error:
    HTTP Status 500 -
    type Exception report
    message
    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: 5 in the jsp file: /ajax.jsp
    Generated servlet error:
    C:\Documents and Settings\gforte\.netbeans\5.0beta2\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\agi\org\apache\jsp\ajax_jsp.java:50: cannot find symbol
    symbol : method format(java.lang.String,java.util.Date,java.util.Date)
    location: class java.lang.String
    String dateString = String.format("%tb%td",date,date);
    ^
    1 error
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:246)
         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:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    Apache Tomcat/5.5.9
    The code I am using is working fine in a class file but wont work in my jsp.
    <%@page import="java.util.*,java.lang.String"%>        
    Date date = new Date();
    String dateString = String.format("%tb%td",date,date);
    System.out.println(dateString);Any ideas?

    I get excactly the same problem.
    If compile the the JSP in Netbeans it works fine, however when Tomcat attempts to compile it into a servlet at runtime, I get the same error as described.
    This is the line in JSP that fails:
    <code>Some more text <%= String.format("%s","Bizarre") %> </code>However this one works OK:
    <code>Some more text <%= "Bizarre".substring(3) %> </code>Its almost as if Tomcat is compiling under JDK 1.4.2 or something but I don't have any other JDK or JRE installed; only 1.5.
    I suspect it may be a Tomcat setting that's causing a 1.4 code compliance.
    In Netbeans, if I go to the project properties -> Sources, at the bottom is the "Source Level" drop down list. If I change this to 1.4 and clean and build the whole project I get the same error when the jsp (or any class with this construct) is compiled by NetBeans.
    Note: I am using the Netbeans 5.0 and Tomcat and 5.5.9 co-bundle which I downloded from the Sun website.
    Can anyone help?
    Heres the splurge from the browser output:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 55 in the jsp file: /login.jsp
    Generated servlet error:
    C:\Documents and Settings\Peter\.netbeans\5.0\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\SuperStruts\org\apache\jsp\login_jsp.java:105: cannot find symbol
    symbol  : method format(java.lang.String,java.lang.String)
    location: class java.lang.String
          out.print( String.format("%s","Bizarre") );
                           ^
    1 error
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:246)
         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:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
    Note also that when I run this JSP page:
    <%@page import="java.util.*"%>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%
            Properties p = System.getProperties();
            Enumeration keys = p.keys();
            Object key;
            while (keys.hasMoreElements()) {
                key = keys.nextElement();
                out.println("key: " + key + " - " + p.getProperty((String)key) + "<br/>");
    %>     ... I get this browser output:
    key: java.runtime.name - Java(TM) 2 Runtime Environment, Standard Edition
    key: sun.boot.library.path - C:\Program Files\Java\jdk1.5.0_06\jre\bin
    key: java.vm.version - 1.5.0_06-b05
    key: shared.loader - ${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar
    key: java.vm.vendor - Sun Microsystems Inc.
    key: java.vendor.url - http://java.sun.com/
    key: path.separator - ;
    key: tomcat.util.buf.StringCache.byte.enabled - true
    key: java.vm.name - Java HotSpot(TM) Client VM
    key: file.encoding.pkg - sun.io
    key: user.country - GB
    key: sun.os.patch.level - Service Pack 2
    key: java.vm.specification.name - Java Virtual Machine Specification
    key: user.dir - C:\Program Files\netbeans-5.0\enterprise2\jakarta-tomcat-5.5.9\bin
    key: java.runtime.version - 1.5.0_06-b05
    key: java.awt.graphicsenv - sun.awt.Win32GraphicsEnvironment
    key: java.endorsed.dirs -
    key: os.arch - x86
    key: java.io.tmpdir - C:\Documents and Settings\Peter\.netbeans\5.0\jakarta-tomcat-5.5.9_base\temp
    key: line.separator -
    key: java.vm.specification.vendor - Sun Microsystems Inc.
    key: java.naming.factory.url.pkgs - org.apache.naming
    key: java.util.logging.manager - org.apache.juli.ClassLoaderLogManager
    key: user.variant -
    key: os.name - Windows XP
    key: sun.jnu.encoding - Cp1252
    key: java.library.path - C:\Program Files\Java\jdk1.5.0_06\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\oracle\product\10.2.0\db_2\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\ATI Technologies\ATI.ACE\;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\Program Files\Common Files\GTK\2.0\bin;C:\Program Files\CVSNT\
    key: java.specification.name - Java Platform API Specification
    key: java.class.version - 49.0
    key: sun.management.compiler - HotSpot Client Compiler
    key: os.version - 5.1
    key: user.home - C:\Documents and Settings\Peter
    key: catalina.useNaming - true
    key: user.timezone - Europe/London
    key: java.awt.printerjob - sun.awt.windows.WPrinterJob
    key: file.encoding - Cp1252
    key: java.specification.version - 1.5
    key: catalina.home - C:\Program Files\netbeans-5.0\enterprise2\jakarta-tomcat-5.5.9
    key: java.class.path - C:\Program Files\Java\jdk1.5.0_06\lib\tools.jar;C:\Program Files\netbeans-5.0\enterprise2\jakarta-tomcat-5.5.9\bin\bootstrap.jar
    key: user.name - Peter
    key: java.naming.factory.initial - org.apache.naming.java.javaURLContextFactory
    key: package.definition - sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.
    key: java.vm.specification.version - 1.0
    key: java.home - C:\Program Files\Java\jdk1.5.0_06\jre
    key: sun.arch.data.model - 32
    key: user.language - en
    key: java.specification.vendor - Sun Microsystems Inc.
    key: awt.toolkit - sun.awt.windows.WToolkit
    key: java.vm.info - mixed mode
    key: java.version - 1.5.0_06
    key: java.ext.dirs - C:\Program Files\Java\jdk1.5.0_06\jre\lib\ext
    key: sun.boot.class.path - C:\Program Files\Java\jdk1.5.0_06\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0_06\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0_06\jre\classes
    key: server.loader - ${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar
    key: java.vendor - Sun Microsystems Inc.
    key: catalina.base - C:\Documents and Settings\Peter\.netbeans\5.0\jakarta-tomcat-5.5.9_base
    key: file.separator - \
    key: java.vendor.url.bug - http://java.sun.com/cgi-bin/bugreport.cgi
    key: common.loader - ${catalina.home}/common/classes,${catalina.home}/common/i18n/*.jar,${catalina.home}/common/lib/*.jar
    key: sun.io.unicode.encoding - UnicodeLittle
    key: sun.cpu.endian - little
    key: package.access - sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans.
    key: sun.desktop - windows
    key: sun.cpu.isalist - demonstrating (I think) that the correct JDK and JDK are in use by Tomcat.

  • WebLogic looking for class file using the wrong case

    During my ant build, I precompile my JSPs using weblogic.jspc. All of the jars and wars are packaged into an ear and deployed to WebLogic 8.1 on Linux. When I access one of our normal screens, everything is good. Things go wrong when I try to access one of our help screens. We have a base help file that includes another file based on the screen code passed to it. The screen code is used in combination with a HashMap to look up the correct JSP to include. This part goes fine. But when the JSP is included, I get the following error. The best I can figure is that the class file is in mixed case (i.e., SampleHelp00.jsp and SampleHelp00.class), but Weblogic is looking for samplehelp00.class.
    I'm not even where I should begin looking to solve this. Anyone have any ideas?
    ----- BEGIN STACKTRACE -----
    javax.servlet.jsp.JspException:
    [HTTP:101249][ServletContext(id=70634941,name=grp,context-path=/grp)]:
    Servlet class jsp_servlet._help.__samplehelp00 for servlet
    /help/SampleHelp00.jsp could not be loaded because the requested class was not found in the classpath
    /usr/share/weblogic/weblogic81/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/wf-web-sys.wftesttest.war:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/jarfiles/WEB-INF/lib/Struts_Validator-20010702.jar:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/jarfiles/WEB-INF/lib/struts.jar:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/jarfiles/WEB-INF/lib/taglibs-session.jar:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/jarfiles/WEB-INF/lib/wf.wftesttest.jar:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp/jarfiles/_wl_cls_gen.jar:
    /weblogic81sp5/weblogic81sp5/config/wftesttest/webSysServer02/.wlnotdelete/extract/webSysServer02_wf-web-sys.wftesttest_grp.
    java.lang.ClassNotFoundException:
    jsp_servlet._help.__samplehelp00.
    at org.apache.struts.taglib.template.InsertTag.doEndTag()I(InsertTag.java:149)
    at jsp_servlet.__su_hl0._jspService(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )V(__su_hl0.java:289)
    at weblogic.servlet.jsp.JspBase.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(JspBase.java:33)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava/lang/Object;(ServletStubImpl.java:1072)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Lweblogic/servlet/internal/FilterChainImpl; )V(ServletStubImpl.java:465)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(ServletStubImpl.java:348)
    at weblogic.servlet.internal.RequestDispatcherImpl.forward(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(RequestDispatcherImpl.java:328)
    at org.apache.struts.action.ActionServlet.processForward(Lorg/apache/struts/action/ActionMapping;Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )Z(ActionServlet.java:1847)
    at org.apache.struts.action.ActionServlet.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )V(ActionServlet.java:1568)
    at org.apache.struts.action.ActionServlet.doGet(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )V(ActionServlet.java:491)
    at javax.servlet.http.HttpServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )V(HttpServlet.java:740)
    at com.clear2pay.ppp.util.ui.struts.ActionServlet.service(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse; )V(ActionServlet.java:138)
    at javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(HttpServlet.java:853)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava/lang/Object;(ServletStubImpl.java:1072)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Lweblogic/servlet/internal/FilterChainImpl; )V(ServletStubImpl.java:465)
    at weblogic.servlet.internal.TailFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain; )V(TailFilter.java:28)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(FilterChainImpl.java:27)
    at com.clear2pay.ppp.util.ui.SetCharacterEncodingFilter.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain; )V(SetCharacterEncodingFilter.java:150)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse; )V(FilterChainImpl.java:27)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run()Ljava/lang/Object;(WebAppServletContext.java:6987)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic/security/subject/AbstractSubject;Ljava/security/PrivilegedAction; )Ljava/lang/Object;(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(Lweblogic/security/acl/internal/AuthenticatedSubject;Lweblogic/security/acl/internal/AuthenticatedSubject;Ljava/security/PrivilegedAction; )Ljava/lang/Object;(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogic/servlet/internal/ServletRequestImpl;Lweblogic/servlet/internal/ServletResponseImpl; )V(WebAppServletContext.java:3892)
    at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic/kernel/ExecuteThread; )V(ServletRequestImpl.java:2766)
    at weblogic.kernel.ExecuteThread.execute(Lweblogic/kernel/ExecuteRequest; )V(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:183)
    at java.lang.Thread.startThreadFromVM(Ljava/lang/Thread; )V(Unknown Source)
    ----- END STACKTRACE -----
    Message was edited by:
    cabuki

    Ignore the part about precompiled JSPs being ignored on my development server. Turns out I had a stale cache. I cleared that out and now it recognizes the files.
    The problem with that, is now I'm getting an Error 500 when I try to access the page.
    ----- BEGIN STACKTRACE -----
    javax.servlet.jsp.JspException
         at org.apache.struts.taglib.template.InsertTag.doEndTag()I(InsertTag.java:149)
         at jsp_servlet.__su_h0._jspService(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(__su_h0.java:316)
         at weblogic.servlet.jsp.JspBase.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(JspBase.java:33)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava.lang.Object; (ServletStubImpl.java:996)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Lweblogic.servlet.internal.FilterChainImpl; )V(ServletStubImpl.java:419)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(ServletStubImpl.java:315)
         at weblogic.servlet.internal.RequestDispatcherImpl.forward(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(RequestDispatcherImpl.java:318 )
         at org.apache.struts.action.ActionServlet.processForward(Lorg.apache.struts.action.ActionMapping;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )Z(ActionServlet.java:1847)
         at org.apache.struts.action.ActionServlet.process(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(ActionServlet.java:1568 )
         at org.apache.struts.action.ActionServlet.doGet(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(ActionServlet.java:491)
         at javax.servlet.http.HttpServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(HttpServlet.java:740)
         at com.clear2pay.ppp.util.ui.struts.ActionServlet.service(Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse; )V(ActionServlet.java:138 )
         at javax.servlet.http.HttpServlet.service(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run()Ljava.lang.Object;(ServletStubImpl.java:996)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Lweblogic.servlet.internal.FilterChainImpl; )V(ServletStubImpl.java:419)
         at weblogic.servlet.internal.TailFilter.doFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Ljavax.servlet.FilterChain; )V(TailFilter.java:28 )
         at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(FilterChainImpl.java:27)
         at com.clear2pay.ppp.util.ui.SetCharacterEncodingFilter.doFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse;Ljavax.servlet.FilterChain; )V(SetCharacterEncodingFilter.java:150)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax.servlet.ServletRequest;Ljavax.servlet.ServletResponse; )V(FilterChainImpl.java:27)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run()Ljava.lang.Object;(WebAppServletContext.java:6458 )
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic.security.subject.AbstractSubject;Ljava.security.PrivilegedAction; )Ljava.lang.Object;(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(Lweblogic.security.acl.internal.AuthenticatedSubject;Lweblogic.security.acl.internal.AuthenticatedSubject;Ljava.security.PrivilegedAction; )Ljava.lang.Object;(SecurityManager.java:118 )
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogic.servlet.internal.ServletRequestImpl;Lweblogic.servlet.internal.ServletResponseImpl; )V(WebAppServletContext.java:3661)
         at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic.kernel.ExecuteThread; )V(ServletRequestImpl.java:2630)
         at weblogic.kernel.ExecuteThread.execute(Lweblogic.kernel.ExecuteRequest; )V(ExecuteThread.java:219)
         at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:178 )
         at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread; )V(Unknown Source)
    ----- END STACKTRACE -----
    The page in question is just a simple JSP using Struts (v 1.0.2) to call in a template.
    ----- BEGIN JSP -----
    <%@ page language="java" contentType="text/html; charset=UTF-8" %>
    <%@ taglib uri="/WEB-INF/lib/struts.tld" prefix="struts" %>
    <%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri='/WEB-INF/lib/struts-template.tld' prefix='template' %>
    <template:insert template='/t/system.jsp'>
    <template:put name='title'><bean:message key="tit_su_h0"/></template:put>
    <template:put name='sidenav' content='/t/su_snv.jsp'/>
    <template:put name='content' content='/c/su_h0_c.jsp'/>
    <template:put name='footer' content='/t/su_ftr.jsp' />
    </template:insert>
    ----- END JSP -----
    I passed the -keepGenerated flag to the precompile task in my Ant build so I could look at the line it's choking on, but it's not very helpful. I'm stuck. I can set up the build so it doesn't precompile the JSPs, but then the QA team wouldn't like me very much.

  • Can I use Serialization if I have to update my class files?

    Hi,
    I'm writing a game right now, and I'm using Serialization to implement saving maps in it. Its saving me a whole bunch of time right now, but I'm worried that if I make even the slightest adjustment to my class files, then old saved maps won't work anywhere.
    Is there anyway to work around this?
    Thank you for any suggestions.
    -Cuppo

    Yes there is; the description of that all can be found in the API docs for the
    Serializable interface; in short: you have to write/read the members of
    your classes yourself by implementing two special methods; that's all.You don't even have to do that. As long as you provide a serialVersionUID
    member and obey the versioning constraints in the Serialization specification
    you don't have to do any extra programing.You're right; your scenario is even simpler; I discovered something funny though:
    my 1.4.2. API docs lack all documentation of the serialVersionUID final member in
    the description of the Serializable interface. It is present in the 1.5. docs, strange ...
    kind regards,
    Jos

  • Trying to move inner class to a class file

    Hi folks,
    I keep getting an error which puzzles me. I cut the following class (MyDocumentListener) out of an outer class (CenterPanel).
    MyDocumentListener compiles OK but...
    Now when I compile the outerclass I get the folowing error:
    C:\divelog> javac -classpath C:\ CenterPanel.java
    CenterPanel.java:54: cannot access divelog.MyDocumentListener
    bad class file: C:\divelog\MyDocumentListener.class
    class file contains wrong class: MyDocumentListener
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define
    the listener class
    ^
    1 error
    ... yes I checked, it is there..
    C:\divelog>dir m*.j*
    Directory of C:\divelog
    MYDOCU~1 JAV 936 03-04-03 11:16p MyDocumentListener.java
    ====================================================================
    MyDocumentListener tests to see if the current document has changed.
    Required fields: boolean documentWasChanged;
    import javax.swing.event.*;
    // ------ Document listener class -----------
    public class MyDocumentListener implements DocumentListener {
    public void insertUpdate(DocumentEvent e) {
    wasChanged(e);
    public void removeUpdate(DocumentEvent e) {
    wasChanged(e);
    public void changedUpdate(DocumentEvent e) {
    public boolean wasChanged(DocumentEvent e) {
    // indicate that the document was changed
    //and test before opening another file or closing the application.
    boolean documentWasChanged = true;
    return documentWasChanged;
    } // close class MyDocumentListener
    ====================================================================
    package divelog;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.lang.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    // import javax.swing.text.JTextComponent.*;
    import javax.swing.text.*;
    public class CenterPanel extends JPanel implements ActionListener
    { // Opens class
    static private final String newline = "\n";
    private JTextArea comments;
    private JScrollPane scrollpane;
    private JButton saveButton, openButton;
    private JLabel whiteshark;
    private Box box;
    private BufferedReader br ;
    private String str;
    private JTextArea instruct;
    private File defaultDirectory = new File("C://divelog");
    private File fileDirectory = null;
    private File currentFile= null;
    // public boolean changed;
    public boolean documentWasChanged;
    public CenterPanel()
    { // open constructor CenterPanel
    setBackground(Color.white);
    comments = new JTextArea("Enter comments, such as " +
    "location, water conditions, sea life you observed," +
    " and problems you may have encountered.", 15, 10);
    comments.setLineWrap(true);
    comments.setWrapStyleWord(true);
    comments.setEditable(true);
    comments.setFont(new Font("Times-Roman", Font.PLAIN, 14));
    // add a document listener for changes to the text,
    // query before opening a new file to decide if we need to save changes.
    MyDocumentListener myDocumentListener = new MyDocumentListener(); // define the listener class
    comments.getDocument().addDocumentListener(myDocumentListener); // create the reference for the class
    scrollpane = new JScrollPane(comments);
    scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    saveButton = new JButton("Save Comments", new ImageIcon("images/Save16.gif"));
    saveButton.addActionListener( this );
    saveButton.setToolTipText("Click this button to save the current file.");
    openButton = new JButton("Open File...", new ImageIcon("images/Open16.gif"));
    openButton.addActionListener( this );
    openButton.setToolTipText("Click this button to open a file.");
    whiteshark = new JLabel("", new ImageIcon("images/gwhite.gif"), JLabel.CENTER);
    Box boxH;
    boxH = Box.createHorizontalBox();
    boxH.add(openButton);
    boxH.add(Box.createHorizontalStrut(15));
    boxH.add(saveButton);
    box = Box.createVerticalBox();
    box.add(scrollpane);
    box.add(Box.createVerticalStrut(10));
    box.add(boxH);
    box.add(Box.createVerticalStrut(15));
    box.add(whiteshark);
    add(box);
    } // closes constructor CenterPanel
    public void actionPerformed( ActionEvent evt )
    { // open method actionPerformed
    // --------- test to see if the current file was modified and give an option to save first.
    if (documentWasChanged) // add and IF filename not null
    // ----- display pop-up alert --------------------------------------------------------------
    int confirm = JOptionPane.showConfirmDialog(null,
    "Click OK to discard current changes, \n or Cancel to save before proceeding.", // msg
    "Unsaved Modifications!", // title
    JOptionPane.OK_CANCEL_OPTION, // buttons displayed
    // JOptionPane.ERROR_MESSAGE
    // JOptionPane.INFORMATION_MESSAGE
    // JOptionPane.PLAIN_MESSAGE
    // JOptionPane.QUESTION_MESSAGE
    JOptionPane.WARNING_MESSAGE,
    null);
    if (confirm != JOptionPane.YES_OPTION) //user wants to save changes
    try {
    // let user save the file
    catch(Exception e) {}
    else // let user open a new file
    } // close "if (documentWasChanged)" - display pop-up alert ----------
    JFileChooser jfc = new JFileChooser();
         //Add a custom file filter and disable the default "Accept All" file filter.
    jfc.addChoosableFileFilter(new JTFilter()); // /** found in Utils.java /*
    jfc.setAcceptAllFileFilterUsed(false);
    // -- open the default directory --
    // public void setCurrentDirectory(File dir)
    // jfc.setCurrentDirectory(new File("C://divelog"));
    jfc.setCurrentDirectory(defaultDirectory);
    jfc.setSize(400, 300);
    jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    Container parent = saveButton.getParent();
    //========================= Test Button Actions ================================
    //========================= Open Button ================================
    if (evt.getSource() == openButton)
    int choice = jfc.showOpenDialog(CenterPanel.this);
    File file = jfc.getSelectedFile();
    // --------- change test was here -----------
    /* a: */
    if (file != null && choice == JFileChooser.APPROVE_OPTION)
    String filename = jfc.getSelectedFile().getAbsolutePath();
    // -- get the current directory name -------
    // public File getCurrentDirectory( );
    File f=new File(System.getProperty("user.dir"));
    fileDirectory = jfc.getCurrentDirectory();
    // -- remember the last directory used --
    if (defaultDirectory != fileDirectory)
    {defaultDirectory = fileDirectory;}
    try
    { //opens try         
    comments.getLineCount( );
    // -- clear the old data before importing the new file --
    comments.selectAll();
    comments.replaceSelection("");
    // -- get the new data ---
    br = new BufferedReader (new FileReader(file));
    while ((str = br.readLine()) != null)
    {//opens while
    comments.append(str);
    } //closes while
    } // close try
    catch (IOException ioe)
    { // open catch
    comments.append(newline +"Open command not successful:" + ioe + newline);
    } // close catch
    // ---- display the values of the directory variables -----------------------
    comments.append(
    newline + "The f directory variable contains: " + f +
    newline + "The fileDirectory variable contains: " + fileDirectory +
    newline + "The defaultDirectory variable contains: " + defaultDirectory );
    else
    comments.append("Open command cancelled by user." + newline);
    } //close if statement /* a: */
    //========================= Save Button ================================
    } else if (evt.getSource() == saveButton)
    int choice = jfc.showSaveDialog(CenterPanel.this);
    if (choice == JFileChooser.APPROVE_OPTION)
    File fileName = jfc.getSelectedFile();
    // -- get the current directory name -------
    // public File getCurrentDirectory( );
    File f=new File(System.getProperty("user.dir"));
    fileDirectory = jfc.getCurrentDirectory();
    // -- remember the last directory used --
    if (defaultDirectory != fileDirectory)
    {defaultDirectory = fileDirectory;}
    //check for existing files. Warn users & ask if they want to overwrite
    for(int i = 0; i < fileName.length(); i ++) {
    File tmp = null;
    tmp = (fileName);
    if (tmp.exists()) // display pop-up alert
    //public static int showConfirmDialog( Component parentComponent,
    // Object message,
    // String title,
    // int optionType,
    // int messageType,
    // Icon icon);
    int confirm = JOptionPane.showConfirmDialog(null,
    fileName + " already exists on " + fileDirectory
    + "\n \nContinue?", // msg
    "Warning! Overwrite File!", // title
    JOptionPane.OK_CANCEL_OPTION, // buttons displayed
                        // JOptionPane.ERROR_MESSAGE
                        // JOptionPane.INFORMATION_MESSAGE
                        // JOptionPane.PLAIN_MESSAGE
                        // JOptionPane.QUESTION_MESSAGE
    JOptionPane.WARNING_MESSAGE,
    null);
    if (confirm != JOptionPane.YES_OPTION)
    { //user cancels the file overwrite.
    try {
    jfc.cancelSelection();
    break;
    catch(Exception e) {}
    // ----- Save the file if everything is OK ----------------------------
    try
    { // opens try
    BufferedWriter bw = new BufferedWriter(new FileWriter(fileName));
    bw.write(comments.getText());
    bw.flush();
    bw.close();
    comments.append( newline + newline + "Saving: " + fileName.getName() + "." + newline);
    break;
    } // closes try
    catch (IOException ioe)
    { // open catch
    comments.append(newline +"Save command unsuccessful:" + ioe + newline);
    } // close catch
    } // if exists
    } //close for loop
    else
    comments.append(newline + "Save command cancelled by user." + newline);
    // ========= }
    } // end-if save button
    } // close method actionPerformed
    } //close constructor CenterPanel
    // <<<<<<<<<<<<<<<<<
    // <<<<<<<<<<<<<<<<< MyDocumentListener class was here <<<<<<<<<<<<<<<<<
    // <<<<<<<<<<<<<<<<<
    } // Closes class CenterPanel

    You didn't put your MyDocumentListener class in the package divelog.
    Add
    package divelog;to the top of MyDocumentListener.java and recompile.

  • Java not creating .class file ?

    I copied and pasted text into textpad then saved textpad creats the java file but no class file ! What gives ? I tried rebooting , the class name is the same (not mispelled) even did a HD search for class file and its no where to be found

    You have to compile a Java source file into a class file.
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html

  • Missing .class file

    I run "javac" and looks that javac compile file "HelloWorldApp.java", but when I try to run "java HelloWorldApp" I have error
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class
    If I go to my directory I can no see .class file. Why?
    I set varible for PATH and CLASSPATH ....

    I see where problem is ...
    I set PATH but does not work ... this is how looks
    like
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System
    32\Wbem;C:\Program Files\Cisco\Call Manager Attendant
    Console\jre1.4\bin;C:\Program Files\Microsoft SQL
    Server\80\Tools\BINN;C:\Program
    Files\Java\jdk1.6.0\bin;
    After I run C:\> javac HelloWorldApp.java , javac
    compile second copy of "HelloWorldApp.java" located
    in C:\
    On this location I found .class file ...
    (I was thinking if I set PATH, I have to save application there tooNo, PATH is an environment variable that tells the operating system where to look for executable files. That tells Windows where to find the .exe files like javac and java and jar.
    ..or when I call "javac" <file
    name>, I have to be in that directory where I saved
    file)Yes.
    I set CLASSPATH to "C:\Program
    Files\Java\jdk1.6.0\bin" and this looks like works
    fine.No, this is a waste. In spite of what that tutorial tells you, there's no need for a CLASSPATH environment variable. (Yours is wrong, BTW.) CLASSPATH is for the JVM. It tells the compiler and runtime where to look for .class files that it needs.
    The right way to set CLASSPATH is using the -classpath option on javac.exe and java.exe. Read those docs.
    After I run "java HelloWorldApp" I have error because
    CLASSPATH is set for diferent location ...java.exe ignores your CLASSPATH anyway.
    >
    When I moved my .class file from loaction "C:\" to
    "C:\Program Files\Java\jdk1.6.0\bin " and run
    "C:\>java HelloWorldApp", I did not have any error
    and application works fine.That's wrong. Your code does not belong in there. Ever.
    >
    So, why my PATH does not work for "javac" ???Your PATH works fine, because Windows found javac.exe and java.exe. It's CLASSPATH that's incorrect.
    Compile like this:
    javac *.javaRun like this:
    java -classpath . HelloWorldAppNote the "dot" after -classpath. That sets the CLASSPATH to the current directory.
    %

  • How to clear old class files cached in JVM

    JVM stores old class files in its cache even after the corresponding files have been deleted from the database. This causes a conflict if a new file is saved with the same name as one that was deleted earlier causing old data to be fetched and not the new one.
    am using the following line of code to load the class file :
    Class.forName(className, false, this.getClass().getClassLoader())
    please help
    Thanks - N

    Why are you trying to do that?
    Dynamic Classloading(reloading) has a meaing only on "application container" like WAS.
    Not appropriate for normal applcation.
    Focus on enhancing your application logic and algorithm rather than wasting your brain on difficult and meaningless things. Applying some flexible design patterns wouldn't suffice?
    Anyway, Sun provides wonderful and simple custom classloader sample.
    http://java.sun.com/developer/onlineTraining/Security/Fundamentals/magercises/ClassLoader/help.html
    Anayzing tomcat source(which is downloadable) is another approach.
    Edited by: Dion_Cho on Nov 26, 2007 5:18 PM
    Typo...

  • Including AS3 external class file

    How do I include 2 or more external action script files in my FLA document.The first one is easy and taken care by setting the class property of the FLA document to the class file name. But if I have several external class files? I have tried the 'include' directive but the compiler complains - any suggestions?
    Thanks
    Joseph Karov

    To import the other Class, just start typing its name in an expression, and hold down the control key while hitting the space bar. Both the Flash IDE and Flash Builder will bring up a code completion dropdown. When you select the Class, the import statement will be generated.
    For example, if you are in Foo and you type:
    protected var bar:Bar;
    Then when you have typed in the "Ba" part of the word Bar after the colon, if you use the Ctrl-Space keyboard shortcut, it should show you your Bar Class, possibly among other Classes starting with "Ba." Select "Bar" with either your mouse or your cursor, and Flash will finish the word for you and generate the import statement. Note that you can now create and use instances of Bar, but Bar won't be "merged" into Foo, which it sounds like is what you want. To do that, you'll need to do what I suggested, which is to have one Class extend another Class.
    To have one Class extend the other, change the line that says "public class Foo" to "public class Foo extends Bar". Note that the two Classes must have compatible functionality and have the same base Class. I'm assuming they do, or else trying to "include" the code wouldn't work either.
    Another possible solution, depending on exactly what you're trying to acheive, is to apply the second Class to a symbol in the library and use that by placing it on the stage or accessing it through code. However, you haven't given us very much to go on, so it's really difficult to help you.

Maybe you are looking for