javac -d option, how does it know which directory to go in? - javac

Hi I have the following directory structure...
I enter this at terminal:
javac -d bin src/com/elharo/math/Fraction.java
and the Fraction.class file gets placed in bin/com/elharo/math instead of bin/
I just wondered why the compiler placed the file there. Is it that the point of having source and bin, so that when you compile a source file it goes in the parallel/mirror bin directory?

The output path will be computed from package and class name of the public class that must be defined in the java source file (which must, incidentally, match the file name minus ".java"). And it will be relative to the directory in the -d option, or relative to the current directory.

This is as expected. /com/elharo/math is the package the class exists in. If you took the class out of this directory an just put it in bin you would like get a noclassdeferror.

Related

Can you use .\swagger-codegen-cli.jar generate to generate files that are not located in the same folder as swagger-codegen-cli?

Using java -jar .\swagger-codegen-cli.jar generate -l typescript-angular -i .\swagger.json, I can turn ".\swagger.json" into a typescript-angular file. However, the .json file must be in the same folder as the swagger-codegen-cli, which is impractical when you have many files to convert (You have to manually download and move every file). I've scoured the web, but haven't been able to find a practical solution. Is there a way to do this? Am I able to integrate swagger-codegen in such a way that I can "mass produce" files? I know I can change the output directory (-o) but that isn't what I'm looking for. Say I have a folder called "scripts" where I've got a lot of .json files. Am I able to call swagger-codegen-cli generate on any file inside of that folder, even if swagger-codegen-cli is located in a different folder?
The -i argument expects a fully-qualified or relative path to an OpenAPI file, or an URL where that file is located. That is, the file does not have to be in the same folder as the Swagger Codegen CLI.
Examples:
# The file is in the current working folder
-i swagger.json
-i ./swagger.json
# The file is in a subfolder of the current working folder
-i sub/folder/swagger.json
-i ./sub/folder/swagger.json
# Relative path to a file in another folder
-i ../../path/to/swagger.json
# Absolute path - Windows
-i C:/path/to/swagger.json
# Absolute path - *nix
-i ~/path/to/swagger.json
# URL
-i https://petstore.swagger.io/v2/swagger.json

protoc --dart_out=grpc:. -Iprotos helloworld.proto - directory does not exist

How do you specify a directory - the following only work if I put my helloworld.proto in a folder named protos
protoc --dart_out=. -Iprotos helloworld.proto
protos: warning: directory does not exist.
helloworld.proto: File does not reside within any path specified using --proto_path (or -I). You must specify a --proto_path which encompasses this file. Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
You should not need to include -I in this case because helloworld.proto is in the current working directory.
-I (proto path) is used by protoc to reference directories that aren't in the current working directory. If you were to use ${PWD}/helloworld.proto for example, I think you'd need need to -I=${PWD}. Even though ${PWD} is equivalent to the current working directory, protoc sees a proto with a directory prefix and expects it to be added to the proto path.
Customarily, you'd need to add a proto path when you have protobuf imports that aren't local. Then, you add -I= and list the directories where these imports may be found.

Fetching current path of the file using Ansible

In Ansible, i need to take a parent directory or current path of file automatically, in some of chef framework we have chef::config,it ll take automatically file path.
e.g:
/tasks/main.yml:
name: execute cmd
command: python file.py
If I have my "file.py" in a tasks folder, I need to execute my playbook from that path only like: /home/playbook/roles/sample/tasks ,then only it taking a script file and running.Suppose when i run from root path i mean /home/playbook/ path,it shows "No such file or directory"
I have tried lookup(env,HOME), It just takes /home alone but not related to that file path.
So to take a current file path how to give in ansible???
Thanks
Answer from comments
script module will copy the file first and then run it. if you use roles, you should place scripts into roles/my_role/files folder.

How to 'set path' automatically when opening Vim from a directory?

I'm trying to get :A (e.g. switch between controller and spec) working in vim-rails. If I navigate to my rails project, run vim ., open a controller file and run :A, I get the error:
E345: Can't find file "app/controllers/widgets_controller.rb" in path
If I then set the path explicitly:
:set path=/Users/me/Documents/Code/my-project
then :A works as expected. How can I set the path initially when I open a directory with Vim?
Not exactly when opening a directory: since you seem to be working with projects, give the project plugin a try.
Using that, you could execute arbitrary commands when entering or leaving a project.
From the plugin description:
You can use this plugin's basic functionality to set up a list of
frequently-accessed files for easy navigation. The list of files
will be displayed in a window on the left side of the Vim
window, and you can press or double-click on
filenames in the list to open the files. This is similar to how
some IDEs I've used work. I find this easier to use than
having to navigate a directory hierarchy with the file-explorer.
It also obviates the need for a buffer explorer because you
have your list of files on the left of the Vim Window.
This is what I do to have a local .vimrc file per project:
In my ~/.vimrc file I define the following:
let s:project_root = finddir('.git/..', expand('%:p:h').';')
let s:local_vimrc = join([s:project_root, '.vimrc'], '/')
if filereadable(s:local_vimrc)
exec "source " . s:local_vimrc
endif
In the project root (which usually has a .git dir) I do the following:
touch /path/to/project/.vimrc
In the .vimrc file, I prepend the path variable (notice the ^path). Using :set path^= instead of :set path+= prepends the new directory to the beginning of the path instead of appending it to the end. This makes it faster for the find command to search for your files.
let s:project_root = finddir('.git/..', expand('%:p:h').';')
exec 'setlocal path^='.s:project_root
setlocal wildmode=longest,list,full
setlocal wildmenu
setlocal tags=/path/to/project/root/tags
Now the :find command should only display files and directories relative to the project root.

javac command is not able to find .class file in the current directory needed to compile a source file

The files A.java and B.class(Bytecode version of B.java) are in the current directory.
A.java uses B.java in the following way:
class A {
B b;
}
From what I have read the JDK tools first look in the directories where the Java standard libraries are installed. If the class is not found in the standard libraries, the tool searches in the class path. When no class path is defined, the default value of the class path is assumed to be the current directory. Then why is the following command not working:
C:\current> javac A.java
The package structure must match the directory structure, otherwise javac will fail.
http://kevinboone.net/classpath.html
Comment out or get rid of the package statements in the begin of your classes. Since you do keep both java classes in the directory where you compile, the compiler should be able to find the B.class without trouble.

Resources