this is my project tree:
.
├── README.md
├── package.json
└── src
└── xyz
└── pagenote
├── HandlerTestA.class
├── HandlerTestB.class
├── Main.class
If I am in the folder src, I can execute Main.class by
src# java xyz.pagenote.Main
It works, but I want to execute it in the current folder, I have tried
.# java ./src/xyz/pagenote/Main
It doesn't work, what can I do?
For the command java, the default classpath is the current working directory (.).
So when executing xyz.pagenote.Main from the src directory, and the classpath flag is not specified, java will look for the class file in src/xyz/pagenote.class
So to execute from a directory other than src, you have to specify the classpath like:
$ java -classpath /path/to/src xyz.pagenote.Main
I find the solution, we can point a classpath for java:
.# java -classpath ./src xyz.pagenote.Main
this command will let java execute it right
Related
I am using Bazel with Golang, but the question is no Go-specific. I have a common go directory structure:
cmd/
├── mycommand/
│ ├── BUILD.bazel
│ ├── main.go
│ └── somefolder
│ └── other.go
├── othercommand/
│ ├── BUILD.bazel
│ └── main.go
pkg/
└── mypackage/
├── BUILD.bazel
└── init.go
BUILD.bazel
WORKSPACE
... and I'd like to reference targets under the cmd folder. I have a bazel query that will give me the list of those targets:
bazel query 'kind("go_binary", deps(//cmd/...))'
//cmd/mycommand:mycommand
//cmd/othercommand:othercommand
The question: How can I include this query in a BUILD.bazel file, something like the following:
pkg_tar(
name = "release",
srcs = kind("go_binary", deps(//cmd/...)),
mode = "0644",
)
...which gives
ERROR: /some/path/BUILD.bazel:10:12: name 'kind' is not defined
ERROR: /some/path/BUILD.bazel:10:30: name 'deps' is not defined
Build targets need to be statically referenced in BUILD files, so embedding queries as inputs to rule attributes does not work.
However, there are a couple of ways to dynamically generate targets to be used statically in the BUILD files:
1) Run a tool that generates a BUILD file before running Bazel. rules_go's Gazelle is a good example.
2) Write a repository rule that invokes non-hermetic tools to dynamically generate targets that your BUILD files can depend on.
Note that you may come across the genquery rule, which does let you perform a query on targets, but the rule outputs to a file during Bazel's execution phase, and not a Starlark list that can ingested into other rules' attributes during the analysis phase, which happens before the execution phase.
I have the following structure:
/Jenkinsfile/script2.groovy
/Jenkinsfile/pipeline2.yaml
script1.groovy
pipeline1.yaml
There's a reference in script1 to the pipeline using:
yamlFile "pipeline1.yml"
or
yamlFile "./Jenkinsfiles/pipeline2.yaml"
And works fine. I'm trying to use the same pipeline file on script2 but can't make it work.
Here's the relevant part of the script:
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
Any idea?
Note: pipeline1 and pieline2 are the same files just showing different locations.
Given the directory structure you mentioned:
.
├── Jenkinsfile
│ ├── pipeline2.yaml
│ └── script2.groovy
├── pipeline1.yaml
└── script1.groovy
The following files can be read from within their parent directory as follows:
For script1 ran from ./
groovy ./script1.groovy is able to read both ./pipeline1.yaml and ./Jenkinsfile/pipeline2.yaml
For Script2 ran from ./
groovy ./Jenkinsfile/script2.groovy is able to read ./pipeline1.yaml, since its in the same directory the file ./Jenkinsfile/script2.groovy is being run from i.e. ./
groovy ./Jenkinsfile/script2.groovy is able to read ./Jenkinfile/pipeline2.yaml also because the path is relative.
I think you could possibly simplify this by just having the files reside in one directory. And also using the syntax readYaml(file: './nameOfFile.yaml') readyaml section.
.
├── pipeline1.yaml
├── script1.groovy
├── pipeline2.yaml
└── script2.groovy
I'm trying to make bazel build a jar and an so file for a flutter project but every time I type 'bazel build' into the command prompt I keep getting
ERROR: The 'build' command is only supported from within a workspace (below a directory having a WORKSPACE file).
See documentation at https://docs.bazel.build/versions/master/build-ref.html#workspace
I've read some documentation it seems like the solution is to create a blank file called 'WORKSPACE' but I don't understand where this file is supposed to be stored. here's a link to the documentation I read https://docs.bazel.build/versions/2.0.0/tutorial/java.html
thanks in advance!
WORKSPACE file goes to the root of your workspace (source). It's the top directory for all your build packages and start of there absolute path you'd refer too with //. For instance if you had a tree like this:
.
├── BUILD
├── a_source_file
├── package1
│ ├── BUILD
│ └── other_source
└── package2
├── BUILD
└── another_source
You would construct your workspace where all your packages converge (root they share) as:
.
├── BUILD
├── WORKSPACE
├── a_source_file
├── package1
│ ├── BUILD
│ └── other_source
└── package2
├── BUILD
└── another_source
And your build targets could then be for instance: //:a_build_target or //package2:another_target.
Problem: I have a one single repository where I have to walk through the repo to find a specific Jenkinsfile to run the pipeline. Note that I want to define the path to this Jenkinsfile explicity so I thought about having a jenkinsfilePath.yml in root directory of the repo, read the yaml, change directory and run Jenkinfile from the path. The folder structure is as follows:
testingSingleRepo
├── Jenkinsfile
├── feature_flagging
│ ├── Jenkinsfile
│ ├── __init__.py
│ ├── src
│ └── tests
└── jenkinsfilePath.yml
I am having issue running Jenkinsfile inside feature_flagging from the root Jenkinfile in testingSingleRepo. I was successful in changing directory to the folder feature_flagging by using dir. After googling a lot with similar questions, I came across the function build but I could not make that work. Any suggestions/solutions?
Calling a Jenkinsfile from a main pipeline, we can use load
load 'feature_flagging/Jenkinsfile'
So after looking around, I have decided to go with another approach. I have decided that I will have a master Jenkinfile in the root where I will have a generic pipeline setup. It will read the yaml file, change directory and execute shell scripts inside Jenkins/ folder accordingly. The folder will consist of generic scripts that reflects to the root Jenkins pipeline such as setup.sh,test.sh, deploy.sh etc. The folder structure will look something like below:
testingSingleRepo
├── Jenkinsfile
├── feature_flagging
│ ├── Jenkins/
│ ├── __init__.py
│ ├── src
│ └── tests
└── jenkinsfilePath.yml
Given a path to a source file within the workspace, how can I derive the label that Bazel uses to refer to the file. This seems to depend on what packages exist. For example, if I have this structure:
.
├── BUILD
├── WORKSPACE
└── src
└── bar
└── foo.go
Then the label for src/bar/foo.go is //src/bar/foo.go. However, if I have this structure:
.
├── BUILD
├── WORKSPACE
└── src
├── BUILD
└── bar
├── BUILD
└── foo.go
Then the label for the same file is //src/bar:foo.go.
Is there a way to get Bazel to tell me what the label that identifies a file is, or must I to derive it based on the presence/absence of BUILD files at various levels of the workspace tree?
If a valid label exists for path/to/file.txt, running bazel query path/to/file.txt will return you the absolute label.
e.g. for the first example:
$ bazel query src/bar/foo.go
//:src/bar/foo.go
and for the second example:
$ bazel query src/bar/foo.go
//src/bar:foo.go
If the file is not referenced in any rule (filegroup, exports_files, etc) in any BUILD file, it will not have a label.