Compiling java programs from CLI using javac - javac

I have the following directory structure form where I am invoking javac
src/ lib/ build/
Under src:
src/com/xyz/App.java -- contains the main class
src/com/xyz/base/j1.java
src/com/xyz/base/j2.java
src/com/xyz/exceptions/e1.java
src/com/xyz/hibernate/factory/hbf1.java
src/com/xyz/hibernate/helper/hbh1.java
Under lib:
lib/hibernate.jar
lib/commons.jar
At the top level, I am using the following javac command:
javac -verbose -classpath lib/hibernate.jar:lib/commons.jar -d ./build -sourcepath ./src com/xyz/*.java
and I receive the following output
javac: No match
How should the args be passed to javac?
And here is the ANSWER:
javac -verbose -d build -classpath lib/commons.jar:lib/hibernate.jar [complete path for ALL the directories]/*.java

javac won't expand wildcards, that's what your shell does. so when you specify com/xyz/*.java , that will not expand to anything, as those files are under src/ but the shell doesn't know that. If you list out every java file as com/xyz/Foo.java com/xyz/Bar.java etc, it should work.
(note that if you're on windows you'll need ; and not : to seperate classpaths)
Something like this might work:
javac -verbose -classpath build:lib/hibernate.jar:lib/commons.jar -d ./build ./src/com/xyz/base/*java ./src/com/xyz/exceptions/*.java ./src/com/xyz/hibernate/factory/*.java ./src/com/xyz/*.java
I'd not do this other than as an exercise on how to compile from a command line, otherwise use a build tool like ant

Related

Aldec Active-HDL VSimSA Converting BDE files into VHDL files

I'm trying to automate compiling my Aldec block designs using the VSimSA shell instead of using the Aldec GUI. Currently, I am able to get the following command to work in the GUI console with the desired results (producing a converting a .bde file to a .vhd file in the compile directory as well as using the VHDL compiler on the .vhd file).
'''
acom -w -O3 -e 100 -work gen8_ieee -2008 -d <path to compile directory> -s <path to library.cfg> -j <path to projlib.cfg> <BDE file path>
'''
When issuing the same command in the VSimSA shell, I receive the following error. This error occurs for multiple lines in the bde file. If I run the same command in VSimSA on a .vhd file, it compiles with no issues.
*Error: COMP96_0010: <BDE file path> : (12, 36) : Invalid literal.*
Line 12 in the BDE file :
#DEFAULT_RANGE0="<range<index=\"0\"><name=\"bist_cctrl\"><left=\"bcw-1\"><direction=\"downto\"><right=\"0\"><initial_value=\"\"><delay=\"\">>"
Is there another command that needs to be issued first to convert the BDE file to a VHDL file prior to running the 'acom' command? The help documentation states the 'acom' command works with BDE files.

cannot execute RUN mkdir in a Dockerfile with space in directory name

I want to create a file in C drive while building docker image and using command as below
RUN mkdir "C:\Program Files\Microsoft Passport RPS"
but it throws error:
Step 6/6 : RUN mkdir "C:\Program Files\Microsoft Passport RPS"
---> Running in ab58c6f2948d
[91mmkdir : A positional parameter cannot be found that accepts argument 'Files\Microsoft'.
At line:1 char:76
+ ... e = 'SilentlyContinue'; mkdir C:\Program Files\Microsoft Passport RPS
[0m[91m+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[0m[91m + CategoryInfo : InvalidArgument: (:) [mkdir], ParentContainsErro
[0m[91m rRecordException
+ FullyQualifiedErrorId : PositionalParameterNotFound,mkdir
Tried above command with forward as well as back slash.
I have tried multiple other command as below:
ENV PATH_WITH_SPACE "C:/Program Files/Microsoft Passport RPS"
RUN mkdir $[PATH_WITH_SPACE]
RUN mkdir ["C:\Program Files\Microsoft Passport RPS"]
Can you please help me with appropriate command?
Came across same problem. None of the answers worked for me.
I finally got it working by escaping space with `
RUN mkdir "C:\Program` Files\Microsoft` Passport` RPS"
COPY . "C:\Program` Files\Microsoft` Passport` RPS"
Another approach is to use Shell, and declare escape explictly
While the JSON form is unambiguous and does not use the un-necessary cmd.exe, it does require more verbosity through double-quoting and escaping. The alternate mechanism is to use the SHELL instruction and the shell form, making a more natural syntax for Windows users, especially when combined with the escape parser directive
# escape=`
FROM microsoft/nanoserver
SHELL ["powershell","-command"]
RUN New-Item -ItemType Directory C:\Example
ADD Execute-MyCmdlet.ps1 c:\example\
RUN c:\example\Execute-MyCmdlet -sample 'hello world'
You have to escape the space, some like:
RUN mkdir "C:\Program Files\Microsoft\ Passport\ RPS"
Or using the JSON format:
RUN ["mkdir", "C:\\Program Files\\Microsoft\ Passport\ RPS"]
note: using JSON format is necessary to escape backslashes. This is particularly relevant on Windows where the backslash is the path separator.
We can use PowerShell command to create folder with spaces.
Try this:
RUN powershell -Command New-Item -Path 'C:\Program Files\Microsoft Passport RPS' -ItemType Directory
It Works !!!

swagger-codegen custom generator ClassNotFound

I'm writing a custom generator for swagger-codegen. When I attempt to run the generator with
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i path/to/swagger.json -l com.my.company.codegen.MyGenerator -o outputlocation
it fails with
Can't load config class with name com.my.company.codegen.MyGenerator
... list of built-in generators...
at io.swagger.codegen.CodegenConfigLoader.forName(CodegenConfigLoader.java:31)
at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:286)
at io.swagger.codegen.cmd.Generate.run(Generate.java:186)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Caused by: java.lang.ClassNotFoundException: com.my.company.codegen.MyGenerator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at io.swagger.codegen.CodegenConfigLoader.forName(CodegenConfigLoader.java:29)
... 3 more
I'm not having trouble with any of the built-in generators.
What I did to get here (following the readme):
cloned the project
mvn package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta -o output/myLibrary -n myGenerator -p com.my.company.codegen
and then the above code
I also tried running mvn package again after making my custom generator (which did not make a .jar file anywhere I could find), and tried creating the .jar file myself. Got the same error.
Also FYI, my confusion was definitely increased by some apparent documentation inconsistencies: expected location for my module differs between here and the classname expected here (end of that section). Also, the command for making your own module specifies modules/swagger-codegen-distribution... when I believe it should specify modules/swagger-codegen-cli.... And the guidance in the project readme doesn't seem very congruent with the custom module readme that is generated here.
I don't normally work with Java, so apologies if I'm just missing something super obvious. Thanks in advance for any help!
After trying a bunch of things / internetting, here is what worked:
java -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen generate -i path/to/swagger.json -l com.my.company.codegen.MyCustomCodegenGenerator -o outputlocation
Here are the steps I had to take start to finish to create a custom generator:
git clone from source
cd swagger-codegen
mvn package
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar meta -o output/myLibrary -n myCustomCodegen -p com.my.company.codegen. This will create output/myLibrary and subdirectories, where you should find myCustomCodegenGenerator.java ("Generator" is appended to the class name you specify in the command). You should also be able to find the mustache templates within the resources subdirectory.
Make whatever changes you want to myCustomCodegenGenerator.java and the templates.
cd output/myLibrary
mvn package
cd ../..
Now generate your custom library: java -cp output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen generate -i path/to/swagger.json -l com.my.company.codegen.MyCustomCodegenGenerator -o outputlocation (building in step 7 should have generated target/myCustomCodegen-swagger-codegen-1.0.0.jar for you)
Notes:
Obviously the cding is based on where I put things, just wanted to be clear on relatively where I was when running commands
If you are just using the default generated base class for your generator (instead of subclassing an existing language), you will get an exception FileNotFound for myCustomCodegen/myFile.mustache -- it's from this optional block which you can just comment out of your custom generator class.
Remember to mvn package your custom module when you make changes
You'll need to include your custom library in the java command. For example:
java -cp path/to/your/jar.com:modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
-jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar \
{args}
Note that if you are attempting to create a generator in Windows and run it from PowerShell, I had to modify #baylee's steps as follows:
mvn install
and
java -cp 'output/myLibrary/target/myCustomCodegen-swagger-codegen-1.0.0.jar;modules/swagger-codegen-cli/target/swagger-codegen-cli.jar' io.swagger.codegen.Codegen -i path/to/swagger.json -l my-language -o outputlocation

Javac bootclasspath option

I try to add -bootclasspath option when compiling java source like this:
javac -classpath lib/* -target 1.6 -source 1.6 -bootclasspath /usr/lib/jvm/java-7-oracle/lib/*.jar Hello.java
I am getting the following error when compiling:
javac: invalid flag: /usr/lib/jvm/java-7-oracle/lib/dt.jar
Usage: javac <options> <source files>
use -help for a list of possible options
How should I add the bootclasspath parameter?
The shell expands /usr/lib/jvm/java-7-oracle/lib/*.jar to the list of jars, so effectively javac is called like that:
javac ... -bootclasspath /usr/lib/jvm/java-7-oracle/lib/rt.jar /usr/lib/jvm/java-7-oracle/lib/dt.jar ... Hello.java
You can avoid that by putting the path between single quotes:
javac ... -bootclasspath '/usr/lib/jvm/java-7-oracle/lib/*.jar' ... Hello.java
I added this -bootclasspath /usr/lib/jvm/java-7-oracle/jre/lib/rt.jar instad of /usr/lib/jvm/java-7-oracle/lib/*.jar and it worked fine.
Try something like this:
java -bootclasspath $(set -- /usr/lib/jvm/java-7-oracle/lib/*.jar ; IFS=:; echo "$*")
Be running bash when you try it, the bourne again shell is the bee's knees.

Need to create a folder in remote server usint ant

using ant scp i can able to copy a file from local system(windows) to server(linux).so what i need is i want to create a folder by the system date at specified directory in linux system using ant and copy the file to the folder which created..
this is my ant script:
<sshexec host="hostname:22" username="****" trust="true"
password="fcubs"
command="mkdir $/home/desktop/<folder to be creted here>"/>
<scp todir="username#hostname:/home/desktop" password="*****" trust="true">
<fileset dir="D:\kkk"/>
</scp>
pls help me
thanks in advance
you can use such linux command which creates directory:
export ATD=`date '+%h-%d-%Y_%H:%M:%S'` && cd /path/to/specified/dir && mkdir $ATD && cd $ATD
it will create dir (for example) "Nov-14-2012_17:41:02" in the dir /path/to/specified/dir and will cd to it.
after executing this command you can simply copy your file to the directory.

Resources