DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page javac error when using jar file : cannot find symbol
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Nov 2008
Default javac error when using jar file : cannot find symbol - 03-18-2009, 02:20 PM

I create the jar file MyJCESP.jar from MyWrapperAbstract.java & MyWrapperData.java.
The DeriveKeyDemo.java use this jar file but compiling it result in the "cannot find symbol" error.
Please help.

//////////////////////////////
// MyWrapperAbstract.java
//////////////////////////////

package com.mycomp.cryptox;

import com.mycomp.crypto.*;

import java.security.*;
import java.security.spec.*;
import javax.crypto.*;

public abstract class MyWrapperAbstract extends KeyGeneratorSpi {
// ...
}


//////////////////////////////
// MyWrapperData.java
//////////////////////////////

package com.mycomp.cryptox;

import com.mycomp.crypto.*;

import java.security.*;
import java.security.spec.*;
import javax.crypto.*;

class MyWrapperData extends MyWrapperAbstract {
// ...
}

MyWrapperAbstract.java & MyWrapperData are compiled to create the jar file MyJCESP.jar.


//////////////////////////////
// DeriveKeyDemo.java
//////////////////////////////
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.cert.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;

import com.mycomp.cryptox.*; // Load MyJCEProvider classes
import com.mycomp.crypto.*; // Load MyJCAProvider classes


public class DeriveKeyDemo
{
public static void main(String[] args)
{
try
{
keyDerivator = MyWrapperData.getInstance("DES", "MyJCEProvider");
keyDerivator.initialize(keyGen, 1024);

// ...
}
}
}

CLASSPATH is setup as below:
$ export CLASSPATH=/home/powah/jdk1.6.0_06/jre/lib/ext/MyJCASP.jar:/home/powah/jdk1.6.0_06/jre/lib/ext/MyJCESP.jar


$ javac DeriveKeyDemo.java
^
DeriveKeyDemo.java:94: cannot find symbol
symbol : method getInstance(java.lang.String,java.lang.String)
location: class com.mycomp.cryptox.MyWrapperData
keyDerivator = MyWrapperData.getInstance("DES", "MyJCEProvider");
^
DeriveKeyDemo.java:95: cannot find symbol
symbol : method initialize(javax.crypto.KeyGenerator,int)
location: class com.mycomp.cryptox.MyWrapperData
keyDerivator.initialize(keyGen, 1024);
^
2 errors
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Mar 2009
Default 03-19-2009, 05:49 AM

The error indicates that the methods with the given signatures cannot be found. Take a close look at you defninition of getInstance in the MyWrapperData class, and the initialize in whatever class keyDericator is an instance of.
Reply With Quote
  (#3 (permalink)) Old
Moderator
 
jwenting's Avatar
 
Posts: 99
Thanks: 0
Thanked 8 Times in 8 Posts
Join Date: Feb 2008
Send a message via MSN to jwenting
Default 03-23-2009, 09:10 AM

start by never putting anything in the jre/lib/ext or equivalent directories. Those directories were a very bad idea and should never be used.
then compile those classes before trying to reference them from a jar.
Reply With Quote
  (#4 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Mar 2009
Default Use engineinit() - 03-23-2009, 10:47 AM

Hi,

You can use engineInit(1024,keygen) intead of Initialize.

do you have method signature of getInstance(string, stirng) in your MywrapperData.java class?
Reply With Quote
  (#5 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Nov 2008
Default 03-26-2009, 02:58 PM

I still has the same problem after changing CLASSPATH & checked that method signature of getInstance(string, string) is in your MywrapperData.java class
export CLASSPATH=/home/powah/myproj/MyJCASP.jar:/home/powah/myproj/MyJCESP.jar:.
Reply With Quote
  (#6 (permalink)) Old
Member
 
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Nov 2008
Default 03-26-2009, 03:04 PM

I still has the same problem after changing CLASSPATH & checked that method signature of getInstance(string, string) is in your MywrapperData.java class
export CLASSPATH=/home/powah/myproj/MyJCASP.jar:/home/powah/myproj/MyJCESP.jar:.
Reply With Quote
  (#7 (permalink)) Old
Member
 
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Apr 2009
Default 04-27-2009, 07:13 AM

Hi,

I think you are not creating the jars correctly.

As you can see you have the following package hierarchy:
com.mycomp.cryptox

First check whether the generated jars has the following packages or not.
The .class files should be inside com/mycomp/cryptox/

For that you should be in the just one level up of the com directory. Then you should use the jar command to generate the jars....

That will definitely work...


Thanks
Nirmal
Reply With Quote
  (#8 (permalink)) Old
Member
 
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Join Date: Feb 2008
Default 04-27-2009, 12:18 PM

Quote:
Originally Posted by jwenting View Post
start by never putting anything in the jre/lib/ext or equivalent directories. Those directories were a very bad idea and should never be used.
then compile those classes before trying to reference them from a jar.
Hmm, could, and would, you elaborate on this please? I've been using the jre/lib/ext directory for years to place .jar files in, and never had a problem....
(That I know of, of course!)

Dave
Reply With Quote
  (#9 (permalink)) Old
Moderator
 
jwenting's Avatar
 
Posts: 99
Thanks: 0
Thanked 8 Times in 8 Posts
Join Date: Feb 2008
Send a message via MSN to jwenting
Default 04-28-2009, 01:41 AM

and have you ever distributed your work to others who don't have those same jar files in there?
Or tried to run any Java software you didn't write yourself that uses different versions of those libraries you put in there.
Obviously you haven't...

Putting things in there leads to the Java equivalent of DLL Hell, missing resources, version conflicts, etc. etc.

It's a terrible mess, and easily avoided by learning how to set your classpath per application (never use the system classpath for the same reason) and include your libraries in an application specific lib directory.
Reply With Quote
The Following User Says Thank You to jwenting For This Useful Post:
jdavidboyd (04-28-2009)
  (#10 (permalink)) Old
Member
 
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Join Date: Feb 2008
Default 04-28-2009, 05:00 PM

Nope, you're right, I've never done that. We sent everything out as a bundle, and the installer always put our libs into that directory.

I won't do that anymore, since it makes sense to add in another directory to the classpath.

Thanks for the tip.
Reply With Quote
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/Replace Newline misterchucker Eclipse 2 03-23-2009 10:55 AM
Security error while loading pdf file in jsp in firefox? randy ortan Java 0 02-09-2009 09:29 AM
Error symbol mea36 Eclipse 0 10-23-2008 09:30 PM
Can't find Flex Builder gleble Eclipse 0 10-04-2008 08:23 AM
Error when launching Eclipse: In Project Explorer window: "Error creating the view" barbuceanu Eclipse 1 05-07-2008 01:41 PM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com