Getting classes in package
Hello,
I have a problem with getting some external classes into my package.
To get a better view over the situation I'll show it as an example:
the class "Zoo" is in the directory: town/district1/
with the follwing content:
package town.district1;
public class Zoo{
Elephant elephant1 = new Elephant();
Ok, my Elephant-class is in directory "pets", pets and town are in the same directorylevel.
Elephant has the following content:
public class Elephant{
//some elephant stuff here
so, from the root-directory of my package structure it looks like:
town/distric1/Zoo.java
pets/Elephant.java
Compiling Elephant is no problem, but if I try to compile Zoo, I keep getting the error:
"cannot resolve symbol", means the compiler doesn't find the Elephant-class. I tried to set several combinations of the -classpath switch to javac, but it still doesn't work. Please note that it is not possible to add package information to the Elephant-class, they have to be kept as they are, modifying the Zoo-class is no problem, as long the package-information is kept.
I would be very happy if there was someone to help me there. Thanks in advance..
Going back to your first post, Elephant is in the pets directory so the path to that directory needs to be in the Classpath. Since Zoo's fully qualified name is town.district1.zoo, the directory that contains the town directory must ALSO be in the classpath.
Lets say you have c:\animals\town\district directory and you have c:\animals\pets\Elephant.class file.
To compile Zoo: javac -classpath c:\animals\pets Zoo.java
Also, Zoo must contain the line "import Elephant:"
I tried this on my system - it works.
public class Elephant {
public static void main(String[] args) {
System.out.println(args.length);
package town.district1;
import Elephant;
public class Zoo {
public static void main(String[] args) {
Elephant e=new Elephant();
Similar Messages
-
How do I get class in the javax.* package
How do I get class in the javax.* package
If possible don't mess with the javax Package
I mean I could not get the advantage of getting a class under javax Package
But for information
make a folder named javax
Make your class in that folder with starting code as
package javax;and then compile it and make a jar file and add it to classpath
It is very simple
But I think you should not mess with it
Is there any special requirement?
Bye for now
CSJakharia -
How do i put classes in package in NetBean Environment
Hello,
I install NetBean IDE for developing website using JSP and Servlet. I am using Internal Tomcat provided by this IDE.
Problem is this i put java classes in the Class folder of Web-INF folder, but i am not able to access these classes from JSp page.
I try to put these classes in Package but even though i use package option IDE does not put classes in the package.
I am using internal compiler provided by this IDE for compiling java class' source file.
What should i do, please help me
Thank youhai
i have the same problem to finding the classes in package...
in my case i know the jars name and i have loaded
classes using code
ResourceBundle bundle = ResourceBundle.getBundle("source\\ClasssPath");
StringTokenizer stToke = new StringTokenizer(bundle.getString("ClassPath"),";");
String temp;
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
while(stToke.hasMoreTokens())
temp = stToke.nextToken().trim();
if(temp.endsWith(".jar"))
JarFile jar = new JarFile(new File(temp));
Enumeration en = jar.entries();
String pathStr;
while(en.hasMoreElements())
pathStr = en.nextElement().toString();
System.out.println("pathStr ="+pathStr);
if(pathStr.endsWith(".class"))
System.out.println( classLoader.getResource(pathStr));
System.out.println(classLoader.loadClass(pathStr.substring(0,pathStr.indexOf(".class")).replace('/','.').trim()));
else classLoader.loadClass(temp);
here i am getting the classes in that package using code
String[] filLis = new File("//it//sella//converter//ptlf//startup//").list();
int length = filLis.length;
while(length-- >0)
System.out.println(">"+filLis[length]);
but its returnign the class when this classes in locale folder(i.e)its not getting the classes in loaded memory...
so how to retrieve the class files names using package structure name...
(i am having more then 20 jars files, inthat inside the jar samepackage structue may appear in more then one jars )
pls help me in this field..
Thanx -
Classes without packages not accepted by ejbc compilation ?
Hey guys ...
I noticed something which I found unusual...I mite be missing something out here
When ejbc generates the Bean IMPL class , it does not put any import statements
in the generated java file but references all the classes in the Bean with their
absolute path ...
Now ..I have a 3rd-party jar which does not have certain classes in packages...and
I reference these classes within my Session Bean...the session bean compiles properly
..but when ejbc happens and the Impl class gets generated with the absolute path
and no imports...the compiler expects to find all these 3rd-party classes without
packages within the current session bean package itself which it will not..and
hence throws all sorts of "cannot resolve symbol" errors...
Does this mean that within my EJB beans I can never reference classes without
packages or is there something I am missing..?
Thanx,
KrishRob ,
I agree with u that giving classes without package is not a good practise..but
Itz got a history which believe it or not stems from another weblogic problem(related
to webservices..)
anywayz..that is another issue alltogether...
I don't think this bug is fixed...coz I checked a WLS70 Impl and it is still generating
the IMPL without the imports...
But can u clarify..what u wud mean by "fixing the bug" ..does it mean that the
Impl would start putting the imports..?
Thanx,
Krish
Rob Woollen <[email protected]> wrote:
I recall this bug being reported before. You might try the latest
service pack and see if it's been fixed already. Otherwise, you'll have
to contact [email protected]
FWIW, it's quite disturbing that a 3rd party would give you a jar
without a package.
-- Rob
Krishnan Venkataraman wrote:
Hey guys ...
I noticed something which I found unusual...I mite be missing
something out here
When ejbc generates the Bean IMPL class , it does not put any import
statements
in the generated java file but references all the classes in the Bean
with their
absolute path ...
Now ..I have a 3rd-party jar which does not have certain classes in
packages...and
I reference these classes within my Session Bean...the session bean
compiles properly
..but when ejbc happens and the Impl class gets generated with the
absolute path
and no imports...the compiler expects to find all these 3rd-party
classes without
packages within the current session bean package itself which it will
not..and
hence throws all sorts of "cannot resolve symbol" errors...
Does this mean that within my EJB beans I can never reference classes
without
packages or is there something I am missing..?
Thanx,
Krish -
hellow, i have a web aplication named test , and i have a class named conexion
when i import a package "pack" with the class conexion, not problem (test/WEB-INF/classes/pack/conexion.class) <% import="pack.* " %> but when i have only the class conexion WITHOUT package (test/WEB-INF/classes/conexion.class) and i import <%import ="conexion" %> i have problem ("The import conexion cannot be resolved") and when i not import the class i have problem (conexion cannot be resolved to a type) , my question is:
how to i import a class without package in JSP , and if the test/WEB-INF/classes is in the classpath when compile the servlet , why the tomcat not found the class conexion?
(tomcat 5.5.20 , jdk 1.5.09 , vim)
thank
(Sorry my english , i'm from Chile)Hi I am hosting my JSP application with Resin 2.17 which uses classes directly in JSP code (not packages). To make this work I had to specify the classpath in Resin.conf and it worked.
My problem is getting this to work with TomCat or any other application server that will allow me to debug my project in Eclipse or NetBeans IDE. (I have yet to find an IDE that Supports debugging JSP/Java code running on Resin - so I want to switch my application server but I am not sure how to configure my classpath for the application servers to look for java classes in the specified directory just like I did with Resin. -
Referencing classes outside package definition
Hi,
I have a strange problem, and I dont know if its a limitation of Java or my IDE (Intellij IDEA using java 1.4.1).
Basically I have a package structure
/classes/com/foo/MyClass.java
now from MyClass, I want to access another class file AnotherClass.java that has no package structure (and I can't change this). So I copied it to the /classes directory.
However, when I try to compile I get a "cannot resolve symbol" error. The IDE wont let me put "import AnotherClass" in the import section.
I'm confused! can anyone help? All I'm trying to do is reference a class "backwards" from the current package
cheersThe proprietry dll I have has already been compiled,
and has a reference to a Java class that performs the
appropriate JNI call. Thsi jva class has no package
structure.Well, then yes I'd suppose you are painted into a corner. Looks to me the no-package class should have been put into a package in the first place, as now you cannot reference that class from other classes that are in packages. Back to what I said earlier, writing classes without packages is a "bad" practice. -
Error "expected a myfaces custom component class in package"
Can anybody help me on this?
just copied the sandbox code on selectmanypicklist and tried in a separate package of mine.
created a jsp page and used the selectmanypicklist component and im getting the component on my browser.
But whn i added the javascript resource calling by "encodeJavascript(facesContext, uiComponent);" im geting an error saying tht "expected a myfaces custom component class in package org.apache.myfaces.custom". i placed the java script file in "mypackage/list/resource/pikscript.js".
should i add anything on faces-config.xml file or anywhr else?
Anybody can help on this?
Thanx in Advance.The problem is that it calls a method validateCustomComponent in MyFacesResourceHandler to see if it can load the js file. This method controlls if the path of the js file begins with org.apache.myfaces.custom. If not throws an exception and doesn't load the file. I changed the package of the class that's trying to load the file in org.apache.myfaces.custom.xx and the package of the file js in org.apache.myfaces.custom.xx.resource. Now it's working.
-
Running Class in package?
I have problem running class in package. What do I write (win) to make the class in a packege run? If I remove it from the package I just write: java MyClass.
If it is in package com.bananaco, for example, then at
the command line you must type
java com/bananaco/MyClassI'd refrain from calling it that way, as it leads to confusion.
The standard way is to call it fully qualified
java -cp <classpath> com.bananaco.MyClass
under any JAVA release with the classpath set appropriately (rename <classpath> with yout path to directory where com is located in exmpale above).
Take in mind that the directory structure should reflect the package structure (having MyClass.class under com/banaco in the class path)
Oliver
>
That works for Java 2, but I sort of recall that for
Java 1 you had to use
java com.bananaco.MyClass
instead. So try both. And if you get NoClassDefFound
error, remember that the package has to be in
your classpath, not the class. -
Getting Class instance of a class
Dear Friends,
I need to get Class instance of a class in my project. Inorder to use the reflection API 's the package name of the class is needed , but it may not be available Only available thing is the name of the class file and the location where that file is existing .
Please suggest some method to get Class instance in this situation.
Shaiju.PYou can create a ClassLoader of your own. There's a simplified example in this thread (reply number 6):
http://forum.java.sun.com/thread.jsp?thread=538836&forum=31 -
How to organize j2me classes into packages?
Hello!
I'm using Wireless Toolkit 2.5.2 and I have got a question about it.
Does anybody know, how to organize j2me classes into packages?
As far as I know, all source files should be placed inside WTK_home_directory\apps\my_project\src folder.
Although it is possible to create arbitrary folder structure (for example, src\com\my_company\www\my_package) and successfully compile the project,
it's not possible to run it on the emulator or any target device. Trying to do it, I get ClassNotFound exception.
It's not surprisingly, because virtual machine on the device doesn't know, where to look for desired classes.
So the question is how to add new entries to the device classpath (of course, if it exists)?
And is it possible to configure it through application descriptor (jad) file somehow?
Any ideas, references, descriptions?
Thanks in advance,
A.Hello!
So, I have found the solution and this question is not actual any more.
The solution is quite simple - you have to properly configure application jad-file.
It can be done like this (in ktoolbar):
1. Open project settings from main menu (Project - Settings).
2. Then go to MIDlets tab.
3. There you have to change value in "*class*" column (for example, to smth like this - com.my_company.www.my_package.my_midlet_class_name).
4. Press Ok button.
Having done these steps, you will be able to have any package structure you need
(because after it AMS on the device will know where to look for your application class files).
A. -
Revision: 11341
Author: [email protected]
Date: 2009-10-30 16:24:35 -0700 (Fri, 30 Oct 2009)
Log Message:
Added some unit tests to get the metadata package above 80%
Modified Paths:
osmf/trunk/framework/MediaFrameworkFlexTest/org/osmf/metadata/TestTemporalFacet.asThe nature of the Media class is that it accesses it asynchronously. This means that when you create an instance of it, and then immediately query it, the data you want may not be available yet. This is all in the Javadoc, see the doc for Media:
The media information is obtained asynchronously and so not necessarily available immediately after instantiation of the class. All information should however be available if the instance has been associated with a MediaPlayer and that player has transitioned to MediaPlayer.Status.READY statusSo you could associate the Media with a MediaPlayer, and then wait until it goes to the Status READY, and then read the length of the Media.
As for your 2nd question, getMetadata() returns a Map. You can just loop through it:
for(Map.Entry<String, Object> entry : media.getMetadata()) {
// etc
}However, the same restrictions apply as with Media -- you will probably need to wait before the information is available -- that's why the Listener approach works, because it will notify you as soon as the information is added to the map. -
Getting class names in jconsole
Hello,
Is it possible to get class names which are loaded in the memory using jconsole?
I am using jdk 1.5. I have configured jmx in my Weblogic 9.2.
I am able to find the memory usage by the application, but i dont know how to get those class names in jconsole.
Regards,
SampathHi,
we ckeck all the class names in package.
first goto se80.select package and give package name and click on display button.it will display all the structures,classes which are assigned to that particular package .in that select class it will expand and displays all the names.
Cheers,
vasavi.
kindly reward if helpful. -
Undefined variable, class, or package name
The following code in the jsp is supposed to display the correct 'Securities' link based on the app_main_frames URL. I am getting an error. Can anyone help?
<% if (parent.app_main_frame.location == ("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) { %>
Securities
<% } else { %>
<a href="/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none
target="app_main_frame">Securities</a>
<% } %>
I am getting the following error:
Generated servlet error:
/opt/JBoss-2.4.4_Tomcat-4.0.1/catalina/work/localhost/cgi-java/common/jsp/NavigationMenu$jsp.java:173:
Undefined variable, class, or package name: parent
if (parent.app_main_frame.location ==
^
("http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")) {If app_main_frame is a frame in a frameset then you cannot
simply refer to it in a Java scriptlet.
You can refer to it in a JavaScript script, like this:
<script>
if (parent.app_main_frame.location == "http://ccmsun57.ccminvest.com:8080/cgi-java/Allocation/jsp/scenario.jsp?source=init")
document.write("<a href=\"javascript:submit_Form('none')\"target=\"app_main_frame\">Securities</a>");
else
document.write("<a href=\"/cgi-java/Holdings/jsp/SecurityInventoryQuery.jsp?which_search=none&which_category=none\"target=\"app_main_frame">Securities</a>");
</script> -
How to call my own class in package B from a servlet in package A?
Hi, I am trying to call a class in my serlvet, but the class is in a different package than my servlet, i.e., my servlet is in package A, and the class my servlet calls is in package B. I created a .jar for all files in package B, put the jar file in %JAVA_HOME%/jre/lib/ext, and set classpath to %JAVA_HOME%/jre/lib/ext. I can compile my servlet, but when I run it with Tomcat 4.0, it says that the class in package B is not defined (NoClassDefinitionError).
Can anyone help? Thanks a lot.I set JAVA_HOME to c:\j2sdk1.4.0.
All classes in package B are in one jar file, and all classes in package A are under CATALINA_HOME\webapps\ROOT\WEB-INF\classes. Do I need to create another jar file for package A or should I put package A in the same jar file as package B?
I tried to put the jar file under WEB-INF\lib, but it still failed.
The project is the first time for me to use servlet, so I am not very familiar with it. I am wondering if there is any configuration file I need to modify for the servlet I wrote?
Thanks for the help. -
When i go to unistall i get, this pack package can not be open.Verify
that the pack package exists and that u can acess it.Or contact the application
vendor, to verify that this is a valid windows installer patch package.I am using a new hp laptop that is running windows 7
Maybe you are looking for
-
Satellite A660 - DVD drive will not recognise some DVDs
I have a new Satellite A660-17E with a HL-DT-ST DVDRAM GT30N drive, running Windows 7 64 bit. The drive will read most DVDs. Commercial DVDs (region 2) are fine. However, there are problems with DVDs recorded using DVD recorders. DVD+R recordings usi
-
Problem to install Oracle 9i on Redhat 7.1
Does anyone has succes to install 9i database on RedHat 7.1 ? My installation failed in LINK (ins_sqlplus.mk)
-
Need help with embedded SWF in PDF as navigation
Hi, I was wondering is there a way to have an embedded swf navigate to different pages of a pdf? Example: My swf is on page one. There are mulitple buttons in the swf, when clicked it will take you to page 3, or 5, or 7, etc. Currently, when I click
-
Wireless All in one not printing
I have a HP all in one model cc335a on a wireless connector that runs on a dsl line. I am on a network with my lap top and main desk computer. The printer acts like it is printing and kicks out a blank sheet. I have reinstalled it a couple of time
-
Limit on the number of panes?
I have a situation where I need to add more than 9 panes on a given form. I can show up to 20 or more, but the user can only select up to and including the 9th pane. Any time they try to select the 10th pane on, the pane is not selectable. Is this