JRE contains the .class files for library classes.
When these .class files in JRE folder will be used?
Does JRE contains the .class files for all library classes.
Let us take an example..
when we are importing the library files, we are using the definition of the class file from the src.zip and not the .class file. E.g. import java.net.InetAddress. that is just we are inheriting the library class.Therefore the code of the library class too complies along with our code na..
we are not using the .class file directly. so what is the use of having .class files for those library files in JRE folder?
I searched JRE folder, but I found no .class file for InetAddress
But command javap java.net.InetAddress still works well.
Someone please help.
Thanks in Advance.
javap runs in the JRE so it has all the classes which come with the JRE in its class path. Most of the classes you will be interested in are in the rt.jar archive.
If you want to decompile your own class, you have to add its base directory to the class path
e.g.
$ ls
HelloWorld.class
$ javap -c -classpath . HelloWorld
Yes the JRE contains the class files.
Related
I have a project in IDE, so I made a new project in Maven. I copy all the files and classes, and I fill the pom.xml.
This is OK, but the problem is in JSP,eclipse dont find the imported clases.
<%#page import="modelos.Mascota"%>
This import for example cant be resolved.
What I'm doing wrong?
All my java classes are in:
\src\main\resources
And jsp files in:
src\main\webapp
Your .java files must be in
\src\main\java
check your dependencies for the class whether it is exist or not
modelos.Mascota
I am trying to add a java command to spring-actuator's ssh remote shell in a spring-boot applicaton. The spring-boot version is 1.2.3.RELEASE.
My sample command is just named 'kafka' and I tried placing it on the classpath in both /crash/commands as well as just /commands. It is never found - it doesn't show up in the help or actually work.
Is there some way to ask the remote shell to tell me what it's scanning/finding when it starts?
Things I have tried include specfically overriding shell.commandPathPatterns though the default seems like it should cover it.
My command - for testing - is very simple:
package commands;
#Usage("Kafka utility commands")
public class kafka extends BaseCommand {
#Command
public Object main(InvocationContext<ObjectName> context) {
return "it's all good";
}
}
After one hour of debugging I've found that the CRaSH remote shell looks for files with the extensions .groovy or .java within the packages are commands and crash.commands. The found files are compiled to bytecode, compiler errors are ignored.
I presume you use something like Maven. When you put your command into src/main/java then Maven will compile it as .class file and CRaSH will not find it. When you put your command into src/main/resources then Maven will not compile it and keep it as .java file instead.
The solution (which is quite odd for me) is to put your java command file into src/main/resources (package commands or crash.commands) so you have a .java source file in your target directory or JAR.
I tested it with spring-boot 1.2.1.RELEASE (crash.shell: 1.3.0) which should not be much different than 1.2.3.RELEASE (crash.shell: 1.3.1).
I have a jar file that has a class that I would like to use from my Rails project. I have tried to import the class with Rjb with these commands. The jar file is in the bin directory.
Rjb.load("#{Rails.root}/bin")
=> nil
Rjb::add_jar("excel_tools.jar")
=> true
Rjb::import("tools.CellEditor")
ClassNotFoundException: tools.CellEditor
Rjb::import("tools/CellEditor")
ClassNotFoundException: tools.CellEditor
The class name "tools.CellEditor" should be correct. At least when I list the classes in the jar in terminal I get this and many more classes from apache poi and log4j.
$ jar tvf bin/excel_tools.jar
6926 Mon Aug 25 13:24:00 EEST 2014 tools/CellEditor.class
Any idea where the jar or class loading goes wrong?
I got this working by importing all the jar files my java class depends on. It is not enough that the dependence jars are bundled into another jar file with my class, they need to be loaded separately before importing the class it self.
I copied all the jars into a java_libs directory and wrote an initializer like this
require 'rjb'
JARS = Dir.glob("#{Rails.root}/lib/java_libs/*.jar").join(':')
Rjb::load(JARS)
CELL_EDITOR = Rjb::import('tools.CellEditor')
Now I can use the CELL_EDITOR methods anywhere in my code.
I'm trying to build a simple WordCount jar project which utilizes Hadoop-lzo library but cannot seem to get the following command to work, even though the class I'm referencing is within hadoop classpath:
$ javac -cp `hadoop classpath` *.java
LzoWordCount.java:76: cannot find symbol
symbol : class LzoTextInputFormat
location: class LzoWordCount
job.setInputFormatClass(LzoTextInputFormat.class);
^
1 error
Any ideas?
I assume you have correctly installed your LZO libraries (you should have libgplcompression.so in your lib/natives/Linux**-**/ and the jar file in your lib/ folder)
Since you have them the correct class should be LzoDeprecatedTextInputFormat.class or LzoTextInputFormat.class depending on wich API you use (According to your post you are using it right Job with LzoTextInputFormat).
So your problem could be in your java.library.path, wich should include path to your jar file. You can set it up in your .bash_profile or in you bin/hadoop file.
hope that helps.
I have a piece of Ruby code which depends on a binary built from C. I generally call the binary through backticks. But now when I package the Ruby code into a jar using Warbler, I'm not sure on how I'd be able to access the binary.
My code structure looks like this:
root/
|--bin/
|--exec.rb #This is the executable when I call java -jar example.jar
|--lib/
|--Module1.rb #This dir contains all the ruby modules my code requires
|--ext/
|--a.out #A binary compiled with gcc
|--.gemspec #A file to guide warbler into building this structure into a jar
I used warble to build this entire structure into a jar. In Ruby, I can access my a.out through the following statement in exec.rb.
exec = "#{File.expand_path(File.join(File.dirname(File.dirname(__FILE__)), 'ext'))}/a.out}";
`exec`
But when I try this code packaged as a jar I get the following error:
/bin/sh: file:/path/to/my/jar/example.jar!/root/ext/a.out: not found
So, how do I access the executable packaged in a jar.
Put the jar in the lib folder.
Require it in the code
require 'java'
Dir["#{File.expand_path(File.join(Rails.root, 'lib'))}/\*.jar"].each { |jar| require jar }
# A war is treated as a directory. If that is not successful add the lib folder to the CLASSPATH environment variable
Then it should be available to be used.
Edit:
Maybe this is what you are looking for https://stackoverflow.com/a/600198/643500 you can implement it with JRuby.