Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7888637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:52:59+00:00 2026-06-03T05:52:59+00:00

I created the following class located in the MainJPrint.java file import com.XXXXX.pdfPrint.PDFPrint; public class

  • 0

I created the following class located in the MainJPrint.java file

import com.XXXXX.pdfPrint.PDFPrint;

public class MainJPrint
{
   public static void main(String[] args) 
    { 
        //System.out.println("Hello World!"); 
        print(".....");
    }   
    public static String print (final String url)
    {
        Object rc = AccessController.doPrivileged(new java.security.PrivilegedAction() 
        {
            public Object run()
            {
                 ...
            }
         }
    }
}

In the same folder I have a jar archive jPrint.jar
I compile the class using the following command

>javac -classpath jPrint.jar MainJPrint.java

When I’m trying to execute resulted class file, I get this error:

>java MainJPrint    

 java.lang.NoClassDefFoundError: com/XXXXX/pdfPrint/PDFPrint

If I uncomment the Hello World line and comment the next line, the program runs fine.

I’m using j2sdk1.4.2 installed at C:\j2sdk1.4.2.
I do also have installed other java versions (at C:\Program Files\Java: jre 1.6.0_01, jre 1.6.0_02, j2re1.4.2, jre6, jre7, jdk1.7.0_03)

The PATH variable contains the C:\j2sdk1.4.2\bin path, however I think the java.exe is loaded from the upper version, but it shouldn’t matter and I can call it like

>C:\j2sdk1.4.2\bin\java.exe MainJPrint

jPrint.jar is a third party archive and I need to create an applet which exposes a method so I can call it with javascript. I’m not a java developer, I’m having some little troubles and I’m really on an end here.

I tried other options like:

>java MainJPrint -cp .
>java MainJPrint -cp jPrint.jar

So how can I execute that class file which uses a class located in a separate archive?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:53:00+00:00Added an answer on June 3, 2026 at 5:53 am

    To execute a class that depends on external JARs, you need to specify all elements of the classpath on the command line.

    If you don’t specify a classpath, Java automatically uses . (the current directory), which is why, if MainJPrint didn’t depend on jPrint.jar, your invocation java MainJPrint would have worked.

    But when you specify -cp jPrint.jar, Java does NOT automatically add the current directory to the classpath, which means that it then cannot find MainJPrint. You need to specify both. On Mac/*nix, the following invocation should work:

    java -cp jPrint.jar:. MainJPrint
    

    Or on Windows:

    java -cp jPrint.jar;. MainJPrint
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java I have created the following class which extends ImageView to create a
In an assembly I created a class like the following: [DataObject(true)] public class A
I have an ExpenseType object that I have created with the following migration: class
I have created mock: GuiExHandler mockGuiEx = EasyMock.createMock(MockedClass.class); And Im getting following exception: Testcase:
I create the following attribute: public class SpecificDataTypeAttribute : DataTypeAttribute { public SpecificDataType(DataType dataType,
Is it possible to create generic class as following? public class AnyClassTypeWithValue<Class<T>, E> {
Consider the following code. public interface IFoo { } public class Bar { public
I have the following Ria Service define: namespace SilverlightTest.Web { [EnableClientAccess()] public class ContactService
I've created an XML schema by annotating an existing Java domain model class, now
I am fairly new to Java programming and was following a tutorial located here:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.