this is the folderI am battling to convert classes2-dex2jar.jar.src.java.
So I deleted ONE DRIVE which was recommended. JDK-8u321 and JRE-8u321 are properly installed.
But whenever I say : javac classes2-dex2jar.jar.src.java it's saying javac: not a file. I also
tried javac classes2-dex2jar.jar.src.java\* still it's javac not a file.
this file folder contains many java sourcefiles
this is the command's response
I am unsure about the real situation.
Unzip classes2-dex2jar.jar.
It contains a sub-directory src/java/ with sources typically in a directory tree.
For every package there is a directory: package x.y.z giving x/y/z/.
You would need to call javac inside src/java listing all *.java
with src/java on the class path (-cp .).
(It might be easier to do this in an IDE.)
Related
I have a project with such structure (shortened for simplicity):
and I'm trying to compile it with terminal.
I'm in src directory and firstly doing this:
find * -name "*.java" > sources.txt
After the first command a sources.txt file is generated:
aircraft/Baloon.java
aircraft/Aircraft.java
aircraft/JetPlane.java
aircraft/AircraftFactory.java
aircraft/Coordinates.java
aircraft/Flyable.java
aircraft/Helicopter.java
exception/WrongNumberArgsException.java
simulator/Simulator.java
Further I'm doing:
javac -sourcepath #sources.txt
And it generates all .class files, EXCEPT the first one - Baloon.java is totally ignored by javac.
If I do:
javac -sourcepath #sources.txt src/aircraft/Baloon.java
a Baloon.class file is generated as well with other .class files.
If I manually change first row of sources.txt, for example switch first and second rows, then when I recompile again first .java file in sources.txt is ignored by javac and respective .class file is not created.
Alternatively if I compile with Intellij Idea - everything is fine, no problems occur.
It doesn't matter if I compile in the root directory of project, or in src directory, result is the same - first line of sources.txt is ignored.
So the question is - what I'm doing wrong with above 2 terminal commands? or maybe it's a bug of javac?
javac version - 1.8.0_221
project files themself: https://github.com/Dman-89/42_avaj_launcher
It sounds like your aim is to create a list of source files, and then pass them all to javac to compile. If that is your aim, -sourcepath is not what you want.
You want one of two things:
Do what all real java programmers do
'real' defined as: They do it for money and/or eyeballs, and not as an academic exercise.
Use a build system; gradle or maven are the common choices. They will take care of all this for you far better than a slapdash effort to hack some bash scripts together.
Just pass the java source files
Just remove the -sourcepath part. javac #sources.txt is what you want.
What is going on?
The first 'argument' (first line in your sources.txt file) is the 'value' for the -sourcepath argument, and javac doesn't compile this, because -sourcepath doesn't mean 'compile this stuff' (see later). The rest (lines 2 and further) are just arguments, which is actually what javac will compile.
So what is sourcepath?
To compile source files with javac, you'd write javac foo/A.java bar/B.java. However, what if, say, A.java contains: import lombok.Value;? Javac is now not capable of compiling this file unless javac knows about lombok.Value. Usually such dependencies are already compiled (you have class files in a directory or a jar file), in which case you'd use the -classpath option of javac to tell javac about where to find this stuff.
-sourcepath is similar, except, it's for not-yet-compiled stuff. That means javac will gain awareness of the existence of anything in the sourcepath, in case it comes up that any of that needs to be compiled first, and will only do so if it is needed by any of the actual files you specified for compilation.
Like any -xpath option to javac or java, if you want to specify more than 1 entry, use colons (semicolons on windows) as a separator, not space. Furthermore, the idea is to pass directories and not actual files. And just like -classpath, passing invalid (e.g. non-existing) paths is fine. Then they are just ignored.
Example
javac -sourcepath deps:deps2 src/com/mypkg/Main.java src/com/mypkg/Extra.java
This will tell javac to compile Main and Extra (not deps or deps2 or any files inside). However, if, say, Main.java contains the line: Object o = new bar.baz.Hello();, and the file deps/bar/baz/Hello.java exists, then this command will end up also compiling Hello.java. If deps/bar/baz/Whatever.java also exists, that won't be compiled, unless Whatever is mentioned somewhere in Hello.java, Main.java, or Extra.java. And not in either a comment or just an import statement (import if java-ese for alias, it doesn't actually import anything).
javac will compile the source files specified, e.g. just Baloon.java in your case.
In addition, any classes referenced from those explicitly named source files will also be compiled, if the compiler can find the source files for them. It looks for them on the sourcepath, which defaults to the same as the classpath if not specified.
Assuming Simulator is the class with the main() method (as indicated by the green "play" triangle of the icon), it will directly or indirectly reference all the other source files, so that's the file to specify:
cd src
javac simulator/Simulator.java
Or:
javac -cp src src/simulator/Simulator.java
I'm creating a Submission System where I would like the Framework files in a fixed location on the server - a user will upload their file in a different directory.
If I'm just working with .class files, then the following command works when executed:
java -cp
/SubmissionSystem/Java/Assessment/Framework:/SubmissionSystem/Java/Assessment/Test
Assessment4
I was wondering whether there is a similar command that can be called to compile the .java files in different directories instead of .class files!
I'd appreciate any help!
Yes, just replace java with javac and instead of passing the folder with the sources to the -classpath option, pass it to -sourcepath:
javac -cp /SubmissionSystem/Java/Assessment/Framework -sourcepath "/SubmissionSystem/Java/Assessment/Test Assessment4"
Don't forget proper quoting when the paths contain spaces. That will compile the files in place (so they will mix with the .java source files). You can let javac write them to a new place using the option -d
Working with some basic java apps on CentOS 5 linux and I have my classpath set to point to home/pathToJava/bin which contains javac and java
and I have .java files in home/pathToFolderA/src
and home/pathToFolderB/gen-java
When I run javac and java in home/pathToFolderA/src everything works perfectly
But when I run javac from within home/pathToFolderB/gen-java on fileName.java I get a file not found error, specifically
javac: file Not found: fileName.java
Usage: javac <options> <source files>
Why could this be happening?
Thanks for all help
The classpath is used to find class files, not source files. (Nor is it used to find the java and javac binaries; those are found in your normal path.) You need to specify the files to compile explicitly:
javac /home/pathToFolderA/src/fileName.java
Obviously if you're already in /home/pathToFolderA/src then you can just use fileName.java because that's treated as being relative to your current directory.
You shouldn't set your classpath to point to your JDK bin directory -- instead it should be the PATH environment variable, which serves a different purpose to classpath. (The classpath defines a list of jars and directories containing compiled Java .class code; the PATH variable defines a list of paths where the shell needs to look and locate programs to execute when they are not found in the current directory -- so if you type for instance zip -- it would look in all the directories defined in PATH and figure out that zip program is located under /usr/bin)
Secondly if you want to compile sources from both directory you need to specify:
all the paths where the sources are (both home/pathToFolderA/src and home/pathToFolderB/gen-java)
the path where the compiled .class files to be generated
specify in the classpath any library you might use in your source files
To sum it up, it would be something like this to compile:
javac -d /home/pathToFolderWithResultsOfCompilation -classpath /path/to/some.jar:/path/to/another.jar home/pathToFolderA/src/*.java home/pathToFolderB/gen-java/*.java
and to run your compiled programs:
java -classpath /path/to/some.jar:/path/to/another.jar:/home/pathToFolderWithResultsOfCompilation full.name.of.your.Java
Working with some basic java apps on CentOS 5 linux and I have my classpath set to point to home/pathToJava/bin which contains javac and java
That's wrong. The classpath is used to find *.class files, not operating system specific executables. The bin directory of your JDK does not belong in the classpath. Note that the classpath is also not for finding *.java source files.
When you run javac you need to specify the path to the source file, if it isn't in the current directory.
make sure that your file name contain no spaces
Eg:
HelloWorld.java
usually the errors occur when you rename the file by copy past that will cause a space between the name and the dot (this is the mistake:HelloWorld .java).
and make sure you changed the directory to the same folder your file in
Without a listing of the directory "gen-java" and the exact command you're typing,my guess would be that you're trying to compile a file that doesn't exist. Linux is case sensitive, so maybe that's your problem. Or the file doesn't exist.
I'm compiling a program that has a package statement.
e.g.
package APPC_LU62.Runtime ;
I also have a pre-existing directory structure that matches the package statement.
C:\APPC_LU62\Runtime
How do I keep the javac compiler from creating the same directory structure within the pre-existing one ? i.e.
C:\APPC_LU62\Runtime\APPC_LU62\Runtime
It seems to me the compiler ought to be "smart" enough to check first for an existing directory structure before creating one.
Thanks
In general, the compiler expects the source files and outputs the class files according to the package structure.
If you don't give any -sourcepath (or -classpath if no sourcepath is given) options, the source files are searched relative to the current directory. If a source path is given, the source files are searched relative to this path (in addition to any file directly specified on the command line).
Similarly, if you don't specify any -d options, the class files will be put into directories according to the package structure, relative to the current directory. If you give an -d option, the class files will be put relative to the directory given by the option. Non-existing directories will be created here.
Thus, if you want to create the output in the same directory tree as your source files are, the usual way to go would be to change into the root of this tree (C:\ in your case), and from there call javac:
javac -classpath ... -sourcepath . APPC_LU62\Runtime\*.java
(or list only the java files you actually want to compile). Alternatively, you could add the -d C:\ and -sourcepath C:\ options, and then call the command from whereever you want:
javac -classpath ... -sourcepath C:\ -d C:\ C:\APPC_LU62\Runtime\*.java
The same is valid later for executing the classes with the java command: This also expects the classes in directories according to the package structure, with the root being a directory or jar file mentioned in the class path. Thus you will have to add C:\ to the -classpath for your java call.
(By the way, I would not use the root of some drive as the root of the package hierarchy - better move everything one directory down.)
Would have been better if you had actually posted your javac command and stated clearly where your sources are located, but here goes anyway: when you issue javac -d somedir blahblah.java, javac will create the appropriate directory structure (matching package name hierarchy) starting at directory somedir.
So in your case, you simply need to do:
javac -d c:\ your_files.java
With reference to this post
Receiving "wrong name" NoClassDefFoundError when executing a Java program from the command-line
I did not understand how to solve the problem
Actually in my java source code there' s line :
package es_2011;
when I compile the program through JCreator everything works perfectly.
It creates a folder named es_2011 where to put .class files.
Also the executing operation goes smoothly, the program runs ok.
Now I'd like to use the command line only.
So I placed my java file in the directory where javac.exe is but whenever I try to compile I get the same error
The command I use is: javac ProgAudioJ.java
The path (where javac.exe is ) is : C:\Program files\Java\jdk1.6.0_22\bin
Is someone willing to help me understand in terms of exactly tell me what I have to do?
thanks very much...MAX
The setup used for the looks like this (under windows)
C:\classDir -> is the project
C:\classDir\testpackage -> is the only package used (the package "testpackage")
C:\classDir\testpackage\Main.class -> is the class with the main method inside (important: it is the .class and not .java)
The Main.class looks like following:
package testpackage;
public class Main {
public static void main(String[] args) {
System.out.println("Program started! ;-)");
}
}
go with your command prompt to:
c:\classDir> java testpackage.Main
the result:
Program started! ;-)
According to your problems that it starts in your IDE but not from the console:
- checked if you realy use the path to the .class files?
- with the console go to the directory of you .class files, not the project (e.g. in Eclipse it is the bin directory
- enter the full qualified class name (including packages seperated by . -> e.g. testpackage.Main
More infos can be found under:
http://www.oracle.com/technetwork/java/compile-136656.html
Hope it helped
MAX, if the class defines that it's inside the package es_2011, then it should be in a folder with the same name.
So in your case, put the ProgAudioJ.java in the folder es_2011 and then run
javac es_2011\ProgAudioJ.java
latter to run it, you need the command
java es_2011.ProgAudioJ
You should add javac.exe in your path .Edit your path variable and append path to jdk's bin
then put java file in a dir named es_2011 , as the package declaration is es_2011 then compile
c:\es_2011\javac YourJava.java
and now go back to C:
c:\java es_2001.Yourjava
After reading you other Post: "Receiving "wrong name" NoClassDefFoundError when executing a Java program from the command-line" I guess you go to the directory es_2011 where your ProgAudioJ.class file is located and run
java ProgAudioJ
from that folder.
instaend you have to go to the folder above (cd ..) and run
java es_2011.ProgAudioJ
Each package in Java corresponds to a folder on the filesystem. So a package declaration such as com.stackoverflow would mean that the source classes need to be in a folder ./com/stackoverflow. Typically the whole project would have a separate src folder containing com/stackoverflow.
When you compile the Java classes you DO NOT need to put source files in the same directory as javac.exe, you do however need to make sure that javac.exe is in your operating systems PATH variable. This tells the operating system where it should look for executable files when a command is run, on a *nix machine this would usually be /usr/bin or just /bin but on Windows machine the executables normally live within the applications own directories, that is C:\Program Files\something. Assuming that you've installed JDK correctly, the javac.exe should already be in the PATH you can check this by opening the command line and just running javac (just like that). If you get some output then all is well, the system knows where to find javac.exe.
Next you will need to go to your project folder and type javac -d . src/com/stackoverflow/MainSO.java notice that is run from the project folder. This will create a folder called com in your project root and put the compiled classes in com/stackoverflow. The -d flag tells javac where to put the compiled classes, if you leave that out, the compiled classes will be where the sources are.
Then when you want to run the classes you type java com.stackoverflow.MainSO (no .class). Crucially this command will need to be ran in the directory that contains the root of the class hierarchy (that is the com folder containing the compiled classes). You can specify other places for java to look for the classes by providing a classpath to the java command with the -cp flag. By default the classpath will contain the directory the java command was ran in. Should your project have dependencies external .jar files for example you will need to provide every single one of them (with their full filepath) in the classpath (this goes for the compiler as well). The IDEs do this automatically for you.
Hope that helps.