jar interview questions
Top jar frequently asked interview questions
Does anyone know of a free decompiler that can decompile an entire Jar file instead of a single class? I have a problem with sub classes like name$1.class name$2.class name.class
Source: (StackOverflow)
if you have a jar file called myJar.jar in /myfolder and you want to use myClass from it, how do you go about doing it from the command line?
i thought it would be go into the directory and say java -cp myJar.jar.myClass but that isnt working. Any help would be appreciated
Source: (StackOverflow)
I write a little command-line-application in Java. This application should work with a mix of parameters and commands, similar to svn
.
Examples
app url command1
app url command2 --parameter2 -x
app url command1 --param-with-argument argument
app --parameter url command1
app --no-url command2
app --help
Wanted
- Exists an easy-to-use library for Java
- Supports parsing of such command-lines
- (Bonus) Automatically creates an appropriate help
Source: (StackOverflow)
What would be the easiest way to view classes, methods, properties, etc. inside a jar file?
I'm looking for something equivalent to the very useful Lutz Roeder .NET Reflector - for Java
Source: (StackOverflow)
Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load jars dynamically. I'm told there's a way of doing it by writing your own ClassLoader, but that's a lot of work for something that should (in my mind at least) be as easy as calling a method with a jar file as its argument.
Any suggestions for simple code that does this?
P.S.: I know some see it as lame to answer your own questions, but I figured I'd do that so that a better one could bubble up past it.
Source: (StackOverflow)
How can I tell what version of the Java compiler was used to build a jar? I have a jar file, and it could have been built in any one of three JDKs. We need to know exactly which one, so we can certify compatibility. Is the compiler version embedded somewhere in the class files or jar?
Source: (StackOverflow)
Maybe this question seems to be a cliché but it bothers me somehow. What it difference in using maven scope compile
and provided
when artifact is builded as a JAR? If it was WAR, then I understand - artifact would be attached or not to WEB-INF/lib. But in case of the JAR it doesn't matter - dependencies aren't attached. They have to be on classpath when their scope is compile
or provided
. I know that provided
dependencies aren't transitive - but is it only one difference?
Source: (StackOverflow)
Is there a tool or script which easily merges a bunch of JAR files into one JAR file? A bonus would be to easily set the main-file manifest and make it executable.
The concrete case is a Java restructured text tool. I would like to run it with something like:
java -jar rst.jar
As far as I can tell, it has no dependencies which indicates that it shouldn't be an easy single-file tool, but the downloaded ZIP file contains a lot of libraries.
0 11-30-07 10:01 jrst-0.8.1/
922 11-30-07 09:53 jrst-0.8.1/jrst.bat
898 11-30-07 09:53 jrst-0.8.1/jrst.sh
2675 11-30-07 09:42 jrst-0.8.1/readmeEN.txt
108821 11-30-07 09:59 jrst-0.8.1/jrst-0.8.1.jar
2675 11-30-07 09:42 jrst-0.8.1/readme.txt
0 11-30-07 10:01 jrst-0.8.1/lib/
81508 11-30-07 09:49 jrst-0.8.1/lib/batik-util-1.6-1.jar
2450757 11-30-07 09:49 jrst-0.8.1/lib/icu4j-2.6.1.jar
559366 11-30-07 09:49 jrst-0.8.1/lib/commons-collections-3.1.jar
83613 11-30-07 09:49 jrst-0.8.1/lib/commons-io-1.3.1.jar
207723 11-30-07 09:49 jrst-0.8.1/lib/commons-lang-2.1.jar
52915 11-30-07 09:49 jrst-0.8.1/lib/commons-logging-1.1.jar
260172 11-30-07 09:49 jrst-0.8.1/lib/commons-primitives-1.0.jar
313898 11-30-07 09:49 jrst-0.8.1/lib/dom4j-1.6.1.jar
1994150 11-30-07 09:49 jrst-0.8.1/lib/fop-0.93-jdk15.jar
55147 11-30-07 09:49 jrst-0.8.1/lib/activation-1.0.2.jar
355030 11-30-07 09:49 jrst-0.8.1/lib/mail-1.3.3.jar
77977 11-30-07 09:49 jrst-0.8.1/lib/servlet-api-2.3.jar
226915 11-30-07 09:49 jrst-0.8.1/lib/jaxen-1.1.1.jar
153253 11-30-07 09:49 jrst-0.8.1/lib/jdom-1.0.jar
50789 11-30-07 09:49 jrst-0.8.1/lib/jewelcli-0.41.jar
324952 11-30-07 09:49 jrst-0.8.1/lib/looks-1.2.2.jar
121070 11-30-07 09:49 jrst-0.8.1/lib/junit-3.8.1.jar
358085 11-30-07 09:49 jrst-0.8.1/lib/log4j-1.2.12.jar
72150 11-30-07 09:49 jrst-0.8.1/lib/logkit-1.0.1.jar
342897 11-30-07 09:49 jrst-0.8.1/lib/lutinwidget-0.9.jar
2160934 11-30-07 09:49 jrst-0.8.1/lib/docbook-xsl-nwalsh-1.71.1.jar
301249 11-30-07 09:49 jrst-0.8.1/lib/xmlgraphics-commons-1.1.jar
68610 11-30-07 09:49 jrst-0.8.1/lib/sdoc-0.5.0-beta.jar
3149655 11-30-07 09:49 jrst-0.8.1/lib/xalan-2.6.0.jar
1010675 11-30-07 09:49 jrst-0.8.1/lib/xercesImpl-2.6.2.jar
194205 11-30-07 09:49 jrst-0.8.1/lib/xml-apis-1.3.02.jar
78440 11-30-07 09:49 jrst-0.8.1/lib/xmlParserAPIs-2.0.2.jar
86249 11-30-07 09:49 jrst-0.8.1/lib/xmlunit-1.1.jar
108874 11-30-07 09:49 jrst-0.8.1/lib/xom-1.0.jar
63966 11-30-07 09:49 jrst-0.8.1/lib/avalon-framework-4.1.3.jar
138228 11-30-07 09:49 jrst-0.8.1/lib/batik-gui-util-1.6-1.jar
216394 11-30-07 09:49 jrst-0.8.1/lib/l2fprod-common-0.1.jar
121689 11-30-07 09:49 jrst-0.8.1/lib/lutinutil-0.26.jar
76687 11-30-07 09:49 jrst-0.8.1/lib/batik-ext-1.6-1.jar
124724 11-30-07 09:49 jrst-0.8.1/lib/xmlParserAPIs-2.6.2.jar
As you can see, it is somewhat desirable to not need to do this manually.
So far I've only tried AutoJar and ProGuard, both of which were fairly easy to get running. It appears that there's some issue with the constant pool in the JAR files.
Apparently jrst is slightly broken, so I'll make a go of fixing it. The Maven pom.xml
file was apparently broken too, so I'll have to fix that before fixing jrst ... I feel like a bug-magnet :-)
Update: I never got around to fixing this application, but I checked out Eclipse's "Runnable JAR export wizard" which is based on a fat JAR. I found this very easy to use for deploying my own code.
Some of the other excellent suggestions might be better for builds in a non-Eclipse environment, oss probably should make a nice build using Ant. (Maven, so far has just given me pain, but others love it.)
Source: (StackOverflow)
Is there a way to extract the source code from an executable .jar file (Java ME)? Any help will be appreciated.
Source: (StackOverflow)
I have a project that contains a single module, and some dependencies.
I'd like to create a jar, in a separate directory, that contains the compiled module. In addition, I'd like to have the dependencies present beside my module.
No matter how I twist IntelliJ's "build jar" process, the output of my module appears empty (besides a META-INF file).
Source: (StackOverflow)
I have created a JAR file in this way jar cf jar-file input-files
. Now, I'm trying to run it. Running it does not work (jre command is not found):
jre -cp app.jar MainClass
This does not work either:
java -jar main.jar
(Failed to load Main-Class manifest attribute from main.jar).
I also found out that
To run an application packaged as a
JAR file (version 1.2 -- requires
Main-Class manifest header)
What is the "Main-Class manifest header"? How do I create it and where do I put it?
Source: (StackOverflow)
I read the Java tutorials on Sun for JAR files, but I still can't find a solution for my problem. I need to use a class from a jar file called jtwitter.jar, I downloaded the file, and tried executing it (I found out yesterday that .jar files can be executed by double clicking on them) and Vista gave me an error saying "Failed to load Main-Class Manifest attribute from [path]/jtwitter.jar".
The guy who coded the .jar file wants me to import it, but where do I store the .jar file to import it in my code? I tried putting both the .jar file and my .java file in the same directory, didn't work.
The file I'm trying to work for is here: http://www.winterwell.com/software/jtwitter.php
I'm using JCreator LE.
Source: (StackOverflow)
Java is one of my programming languages of choice. I always run into the problem though of distributing my application to end-users.
Giving a user a JAR is not always as user friendly as I would like and using Java WebStart requires that I maintain a web server.
What's the best way to distribute a Java application? What if the Java application needs to install artifacts to the user's computer? Are there any good Java installation/packaging systems out there?
Source: (StackOverflow)
I found the maven-shade-plugin being used in someone's pom.xml. I've never used maven-shade-plugin before (and I'm a maven n00b) so I tried to understand the reason for using this and what it does. I looked at the maven docs, however I can't understand this statement: "This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies." The documentation on the page doesn't seem very newbie-friendly.
What is an "uber jar?" Why would someone want to make one? What's the point of renaming the packages of the dependencies? I tried to go through the examples on the maven-shade-plugin apache page such as "Selecting contents for Uber Jar," but I still can't understand what is being accomplished with "shading."
Any pointers to illustrative examples/use-cases (with an explanation of why shading was required in this case - what problem is it solving) would be appreciated. Lastly, when should I use the maven-shade-plugin?
Source: (StackOverflow)