473,666 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help linking & packages

If I try to access another jar files default package I have no
problem. When I try to access anythig else i.e. package com.mine.thing,
I always get the not found message.

What special thing do I need to do to make it work?
package a.b.c.*;

import Another.*;
class Test {
System.out.prin tln ("Hello World");
try {
Class.forName(" another/Thing");
// Class.forName(" Stuff");
}
catch (ClassNotFoundE xception ex) {
ex.printStackTr ace();
System.out.prin tln ("Good bye Cruel World");
System.exit (-1);
}

}
for this class Stuff works but another/Thing is another thing.

Any ideas?

Thanks for your time.
Aug 14 '07 #1
3 2464
Doug Robinson <dk*****@XXXtel usplanet.netwro te:
>If I try to access another jar files default package I have no
With the exception of "sealed packages", jars and packages are unrelated.
Jars can contain classes from multiple packagages, and classes in the same
package can live in multiple jars.

There is no "default package" for a jar. There is the or un-named package
that can have classes in it, but generally you shouldn't use it as it's a PITA
to mix named and un-named packages.
>package a.b.c.*;
* isn't a valid package name for this class.
>import Another.*;
This will make short names used in java code search the Another package for a
match. It's just a coding shortcut, and has no effect at runtime (it
doesn't even end up in your .class file). Since you have no java references
to any class, it will have no effect.

Oh, and by convention packages should start with lower-case letters. Classes
start with a capital. And it does matter - names are case-sensitive.
>class Test {
System.out.prin tln ("Hello World");
try {
Class.forName(" another/Thing");
Class names don't have slashes in them. They have dots to separate package
elements and to separate package from classname. Packages and classes are
case-sensitive, too, so "Another" and "another" are different. Try
Class.forName(" another.Thing") . Since this is a method call rather than java
code to be compiled, the imports have no effect and you must pass in the
fully-qualified classname.

But really, there's no reason to do this for most programs. Class.forName()
is only needed if you don't know when writing the code what the class name
will be.

You should just do:
Thing t = new Thing();
/* or whatever. If you haven't imported another.* or another.Thing,
you can say another.Thing t = new another.Thing() ; */
>// Class.forName(" Stuff");
This is an example of trying to use the unnamed package to look for Stuff.
Getting that to work is unfortunately complicated, and you should just avoid
having classes without a specified package name.

Good luck!
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Aug 14 '07 #2
You should just do:
Thing t = new Thing();
/* or whatever. If you haven't imported another.* or another.Thing

you can say another.Thing t = new another.Thing() ; */

// Class.forName(" Stuff");

This is an example of trying to use the unnamed package to look for
Stuff. Getting that to work is unfortunately complicated, and you should
just avoid having classes without a specified package name.

Thank you for your response!

I am well aware of all of the things you say. but but but...

The recomended way to "connect" to say a jdbc driver is indeed

Class.forName(" driver.package. ..");

and in no way was I recommending the use of the "unnamed package" just
that I CAN "connect" to jars that contain one.

However I still can not make any reference to a "package" work in this
fashion.

Thanks again for your time & effort!

dkr
Aug 15 '07 #3
Doug Robinson <dk*****@XXXtel usplanet.netwro te:
>Thank you for your response!
I am well aware of all of the things you say. but but but...
>The recomended way to "connect" to say a jdbc driver is indeed
Class.forName( "driver.package ...");
Ah, yes. JDBC driver loading involves certain tricks where a driver registers
itself when the classloader first loads the class. Knowing you're having
troubles with JDBC rather than general java package questions is helpful.
>However I still can not make any reference to a "package" work in this
fashion.
Then it's time to get specific. Show us a small self-contained example, and
the output you get when you run it. A single class with a main(String[]) that
loads the driver should be sufficient.
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Aug 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2983
by: RJS | last post by:
Hi all, I can't get a py2exe compiled app to run with numarray (numarray-0.5.win32- py2.2). Also wxPythonWIN32-2.3.3.1-Py22 and ActivePython-2.2.1-222. In the sample below, commenting out "import numarray" allows the exe to run. Left in, I get "4.exe has generated errors" etc. I'm going around and around and there isn't much on Google. py2exe output is last.
7
6548
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with LIBCMT(D).DLL. (My requirement is that we can't link with MSVCRT(D).LIB.) Below are steps I've followed, and the resulting problems 1. Using the New Project wizard, generate a Visual C++ .NET Class Library project (call it "Doomed") and a VC++...
10
2261
by: mark | last post by:
I have this class: class Selections { OSStatus Init(); protected: CFMutableSetRef selectionObjects; static void CFASelectionsApplier(const void* value, void* ctx); OSType ready; public: Selections();
0
2188
by: venkatbo | last post by:
Hi folks, I'm trying to get lighttpd, fastcgi & python working on a 2.4.21.x i686 linux system. I tried following the steps in: http://www.cleverdevil.org/computing/24/python-fastcgi-wsgi-and-lighttpd Some of the lighttpd.conf setting are slightly different from those in that article - fixing some erros in the original and accounting for some change in entry formats itself.
1
7701
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML special characters such as < > into the corresponding character entities. I'm working with Java.
1
5954
by: srikar | last post by:
what is the difference between static linking & dynamic linking, what are the advantages of each? How to perform static linking & Dynamic linking by using gcc -o liniking will be done , but how can we control the type of linking Hi any one please help me to clarify my doubt
2
2725
by: pssraju | last post by:
Hi, At present application was built on solaris 9 using sun studio 9 (Sun C++ 5.6) & rouguewave sorce pro 5. We are planning to port the same application onto SuSE Linux 9.5.0 using GCC 3.3.3 & RW source pro 9. My application heavily uses RW tools through wrapper classes on the top existing RW classes. RW libraries were built using gcc on linux platform and standalong RW examples are working fine. Since the application compilation is moving...
0
7183
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
3
3204
by: dpholmes | last post by:
hi everyone, i'm very new to python and to this forum. i'm actually just trying to work through the tutorial on webpy.org. so far, so good, but as i tried to incorporate a postgresql database into the demo web app i'm receiving this error print out: Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/web/wsgiserver/__init__.py", line 624, in communicate req.respond() File...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.