Results 1 to 2 of 2
  1. #1
    splinter64uk is offline Member
    Join Date
    Nov 2007
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    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:
    Java Code:
    package com.examples;
    That means that your structure would be:
    Java Code:
    |-src
     |-com
      |-example
       |-Test.java
       |-Other.java
    so when you compile, you would cd to the src folder, and type
    Java Code:
    javac com.example.Test.java

Similar Threads

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •