Find a class under Jar file
Hi all,
If I want to find out a class resides under what jar file, under Linux, I use this command:
for i in $(find -name \*.jar) ; do if jar tf $i | grep �q className.class ; then echo $i ; fi ; done
Does anybody know how can I do this under Windows? If I need to know a class is under what jar file, is there anyway to do this except extracting each jar file and see what classes are under the jar file?
Is there any tool that can mount the jar file and expand it in a tree structure to see all of it's classes visually?
Any help is greatly appreciated.
if you have a lot of jars, its actually time-consuming....Sorry, my computer freez.
Vector<String> parcalar=null;
try {
JarFile jarfile = new JarFile(new File("lang.jar"));
Enumeration<JarEntry> dosyalar=jarfile.entries();
parcalar=new Vector<String>();
System.out.println(jarfile.size()-2);
while(dosyalar.hasMoreElements()) {
JarEntry entry = dosyalar.nextElement();
String name=entry.getName();
if(name.equals("MessagesBundle.properties")) {
//parcalar="--------------------";
else if(name.equals("META-INF/MANIFEST.MF")) {
else {
parcalar.addElement(name);
catch(IOException ex){
ex.printStackTrace();
System.out.println(parcalar);
Similar Messages
-
Where to put common classes and jar files
hi,
i want to put some classes and jar files in a common folder so that it can be accessed by other applications is there any way doing that.In tomcat server they have common and shared directories once any classes are into that folder they are being accessed easily ,but i am having problems with sun one .
Regards
Ameem SamiDid you find a solution for this? I'm having the same problem.
Thanks,
Tony -
How to find directory java program .jar file is in?
I have a Java program that needs to save some configuration and data files in the same directory as the .jar file that contains the program.
If the user launches the app from that directory, it's easy.
The problem is when they do something like "java -jar /dir1/dir2/program.jar".
When they do that, HOW can I find the directory the .jar file is in - from within the program?CasaDelGato wrote:
I have a Java program that needs to save some configuration and data files in the same directory as the .jar file that contains the program.
If the user launches the app from that directory, it's easy.
The problem is when they do something like "java -jar /dir1/dir2/program.jar".
When they do that, HOW can I find the directory the .jar file is in - from within the program?There is an obscure way that basically consists of the following.
1. Get the class loader of the class (obviously one in the jar)
2. Find the 'resource' of that.
3. Resolve that to a path
4. Make it absolute if not already.
5. Extract the directory part.
2 and 3 are always the hard ones (conceptually and figuring out from the javadocs). There are examples somewhere on the forum. -
Can I increase heap memory without specify any class or jar file??
Hi,
I tried to increase my heap memory in this way :
java -Xms256m -Xmx256m
but I got an error ... it's seem that I must specify a class java or a .jar file ...
This is the error :
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
can I increase heap memory without specify any class or jar file??
thxchiara wrote:
Hi,
I tried to increase my heap memory in this way :
java -Xms256m -Xmx256m
but I got an error ... it's seem that I must specify a class java or a .jar file ...
This is the error :
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
can I increase heap memory without specify any class or jar file??The job of java.exe is to execute java bytecode.
What is it supposed to do with your request to use 256m of memory for heap
when you are not giving it a class or a jar to run? -
Ojvmtc reports xy.jar is not a class or jar file
Hi
I am a little bit confuced because ojvmtc reports an error I can not imagine about:
oracle@cikic-desktop:~/Downloads/dom4j-1.6.1$ ojvmtc /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar
/u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar is not a class or jar file
The set is closed
But jce.jar is a jar file and I can inflate it:
oracle@cikic-desktop:/tmp/fo$ jar -xf /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar
oracle@cikic-desktop:/tmp/fo$ ls -l
total 8
drwxr-xr-x 3 oracle oinstall 4096 2010-05-03 19:40 javax
drwxr-xr-x 2 oracle oinstall 4096 2010-05-03 19:40 META-INF
And if I do a ojvm on a class file everything is working like expected:
oracle@cikic-desktop:/tmp/fo$ ojvmtc javax/crypto/Mac.class
The set is not closed
96 classes are missing
So It must be a configuration mistake somewhere ...
Can you please help me out.
Thanks
Christian MaierCoole thanks, this works pretty well!
Chris
oracle@cikic-desktop:~$ cp /u01/app/oracle/product/11.1.0/mds/jdk/jre/lib/jce.jar /tmp/
oracle@cikic-desktop:~$ ojvmtc /tmp/jce.jar
The set is not closed
131 classes are missing -
Problem finding class in jar file
I have an applet that will run when I have all the classes sitting in the same directory. ex) http://IPaddress/directory. But I try to put them all into a jar file and run the code and it says cant find the class. Below is my html code. Please help!
<HTML>
<HEAD>
</HEAD>
<BODY>
<APPLET
CODEBASE="http://IPaddress/directory1/directory2"
CODE="Applet.class"
ARCHIVE="1stJar.jar,2ndJar.jar,3rdJar.jar,Applet.jar"
WIDTH=600 HEIGHT=600>
</APPLET>
</BODY>
</HTML>Where are your jar files contained? They need to be in the same directory as your CODEBASE, or otherwise include a relative directory.
Also, what browser are you using?
From the Java web page on APPLET tags
"Unfortunately, not all browsers understand the same archive format or use the same HTML code to specify the applet archive" -
WAR Can't find class in JAR file in EAR/lib
Hi,
I have 1 EAR file with 1 WAR and 1 EJB-JAR file. Our main business-code is in a JAR-file which is placed in the EAR/lib/ folder along with the rest of the shared JAR-files.
When i deploy the EAR the EJB gets deployed fine but when the WAR gets deployed, we get a ClassNotFoundException. We configured a class as a ServletContextListener (Which is part of the jar) in the web.xml so at startup it should perform some initiation. But since it can;t be found....
I've tried changing the Mainfest.mf to include a CLASSPATH attribute with ./lib/x.jar but it stil the same problem. The only thing that solves it is to put it in the WEB-INF/lib folder.
What am i doing wrong?
Thanks,
MaartenHere it is
<?xml version="1.0"?>
<!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
<application>
<display-name>spg-online</display-name>
<module>
<web>
<web-uri>appname.war</web-uri>
<context-root>appname</context-root>
</web>
</module>
<!--module>
<ejb>appname-ejb.jar</ejb>
</module-->
</application>
My app follows the basic structure of an EAR-file:
EAR
META-INF
application.xml
lib
appname.jar
a.jar
spring.jar
appname.war
appname-ejb.jar
The meta-inf of the war-file looks like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.4.2_08-b03 (Sun Microsystems Inc.)
Class-path: ./lib/appname.jar ./spring.jar
I let ANT generate the Class-path:
<jar jarfile="${dist.home}/${component.name}.war">
<fileset dir="${build.home.webroot}" />
<!-- dependency -->
<manifest>
<attribute name="Class-Path" value="${lib.project.manifest.classpath}"/>
</manifest>
</jar> -
Importing classes from Jar files..?
I've run into a problem that I am having some difficulty solving. I currently trying to port a two part Java UI project from Solaris to Windows. The first is a package of core classes out of which I (successfully) create a jar file. The second is a product-specific package that imports the core classes from the package created in the first. The problem is that the second package fails to build because javac says the package from part one does not exist. Here's what I know:
- This UI (built via a Makefile) builds successfully under Solaris
- The jar file that I created in the first part exists in the appropriate directory.
- When I view the contents of that jar it appears as though everything is there.
- The jar file is appropriately included in the classpath of the second build.
Any suggestions you could provide, or resources you could point me to would be greatly appreciatedjh.jar is a static, 3rd party component. Doesn't seem to be giving me any grief, at least not yet.
Correct on your second point.
This is interesting. When I open my "CoreConsole.jar"
file, I DO NOT see any reference to the
com.emc.avalon.core.server package, only a list of
class files that make up that package. You should see the .class files on the left and the relative path on the right.
Also, all of the class file listings have absolute paths according
to the location on my machine they were built, for example:
m:/xpe/CoreConsole/classes/com/emc/avalon/core/server/MessageLogUtility.class
Is this a problem..?Yes, that should be a relative path, with the first entry being the first name in the package statement. So you should see an entry MessageLogUtility.class, and the path should be com.emc.avalong.core.server.
If you can't see the class that's missing, that would explain why the class loader can't find it, either. -
OC4J: Class not found for class in jar file placed in \j2ee\home\applib\
I have an ADF application which uses external libraries (jars), which works fine when running the application from within JDeveloper (TP4).
However if I deploy the application to the embedded OC4J server it won't find any classes imported in those external libraries at runtime (deploy does work). E.g. one library class imports oracle.jbo.server.DBTransaction. If a method of this class is called I get the following exception:
Unexpected exception caught: java.lang.NoClassDefFoundError, msg=oracle/classloader/util/AnnotatedNoClassDefFoundError
oracle/classloader/util/AnnotatedNoClassDefFoundErrorThe same exception, when using a german locale, explicitely states that it cannot find oracle.jbo.server.DBTransaction.
The jar files are placed in the \j2ee\home\applib\ directory and a <library> element to this path is present in application.xml.
Any further hints what could be wrong?Hi Edwin,
tried your suggestions but without success.
when I add this library to server.xml then following error occures when starting OC4J
17.09.2008 17:10:33 oracle.oc4j.util.SystemLog log
SCHWERWIEGEND: Server start failed processing configuration
java.lang.InstantiationException: Illegal tag, 'library': The library tag has moved from config/server.xml to config/application.xml, please update your configuration manually or reinstall.
at com.evermind.server.XMLApplicationServerConfig.parseDeploymentMainNode(XMLApplicationServerConfig.java:1227)
at com.evermind.xml.XMLConfig.parseRootNode(XMLConfig.java:342)
at com.evermind.xml.XMLConfig.init(XMLConfig.java:222)
at com.evermind.xml.XMLConfig.init(XMLConfig.java:154)
at com.evermind.server.XMLApplicationServerConfig.<init>(XMLApplicationServerConfig.java:237)
at com.evermind.server.ApplicationServer.createConfig(ApplicationServer.java:661)
at oracle.oc4j.server.ServerFactory$Worker.prepareConfig(ApplicationServerFactory.java:225)
at oracle.oc4j.server.ServerFactory$Worker.start(ApplicationServerFactory.java:244)
at oracle.oc4j.server.ServerFactory$Worker.run(ApplicationServerFactory.java:259)
at java.lang.Thread.run(Thread.java:619)
17.09.2008 17:10:33 oracle.oc4j.util.SystemLog logNoStack
SCHWERWIEGEND: Server exiting: ApplicationServer entered state EXITING--> I added this to application.xml
Than I enabled more logging of classloader "-Duser.country=US -Dclass.load.log.level=finest"
Here a snippet of the output at starttime of OC4J:
================================
08/09/18 10:17:07 Initial class loaders created. Uptime: 3156ms.
08/09/18 10:17:07 Loading main class com.evermind.server.OC4JServer...
08/09/18 10:17:07 com.evermind.server.OC4JServerMain class loaded. Uptime: 3344ms.
08/09/18 10:17:07 Transferring to com.evermind.server.OC4JServer.main()...
08/09/18 10:17:15 Ignoring non-existent code source: D:\oracle\jdevstudio1111_preview4_standalone\j2ee\home\config\..\..\..\BC4J\lib\jmxdc.jar(from <code-source> (ignore manifest Class-Path) in /D:/oracle/jdevstudio1111_preview4_standalone/j2ee/home/config/server.xml)
08/09/18 10:17:15 Ignoring <code-source> (ignore manifest Class-Path) in /D:/oracle/jdevstudio1111_preview4_standalone/j2ee/home/config/server.xml entry: code-source /D:/oracle/jdevstudio1111_preview4_standalone/j2ee/home/lib/api-ext/adflogginghandler.jar (from system property api.ext.dirs) is already visible in the search path of adf.oracle.domain:11.1.4949.
08/09/18 10:17:15 Ignoring non-existent code source: D:\oracle\jdevstudio1111_preview4_standalone\j2ee\home\config\..\..\..\BC4J\lib\jmxdc.jar(from <code-source> (ignore manifest Class-Path) in /D:/oracle/jdevstudio1111_preview4_standalone/j2ee/home/config/server.xml)
08/09/18 10:17:15 Import was not resolved for adf.oracle.domain:11.1.4949: shared library "oracle.fabric.runtime" could not be found.
08/09/18 10:17:15 Import was not resolved for adf.generic.domain:11.1.4949: shared library "oracle.fabric.runtime" could not be found.Seems that oracle.fabric.runtime couldn't be found but the jar's are located in D:\oracle\jdevstudio1111_preview4_standalone\lib\java\shared\oracle.fabric.runtime\11.1.1.0.0
It's the same as with my jdeveloper installation where I don't have this problems.
regards
Peter -
How to bundle java help class into jar file ?
Hi, all,
I have some package in my project, with which I have a java help jar file as classpath, when I run my project, I need the jh.jar file in directory /jar/jh.jar.
Now, I bundled all my class packages into a jar file, my.jar, together with the /jar directory. When i run my jar file with command:
java -jar my.jar
It tells me couldn't find javahelp class.
What shall I do? How can I create my jar file with the jh.jar?
Thanks in advance.I think you'd be better off just adding the jh.jar as
a classpath argument and running it like that:
java -classpath /myjavalibdir/jh.jar -jar myjar.jar
...otherwise you're stepping into redistribution of
binary issues licensing-wise. That won't work either; when you run java with the -jar option, it ignores both the -classpath option and the CLASSPATH environment variable. However, it will see jh.jar automatically if you put it in the <path-to-java>/jre/lib/ext directory. But for distribution purposes, it might be simpler just to combime the contents of jh.jar into myjar.jar (if you use Ant, its <jar> task makes that very easy). Or, you can just run it this way:java -classpath myjar.jar;jar/jh.jar MyMainClassBTW, I don't think redistribution is a problem; otherwise how anyone even use JavaHelp? -
How to access classes in jar files
hi I have added a jar file to my project in eclipse.How to access the classes in that jar file?
cu is right.
classloader returns the URL of your resource. You can the jar using something like the following...
ClassLoader classloader = this.getClassLoader();
url = classloader.getResource("your_resouces...");
if(url == null)
System.out.println("cannot find resource ");
return null;
String jar = url.getFile();
jar = jar.substring(jar.indexOf("/")+1, jar.lastIndexOf("!")).replace('/', '\\');
obviously, this code snippet works on windows only. Now you have the jar file path. I use Jar file classes to access the jar file. (e.g. you can search for each class files)
Ming -
Okay, so I am somewhat new to Java, and I've never used a JAR file before. However, I need to make an applet with access to the local machine, so I've got to put it in a JAR file so I can sign it and blah, blah, blah . . .
Anyhow, my understaing is that I write
<APPLET
CODE = DisplayClass.class
ARCHIVE = display.jar
HEIGHT = x
WIDTH = y>
</APPLET>
then use java.sun.com's html converter to make the tag like
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 800 HEIGHT = 450 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = DisplayClass.class >
<PARAM NAME = ARCHIVE VALUE = "display.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" CODE = DisplayClass.class ARCHIVE = "display.jar" WIDTH = 800 HEIGHT = 450 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED></COMMENT>
Man, you need a new browser, one that can display applets
</NOEMBED></EMBED>
</OBJECT>
<!--
<APPLET CODE = DisplayClass.class ARCHIVE = "display.jar" WIDTH = 800 HEIGHT = 450>
Man, you need a new browser, one that can display applets
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
In any event, whenever I try to view it, with either IE or Netscape, the browser can't find the .class file in question.
The JAR file contains all the classes in the base directory. I'm really at a loss as to what I'm doing wrong, since all the docs I can find seem to indicate this should work.What's all this about DisplayClass.class being in a
package? It was my understanding that classes are
always part of packages. DisplayClass.java (the
uncompiled DisplayClass) certainly refers to itself as
being in a package, with the first line being package
testapplet;So your DisplayClass is in the package testapplet. Then you have to move DisplayClass in a folder named testapplet, or compile as
javac -d . DisplayClass.java
which will then create that folder for you and place the class file inside that.
The jar file should then keep the class in the same folder structure
testapplet/DisplayClass
And your CODE tag should refer to
testapplet.DisplayClass
If you didn't add the package statement to your DisplayClass.java file, then it would be in a default package and you wouldn't have to place the class file in a folder. -
Instantiate class from jar file
Need a quick hand...little bit of a rush here.
How do I go about instantiating a class from a jar file?
If my jar file resides at c:/MyApp/MyJar.jar
The contents of the jar file are:
meta-inf/MANIFEST.MF
A.java
How do I go about creating an instance of A? I see people saying to use the URLClassLoader, but I can't find any good sample code to clarify how it's done. Assuming I already know the name of the class I'm instantiating, could someone show me how the URLClassLoader is used please? Also, please note that the jar file is NOT in my classpath, and I am not able to put it there....because it needs to be dynamically loaded as a plugin. I'm not sure if that matters or not with regards to the instantiation.Thanks so much for that..I think it's just about what I need. However, I'm still running into a bit of a snag. After executing the code and trying to run a method to print something out from the object I just loaded, it instead prints a memory location. So I don't think it is quite working as intended. Here's the code I'm working with at the moment....
String jarPath = baseDir + "myApp/plugins/" + fileName;
Manifest mf = jar.getManifest();
Attributes att = mf.getMainAttributes();
String className = att.getValue("Main-Class");
//System.out.println(className);
File file = new File(jarPath);
URL[] urls = new URL[] {file.toURL()};
ClassLoader loader = URLClassLoader.newInstance(urls);
Class dynmicallyLoadedClass = Class.forName(className, true, loader);
PlugIn plugin = (PlugIn) dynmicallyLoadedClass.newInstance();
System.out.println(plugin.toString()); //This prints out "TMGImporter@1ce50a9" instead of what it's supposed to....Also, I am using Java 1.4.2_08 so I can't use generics. There are no error messages, just the wrong output. The jar this is using actually contains two files, besides the manifest. The TMGImporter (which Im trying to instantiate) and a TMGImporter$1 anonymous inner class. There is no package declaration on the class.
Any thoughts? -
I need a link where I can find "Apache POI - HWPF" jar file
I want to create a program that reads a word document and I can not find the .jar file of "Apache POI - HWPF". Can anybody send me the link from where I can download it? 10x
I modified my code as below:
import java.io.*;
import org.apache.poi.hwpf.extractor.*;
public class Word_Reader
public static void main (String args[])
try
InputStream is = new BufferedInputStream(new FileInputStream("test.doc"));
WordExtractor wd = new WordExtractor(is);
String text = wd.getText();
System.out.println(text);
catch(FileNotFoundException e1)
System.out.println("File does not exist.");
catch(IOException e2)
System.out.println("IO Exception");
I get printed on console: "IOException". What is wrong in my code? -
Run class in jar file using command prompt
Hi,
I have created a jar file OSTBTLDataTransfer.jar using eclipse and tried to run a class Person in the package com.aqa.details using the command prompt like this
java -classpath com.aqa.details.Person
but this complained about a jar file dependency and i have set it to the classpath like this:
set CLASSPATH=C:\jarup\abc\ibatis-2.3.4.726.jar
but it couldn't find the dependency when i tried to run again.
please let me know your suggestions
Thanks,
KCjava -classpath OSTBTLDataTransfer.jar com.aqa.details.Person
or if you have an appropriate manifest in the jar simply
java -jar OSTBTLDataTransfer.jar
Maybe you are looking for
-
Ipod not recognized by iTunes, won't update
My 4thGen ipod suddenly isn't being recognized by itunes. I've trying resetting, no help. I get an "ipod needs formatted" window, so when I try to run the ipod updater, the ipod still isn't recognized. But in MyComputer, it is recognized as "e drive"
-
Error message when running updates
I keep getting an error message when updating my CS programs. "This update from the internet cannot be completed. Please try again later." I bought a Canon 6D and the Adobe Camera Raw won't work because it isn't the latest version and that it needs t
-
Hi Automatic Payment Program considers due date for making payment to vendors. Now i want to know if there is possible for making payment on the basis of average due date (calculated on the basis of amount and the actual due date). Requirement: While
-
My wife and I have identical razr's. Hers updated automatic one night and she's not happy with the changes to the display. I keep selecting later for the update because I don't like the chages they made. Aside from that we can be next to each other i
-
How to insert jquery script in DW CS5?
Hi folks, I've always struggled with jquery scripts because I've never quite understood how to use them. I've installed extensions and widgets with no trouble but jquery scripts are just a little beyond my abilities so I'm hoping someone here can giv