I tried to compile (using only javac filename.java) a class with the following import:
import org.apache.commons.io.FileUtils;
This threw an error: "package org.apache.commons.io does not exist".
So after some googling I realized that I need some sort of commons-io .jar file and that I can try to compile with something like,
javac -cp .:common-io-xx.jar filename.java
I guess the xx part is a placehodler meant to be replaced when I know the proper name of the file that I'm trying to add to my classpath (tell me if I'm wrong).
I tried finding this .jar file but on the following site:(http://commons.apache.org/proper/commons-io/download_io.cgi) I could only find some .tar files which as far as I could see did not contain any .jar files. Thus I need help with two things:
1) Where can I find the correct file containing the source code I need to use the commons-io library?
2) Upon finding that file, how do I successfully compile (and run) my program in the Linux terminal?
Please note that I am completely new to the concept of classpath and need help with how to apply this in the terminal.
I know similar questions have been asked before, but none so elementary that I could use their answers, I'm afraid.
1) You don't need the source code of commons-io in order to compile your code. As you have been trying to do, you just need the commons-io jar file. If you are interested learning how the code works in that particular jar, a quick google search will bring you to this github repo: https://github.com/apache/commons-io
2) The files from http://commons.apache.org/proper/commons-io/download_io.cgi are compressed files. The easiest option for you is to download commons-io-X.Y-bin.zip (replace X and Y with whatever version you are looking for). Unzip the zip file you downloaded (https://unix.stackexchange.com/questions/156261/unzipping-a-gz-file-without-removing-the-gzipped-file), then compile with the command you have above (make sure your classpath, source file locations are correct).
Related
I'm curious about Apache commons-io, why do they include a sources-jar inside the code package. We will not compile the program like so :
javac -cp .;.\lib\commons-io-2.4-sources.jar myCode.java
But we compile it like this :
javac -cp .;.\lib\commons-io-2.4.jar myCode.java
So why do the libraries also include a -sources jar in the download code ? I'm guessing it's for studying the source code, if we want to add/improve ?
The source JAR is so you can read the code is you want to. If you use an IDE, it can know to down load this JAR and if you look at a class in it, it will show your the source. esp useful when debugging a program. If you are not using an IDE, you can unpack the source and read it to understand what it is doing.
The reason the source is not included in the compiled JAR is so it can be easily dropped if all your are doing is running the program e.g. in production.
Dear Java Programmers,
JavaBib (http://code.google.com/p/javabib/) is a simple open source java package for which I would like to generate bytecode.
The source can also be obtained by version control via
svn checkout http://javabib.googlecode.com/svn/trunk/ javabib-read-only
Although it consists of only a few java files, I am not able to compile it using
javac *.java
I get
cannot find symbol
error messages for nearly all of the files.
The source files of the dom package all reside in one folder. Therefore, I think it should not be a problem with the classpath. I have tried different values for it nonetheless.
There are additional source files in other directories. I tried copying them all in one directory and run javac in this directory, but javac was complaining about the same imports.
Unfortunately, I have hardly any experience with java and can't fix the problem myself.
Therefore, I would be grateful for hints towards additional diagnostics in order to pin down the problem.
I use Ubuntu 12.04 as operating system and haven't set any classpath or sourcepath variable. At least javac seems to find imports like "java.util.list".
Thanks in advance for your help.
We accidently got some JAVA source files deleted from the system.
This happened when We checked out a folder from repository directly as an eclipse project and then tried to copy a folder from another eclipse project into this one.Strangely all those folder files have vanished from local system (and obviously they never made it to SVN repository).
Somehow We have obtained .svn-base files for some CLASS files.Now We are trying to decompile class files to obtain the source code back. However some of the class files are giving error "invalid input file" when jd compiler is trying to process them.
Is there any other solution to this ?
From what I can tell, "jd-gui" is closed source, so you may need to contact the developer to find out what that message means. (If it was open source, we could just look at the source code to figure out what the likely problem was!)
However, one thing is clear from various questions that Google shows up, and that is that "jd-gui" doesn't understand how to decompile archives (JAR, EAR, etc). So maybe you just need to un-JAR something to make it work.
The other thing you could try (first) is to see what "javap" makes of the class files that "jd-gui" doesn't like.
Try using JAD to decompile your files.
www.varaneckas.com/jad/
You may need to unzip your jar files and then run something like the following to decompile them all
find <srcdirectory> -name *.class -exec jad -s .java -r -ff -clear -debug -d <dest directory> {} \;
I havent tested the above command but hopefully it is almost there...
I also had the error "invalid input file" with a certain class file. I was using version 0.3.6 of jd-gui. After downloading the newest version of jd-gui (which was 1.6.6 at the moment of writing this) I could decompile the class file which previously failed.
So if someone still has this problem it makes sense to check the version and upgrade if it is an older one. Here is a link to the "Latest-Release"-download page:
http://java-decompiler.github.io/
I'm a rookie as to java.
I'm using an open source library named JCIFS.In its ZIP package,it has patches.And I want to use some functiones that only the patch has.But I don't know how.There are lots of irrelevant messages while I use google.Thus I ask here.
Can anyone help me?
Thanks in advance.
In ZIP package you probably have sources (maybe in src directory). I mean lots of *.java files and some with other extension. You have to apply patch on this files. At the beginning of patch it is specified which file you need. And then compile it all using javac and maybe package into jar.
If you don't have sources you have to get source for given class.
Then you have to apply patch on this file and compile it using javac. Then you will get .class file. You have to replace this file in .jar or .zip archive used with your system.
On Unix, you have the standard patch program to do that, but that ofcourse isn't normally present on Windows. If you want the patch command (and lots of other Unix utilities) on Windows, you could download and install Cygwin.
But looking at the patch file, it's very small and you could easily do the change by hand. Look at the patch file: The lines with a - in the left column must be removed. The lines with a + must be added.
This question already has answers here:
What is a classpath and how do I set it?
(10 answers)
Closed last year.
I am trying to compile a library I wrote, using javac and I am getting the error: package org.json does not exist. My program includes org.json.JSONArray and org.json.JSONException.
I have this package installed on my computer because I have successfully compiled android apps that import org.json libraries. I'm pretty sure all I have to do is specify a -classpath but I have been unable to find where these files live on my system (ubuntu 10.10 64-bit sun-java6).
Having been unable to find these on my own system I downloaded the org.json files from here, but I was unable to compile them individually because they were co-dependent on each other.
So I have a couple questions:
Does anyone know where the org.json
package lives from android sdk
install?
Where might I find a tutorial
explaining these basic concepts
regarding compiling, and javac.
Whatever external jars you need to compile with should be on the classpath when you compile. The most non-invasive way to do this is do add these items to the javac command line such as
javac -classpath /path/to/json.jar;. -g YourClass.java
or more likely if you use an IDE, add these jars to your referenced jars of the project in your IDE.
It usually isn't a good idea to pollute the global $CLASSPATH variable, as this then gets pulled in for everything you do with java, which may cause unintended conflicts.
Wherever you like. What you need to do is examine your CLASSPATH variable, and make sure it includes the directory with your library.
Here's the first thing:
$ echo $CLASSPATH
and you'll see your classpath as it is.
Now you need to find the jar file containing the org.json; consult the documentation, but it may be something as simple as json.jar. On most LINUX systems you can then just run
$ locate json.jar
And you'll get a path name for the jarfile. Make sure that path is part of your CLASSPATH and you'll be in fat city.
Oh, and the "Getting started" tutorials at Sun Oracle are the easiest place to start.
Actually, having looked at the files, they may not be packaged as a jar file. In that case, you want to put them into your sources starting at some top directory (src in this example.)
/src
/org/json/ ... put the json files here
... put your files here
and when you compile, they'll all be included, which will resolve all the dependencies.
Again, the place to look for first steps is that tutorial.
use "java" command instead of "javac"