Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-05-2007, 02:17 AM
Member
 
Join Date: Nov 2007
Posts: 4
splinter64uk is on a distinguished road
Importing / compiling and running with .jar package
Hi,

I'm getting really confused trying to use an add-on package. I have a .jar file containing the classes and I have the import statement referencing it. However, every time I compile and run do i need to use the -cp switch and specify the path of the jar? Seems like a lot of typing when the .jar file is in the same directory.

I've also tried organising my own project into packages but the files wont compile (I get a package does not exist error even though the package is defined using the package statement). Any tips/ good tutorials on this?

Cheers.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-05-2007, 03:47 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Yes you have to do -cp, otherwise java wont know where to look for your classes.

When you compile a package, you should make sure that you have the right structure:
Code:
package com.examples;
That means that your structure would be:
Code:
|-src |-com |-example |-Test.java |-Other.java
so when you compile, you would cd to the src folder, and type
Code:
javac com.example.Test.java
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running main in a package... Bizmark New To Java 1 04-07-2008 02:58 PM
Need help with importing classes Deathmonger New To Java 3 02-07-2008 11:03 AM
Compiling and running code in runtime tim New To Java 4 01-27-2008 07:58 PM
Compiling a class in a package from cmd Java Tip Java Tips 0 12-17-2007 11:27 AM
Importing package bugger New To Java 5 11-26-2007 01:29 PM


All times are GMT +3. The time now is 08:15 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org