Can Java reflect not only .Class file
Hi' i'm newbie in this topic, i'm really appreciate if somebody can help me..cos i'm really stuck in here...
My Problems are :
1. i want to ask about this, can Java reflect from .java file?
2. i'm using Eclipse IDE, i'm really interesting about how JTree or Package Explorer in Eclipse can always displaying update information about class structure? but .java files not compiled, how can? if Eclipse using reflection, .java files must be compiled first, correct me if i'm wrong?
The fact is Eclipse don't have to compiled .java files to get the update information about class structure and displaying in JTree or package Explorer...how implement like this?
what i mean like this :
ex : if i type int x = 100; (not only int, it could be anything else..) at the working files, JTree or Package Explorer in Eclipse can always update the informasion about class structure, but .java files not compiled..
i hope my question are easy to understand, i really need some help..
Thanks a lot..
hey, thanks for the answers, but i would like to ask :
1) Eclipse performs background compilation of the Java sources, then performs reflection on those temporary classes++ if i'm using this way, how about the performance? seems that it will be compiled all the time right?
2) Eclipse has access to the results of the Java source code parser, and can extract the information from the java syntax parser, before it gets to the compilation stage.++ how to implement this? what do you mean about java syntax parser?
do you know where i can find any article about this?
thanks a lot again...
Similar Messages
-
Why require cap file why not only class file as in java
why do we convert .class to .cap file why not simply load the .clss file to the card
If Java Card has to accept .class file, it's certain
that JCVM developers are going to spend more and more
nights in their office.
Just kidding. I'm one of them.LOL :)
Put the CAP file converter on-card. -
URGENT PLEASE:How can I run a a class file on the Apache server?
Hi Guys and Gurus,
I am seeking some favor all of experienced gurus, i.e.
How can I run a a class file on the Apache server? Can I run through an Applet?
How can I set Environment variables in Windows2000 Professional Environment?
Actually, I want to extract some records from a MySQL Database running on Apache Server. I wrote a program just to select the columns and show them. It is now a Class file, Now how can I run this class file from the Server???
The code is here
import java.sql.*;
public class RecordShow {
public static void main(String args[]) {
String url = "jdbc:mysql://localhost/myhost";
Connection con;
String query = "select mytable.column," +
"from mytable " +
"where mytable.column = 1";
Statement stmt;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try {
con = DriverManager.getConnection(url,
"myuser", "mypassword");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
int rowCount = 1;
while (rs.next()) {
System.out.println("Row " + rowCount + ": ");
for (int i = 1; i <= numberOfColumns; i++) {
System.out.print(" Column " + i + ": ");
System.out.println(rs.getString(i));
System.out.println("");
rowCount++;
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
Please advise... THANKS
VJEhm, I wasn't referring to you at all... read up,
there's a comment by jschell saying that CGI might be
easier/better for his purposes.
Yep.
I know PHP/Perl/whatever might be easier for some
purposes, but only if you happen to know them and want
to/are able to use them. Ok. But you aren't the one asking the question are you. And the person who asked the question seems to have absolutely no familiarity with Apache or applets.
So whatever they do they are going to have to learn a lot.
And that does indeed suggest that in all likelyhood they have not investigated the alternatives.
And for the vast majority of internet applications, especially with smaller projects (obvious this person is not working with a large team), using perl, or something besides java, is going to be the best business solution. It is simpler, and more secure (probably due to the fact that it is simpler.)
Since this is a Java forum, I
answer under the assumption that people have made a
choice one way or another to use a Java solution to
their problem, so I try to solve it in Java first, and
only when that fails (very seldom) do I turn to other
solutions.You approach problems by arbritrarily deciding to try to solve it in java first and only if you fail do you then look to other solutions?
My first step is to try to figure out which of the various avenues is going to cost less. (And a secondary, but non-trivial concern, is then to convince the customer that just because they have heard of a buzz word like 'enterprise bean' that it doesn't mean that is a cost effective solution.) We must come from different worlds. -
Reflection - reading a .class file
I want to read in a .class file, and be able to use reflection to get a list of that class's methods. I'm using a JFileChooser to find the file, I just need to know how to use the output from the JFileChooser (a path to the file) to load the file into the program, and use reflection methods to create an appropriate Class object.
kajbj wrote:
fredley_m wrote:
kajbj wrote:
fredley_m wrote:
I don't think I'm making myself clear. I can read in a file, I don't know how to use reflection on a .class file. I need to know how to complete the following line of code:
Class reflectedClass =reflectedClass should then contain a copy of the class from the .class file.You load a class using Class.forName(..)This does not work.
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(main_panel);
if(returnVal == 0)
String fileName = fc.getSelectedFile().getName();
fileName = fileName.substring(0,fileName.lastIndexOf('.')); //also doesn't work without this line
Class c = Class.forName(fileName);
...I get a ClassNotFoundException when I try to open MyClass.classYou need to know about how class loaders work, and use one. Read the javadoc:
[http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html]
The NetworkClassLoader sample is pretty close to what you want.Thanks, the URLClassLoader is perfect, however my code:
String fileName = fc.getSelectedFile().getName();
fileName = fileName.substring(0,fileName.lastIndexOf('.'));
URL[] urls = {new URL(filePath)};
URLClassLoader cl = new URLClassLoader(urls);
Class c = cl.findClass(fileName);does not compile: "findClass has protected access" -
Hello all,
I'm writing a ClassLoader and the funniest things are happening. If I load a compiled class for the first time after compilation everything is ok. Once I change the class and recompile it, it starts putting out java.lang.ClassFormatError: (Truncated class file). If I alter the changes back to normal and recompile. It works again. Is there some sort of buffer which keeps the once loaded class in memory, even after rebooting?
Please help, I'm at a loss
Gideonhi dmbdmb,
I got following error when try to run a java code in JBoss.
15:39:56,696 ERROR [LogInterceptor] Unexpected Error:
java.lang.ClassFormatError: Thilina (Truncated class file)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
at com.sun.tools.javac.v8.StringCompiler$Loader.findClass(StringCompiler
.java:63)
at com.sun.tools.javac.v8.StringCompiler.executeMethodWithReturnType(Str
ingCompiler.java:120)
at cc.aot.qVoice.domain.ejb.qVoiceManager.qVoiceManagerEJB.getVxmlString
(qVoiceManagerEJB.java:125)
I use JBoss 3.0.6 and sdk 1.4. In my program, classes are create and load on the fly. Then using Reflection API I called some
methods in the dynamically created class(this class not
write into a file and it is taken as a String variable).
I refferd this url as a guid to write class loader and compiler.(actually same thing i copied
from there and change it's name Pmat1 to StringCompiler)
http://forum.java.sun.com/thread.jsp?thread=347467&forum=4&message=1439418
When I run this as a normal application, it is work well. Then I try to run it in a jboss and it will give the above error.
In here I Wote some EJBs and struts also and i called the methodds in the StringCompiler(Pamat1) class in a EJB. Thilina is
the name of the dynamically created calss and StringCompiler is the class that includes the class loader and compiler methods
as in the above url. qVoiceManagerEJB has a getvxmlString method. Whithin this method
i called required the methods in the String compiler.
Can u some body help me. Thanx in advanced for any help.
anjithalb -
Win xp not opening class file.
win xp not opening class file.
Runtime.getRuntime().exec("cmd /C start c:/database/Myclass.class");
or
Runtime.getRuntime().exec("cmd /C c:/database/Myclass.class");
is this code wrong for xp ?let me give some more information...
i have c:\database
in this folder i have 2 class...Myclass.class and Dbconnection.class
Myclass simply uses the database connection from Dbconnection.class , nothing else.
you see both of the classes are in the same folder(i.e c:\database) and there is no package
statement inside the code .
in command prompt if i do....
c:\database\java Myclass // this works fine
but i want this class to run at runtime, so i did like above and it is not running!!
what i am getting is a irritating windows file chooser is poping up and saying "class not
found...browse or search in web...etc etc"
Now my question is >
Q1 . how can i run that class at runtime ?
N.B
here is some brief idea abt classes
Dbconnection.java
DriverManager.forClass("...database....");
// only for database connection
Myclass.java
Connection con =db.getConnection();
//use this con and show results for ur database related queries.
}Q2. Can u plz tell those correct syntax how to run class file in this situation ?
i will try all possible solutions tomorrow.
thanx. -
How to create a Jar with only class files?
Dear all,
I want to create a jar file with only classes.My class files and java files are in different folders under com .
say
com
in com there are two folders
folder 1 -- subfolder 1
folder 2 -- subfolder 2
like this.
If i want to create a jar file from com directory how should i give the jar command.Again my jar should contain only .class files.
Any help will be appreciated
Thanks
lekshmiIt doesn't work.Says "No such class or directory"
Any other way Or is it possible to do so?Read the link I posted and create the statement to make your structure. I was thinking you were inside the com directory but if you are above it you will need something like this instead:
jar -cf test.jar com\*.class com\subfolder1\*.class com\subfoler2\*.class
But either way don't just copy and past this. Think about what is does so that you can make it work for you.
Also, you might want to look into using Ant if you are going to be building this a lot. -
I have placed my jar file in c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jar
But, after restarting tomcat6, when i try to import the class file contained in the myjarfile.jar in a servlet, it says
ProcessFileUpload.java:4: package test.test1 does not exist
import test.test1.*;
^It clearly tomcat's class loading problem.
As i unzipped my jar and placed the packagefolder structure to
c:\tomcat6\webapps\my-application\WEB-INF\classes\testand it works perfectly.
Anyone knows its workaround? please suggest if any configuration changes is required in tomcat or so.
Thanks.
---SujoyThank you gimbal2 . There was error in creating the jar file myjarfile.jar.
But, now I have created it again and placed it in place
c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jarand tried to use one on the Class file included within the jar to compile my servlet. But, still I am getting error at servlet compilation time. I want to place executable jar files in
c:\tomcat6\webapps\my-application\WEB-INF\lib\myjarfile.jar and compile my servlet and execute the servlet.
I DO NOT WANT TO unzip the jar, placing all unzipped files to
c:\tomcat6\webapps\my-application\WEB-INF\classes\ folder and comiple my servlet and execute the servlet. But, I am failing to user WEB-INF\lib\ folder facility....please help me why i am not getting class files from WEB-INF\lib\ folder.
If you please see the small code bit and tell me any possible error that would be very helpful.
Step 1: my library java file MyClass.java
package test.test1;
public class MyClass {
String myName = "Default return string value";
public void setMyName(String varName) {
this.myName = varName;
public String getMyName() {
return this.myName;
}Step2 : Creating jar file of my library class files
C:\jdk1.6\bin>jar cvf myjarfile.jar test
added manifest
adding: test/(in = 0) (out= 0)(stored 0%)
adding: test/test1/(in = 0) (out= 0)(stored 0%)
adding: test/test1/MyClass.class(in = 452) (out= 296)(deflated 34%)
adding: test/test1/MyClass.java(in = 230) (out= 140)(deflated 39%)
C:\jdk1.6\bin>Step3 : Double checking the created jar file content by listing its content
C:\jdk1.6\bin>jar tf myjarfile.jar
META-INF/
META-INF/MANIFEST.MF
test/
test/test1/
test/test1/MyClass.class
test/test1/MyClass.java
C:\jdk1.6\bin>Step4 : Placed myjarfile.jar to
c:\tomcat6\webapps\my-application\WEB-INF\lib\Step5 : Restarted standalone Tomcat6 in my Windows XP SP2.
Step6 : Created a simple servlet LibFolderTest.java within my-application\WEB-INF\classes\ folder with code
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import test.test1.*;
public class LibFolderTest extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
MyClass mc = new MyClass();
out.println(mc.getMyName());
}Step7 : Tried to compile my servlet LibFolderTest.java and got the following error
LibFolderTest.java:4: package test.test1 does not exist
import test.test1.*;
^
LibFolderTest.java:11: cannot find symbol
symbol : class MyClass
location: class LibFolderTest
MyClass mc = new MyClass();
^
LibFolderTest.java:11: cannot find symbol
symbol : class MyClass
location: class LibFolderTest
MyClass mc = new MyClass();
^
3 errorsThe above servlet compilation error on Step7 is telling me that myjarfile.jar is not loaded by Tomcat6 or not available for use when compiling servlet. I want to use myjarfile.jar from within WEB-INF\lib\ folder but I can not. please help.
---Sujoy -
Problem with:error: java.lang.ClassFormatError: Truncated class file
Hello, I created an simple applet writing "hello world". Now I would like to add *.class file to my serwer witch I've implemented on microcontroller P89C51RD2BN.
Serwer is programmed with hex file which is created after compiling C source files. In this case I converted .class file to array in C (using hexedit program). When I am (using IE ) browsing my serwer Html site is loading corectly and *.class file is send from serwer also corectly (define arrays are transfered corectly) but applet is not initiated. When I am runnig Java console I can see this:
error: java.lang.ClassFormatError: Truncated class file
When I am runnig the same site with the same class file on my PC everything is ok.
I would be greatfull for any help. Thx. (sorry for my English :P )Not too familiar with native compilation, which I believe you are trying to accomplish here. It would appear that you don't have any problems running your applet, more or less running it after being converted to legacy code. Try the "native methods" forum under "Fundementals/Key Classes", this may be helpful. Sorry for not being too helpful.
-
How can I run a a class file on the Apache server?
Hi Guys and Gurus,
I am seeking some favor all of experienced gurus, i.e.
How can I run a a class file on the Apache server?
Actually, I want to extract some records from a MySQL Database running on Apache Server. I wrote a program just to select the columns and show them. It is now a Class file, Now how can I run this class file from the Server???
Please advise...
VJcross posted
http://forum.java.sun.com/thread.jsp?thread=299137&forum=31&message=1184025 -
Java.lang.ClassFormatError: Truncated class file
Hi
Previously my application is running on jdk 1.4 and its supporting castor i.e. castor-0.9.5.4-xml.jar
Now i had upgrade my jdk to 1.6 and i am using same castor.jar
so it is giving me following error
Exception in thread "main" java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at com.sun.tools.javac.v8.GenerateClass$Loader.findClass(GenerateClass.j
ava:273)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.exolab.castor.mapping.loader.Types.typeFromName(Types.java:93)
at org.exolab.castor.mapping.loader.MappingLoader.resolveType(MappingLoa
der.java:228)
at org.exolab.castor.mapping.loader.MappingLoader.createDescriptor(Mappi
ngLoader.java:394)
at org.exolab.castor.xml.XMLMappingLoader.createDescriptor(XMLMappingLoa
der.java:202)
at org.exolab.castor.mapping.loader.MappingLoader.loadMapping(MappingLoa
der.java:258)
at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:291)
at org.exolab.castor.mapping.Mapping.getResolver(Mapping.java:246)
at org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:520)
I also try to upgrade castor to latest version i.e castor1.2-xml.jar with jdk 1.6 and this time it gives me error
Exception in thread "main" java.lang.ClassFormatError: Truncated class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at com.sun.tools.javac.v8.GenerateClass$Loader.findClass(GenerateClass.j
ava:273)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.exolab.castor.mapping.loader.Types.typeFromName(Types.java:92)
at org.exolab.castor.mapping.loader.AbstractMappingLoader.resolveType(Ab
stractMappingLoader.java:384)
at org.exolab.castor.xml.XMLMappingLoader.createClassDescriptor(XMLMappi
ngLoader.java:209)
at org.exolab.castor.mapping.loader.AbstractMappingLoader.createClassDes
criptors(AbstractMappingLoader.java:262)
at org.exolab.castor.xml.XMLMappingLoader.loadMapping(XMLMappingLoader.j
ava:156)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmars
haller.java:162)
at org.castor.mapping.MappingUnmarshaller.getMappingLoader(MappingUnmars
haller.java:128)
at org.exolab.castor.xml.Marshaller.setMapping(Marshaller.java:556)
Can any one please help me out..
Thanks in advancehi,
i think one of application's class file currupted , Recompile all java files and then try.
Edited by: sagar_birari on Mar 27, 2008 5:47 AM
Edited by: sagar_birari on Mar 27, 2008 7:20 AM -
Can JAVA import 3D Max Studio files?
I'm currently doing a research for my final project. The tittle is "Comparison Between JAVA 3D and Macromedia Director". Director can import 3D Max studio files, and i do not know whether can JAVA import 3D max Studio files? Pls help.... thanks
have a look at www.j3d.org , they have several different importers for 3d model file formats and might have one suitable..
-
How can I import not only apps from the old iphone to the new iphone, but also the content of the apps?
You can sync apps as you normally would, but I do not believe this copies over app specifc data (i.e. saved game status/scores).
You can always restore your new device with a backup from your old device. -
How do I get the java code from a class file ?
I want to know how to findout the java code from a .class file . Is there any utility or any way to get the java code from a .class file. If so , please let me know the step by step procedure .
Thanks
ShivaCheck out Mocha (http://www.brouhaha.com/~eric/computers/mocha.html)
It's free! -
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
Maybe you are looking for
-
Mail and keychain problems when upgrading to SL
I have tried twice to upgrade to SL from 10.4.11. Initially everything is smooth as glass, fast, no issues at all. After I open mail everything works fine. After closing mail; the next time I open it and try to get mail the little boxes asking for my
-
How do i delete all information of my card details from my apple id
hello, so when i tried to buy something the other day on the app store it told my my card was declined so i needed to re enter my card details, in doing so it then told me: your payment method was declined please enter another payment method. so i th
-
Electronic signature in merged documents?
I am trying to create a new document using multiple files. Some of these files contain electronic signatures. Can the electronic signatures be preserved in the merged document?
-
New User - Cannot select drum kit loops
Hi, I am a trying out GarageBand for the first time and having a lot of fun. However I was following one of the Apple tutorials where I clicked on song writing and had a basic drum track. The tutorial said if you don't like the drum track you can del
-
[WORKED-AROUND]video files not playing
Hi archers, upgraded my system today & now it refuses to play video files in vlc I get the following output: VLC media player 2.1.5 Rincewind (revision 2.1.4-49-gdab6cb5) [0x8541f8] main libvlc: Running vlc with the default interface. Use 'cvlc' to u