$ is not recognized as an internal or external command - java

I am trying to develop my own app using Android Studio and Google Calendar API.
The Google page says this:
In your working directory, run the following commands:
$ gradle init --type basic
$ mkdir -p src/main/java src/main/resources
When I try to put that into the command line, it comes back with:
'$' is not recognized as an internal or external command,
operable program or batch file.
Am I putting this in the wrong place?
I didn't even realize they were assuming that people are using Linux. I have a Windows machine. I have tried all the suggestions and am not getting anywhere so far, so I'm not sure where to go from here.

Not a problem at all! The $ means the following command needs to be run in the terminal (in this case, a Bash terminal). So try opening one on your machine and cd'ing into the project. Then run this:
gradle init --type basic && mkdir -p src/main/java src/main/resources
EDIT: Changed it to make use of the && operator

$ is shorthand in documentation for your command prompt and the lines mean you've got two things to enter at subsequent prompts:
gradle init --type basic and
mkdir -p src/main/java src/main/resources

Related

Why I always received invalid flag error while building .jar

Why I always received invalid flag error while I'm building .jar
When I using Build Jar to make a .jar file in java:
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Desktop/projects/Swings/source/library/* && jar cvf build-jar/window.jar build-jar *
I always receive a error:
error: invalid flag: /Users/user/Desktop/projects/Swings/source/library/controller
Usage: javac <options> <source files>
If I use path to .class file:
rm -rf build-jar && mkdir build-jar && javac -d build-jar /Users/user/Library/Application Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/* && jar cvf build-jar/window.jar build-jar *
I also receive an error:
zsh: no matches found: Support/Code/User/workspaceStorage/ca7d24d42ba31de4cfb244fc0f239d07/redhat.java/jdt_ws/swings_12c4bbf0/bin/*
I'm not very familiar with building jar, It make me headache, And I don't know what to do, the other question's solution or solution on internet are all not work for me(like Classpath invalid flag - Java, etc.)
I'm using IDE vscode, and using vscode extension "JAR Builder"
'star' expansion is a thing your shell does. When you type ls *.txt in your shell, that's not what is run. Your shell itself detects that * and will go out and figure out what you really mean. What actually ends up being executed is ls a.txt b.txt c.txt - everything that star matches, separated out by spaces.
The same is happening here. Hence, why you get this error: Your shell is executing:
javac -d build-jar
/Users/user/Desktop/projects/Swings/source/library/controller
/Users/user/Desktop/projects/Swings/source/library/model
/Users/user/Desktop/projects/Swings/source/library/... and all the other dirs...
and here's the clue: javac does not work like this. You cannot specify directories and expect it to know what to do. You need to list each java file individually, which means you need one heck of a long command line.
There is a reason nobody in the java ecosystem builds apps with the command line. Everybody uses maven or gradle instead. So should you. It'll solve this problem; you just stick your sources in the right location and maven / gradle figure it out from there. Have as many packages as you want.

Execute a .jar file using shell script

I want to execute a jar file of DOMO CLI from a shell script. The jar file itself has some functions which I want to call after I call the main jar file. The problem which I am facing is that after it executes the jar file, I am not able to pass the additional commands to execute inside that jar through a shell script. It just stops after calling jar and doesn't take further commands. Can anyone please help? Below is the code I am calling from a shell script.
java -jar XX.jar
The commands are as below which follow the above jar. So once we enter into the above jar we have to execute the below commands one after the other. I am not sure how to achieve this through a shell script.
connect -s X.domo.com -t Ysssss
upload-dataset -a -i dhdhdhdh -f /prehdfs/dev/comres/herm/data/yyyy.csv
Did you try using pipes and inputs.
When you execute above it runs it under a child shell.
You may try below format if not tried already
$ (echo "connect -s X.domo.com -t Ysssss" && cat) | java -jar XX.jar
If you can reference a file in your use case, you could put your commands in a file.
File: list_my_datasets.domo
connect -t ... -s ...
list-dataset
quit
then run the command:
java -jar domoUtil.jar -script list_my_datasets.domo > datasets
I wanted the data from it so I piped to a file (where I had to grep what I wanted), but you would omit that I believe, unless it has some output you'd want to check. I haven't tested with the upload command, but I would hope any commands substituted or added to the example work similarly.
Domo docs on scripting

How do I execute a shell command path after creating a new directory in Makefile?

I'm trying to get an updated path of my variable service_SOURCES, after I have generated some files from jaxb with my makefile:
service.jar$(EXEEXT): $(service_SOURCES)
mkdir -p bin
xjc -d src -p gen.files ./src/resources/info.xsd
javac -cp service_SOURCES
service_SOURCES := $(shell find ./src -name "*.java")
I am trying to compile my existing java code with my generated java code Currently, my service_SOURCES variable finds my folder containing my java files, and compiles them all together. I need it to update to include the newly generated java folder, so it compiles my new java files along with my old java files.
I've tried linking the above commands together using && but the shell command still doesn't update. If I run the above commands in terminal it works, but when I run it in my Makefile the path won't update properly.
(moving to answer as this doesn't fit in comment)
You should understand that Make runs in two phases -- The dependency tree is built in the first phase, and the rules are run in the second. This means that the dependency tree cannot be updated by a shell command run after files are generated by a recipe. If you want to do something like this (and I agree with #JohnBollinger, this might not be the best idea), you might need to split your logic between two makefiles, or have a self-recursive makefile. Either way you need to generate the files, then call the second makefile, which can then build a new dependency tree based on a timely shell command.
Alternative:
service.jar$(EXEEXT): _target_to_generate_java_files_
mkdir -p bin
xjc -d src -p gen.files ./src/resources/info.xsd
javac -cp $$(find ./src -name "*.java")

Java not running in crontab

java -jar /home/scripts/relay.jar is working fine when I launch from command line. The command produces a file: relay.txt
In crontab
/usr/bin/java -jar /home/oneprovider/relay.jar
is not producing anything. I first had it without /usr/bin/ but then did which java and added absolute path with no luck. The jar file was originally written for windows but it works in Linux fine when launched from command line
What am I missing?
Agreed that the working directory is likely the problem. Can you write a shell script that wraps the java invocation and sets the working directory? Something like:
#!/bin/sh -e
cd /home/oneprovider
/usr/bin/java -jar /home/oneprovider/relay.jar
Then change the cron job to run the script instead. Remember to chmod it and make sure that the cron user can write to the directory if it isn't your personal crontab.

osmdroid-packager Could not find or load main class

This is mostly a java question, and likely something I'm overlooking.
I've been trying to use osmdroid-packager (http://code.google.com/p/osmdroid/wiki/HowToUsePackager) to package map tiles for my android app, on Ubuntu Linux. I've been following the instructions on the site above, and have run into some issues.
I have in my current directory, osmdroid-android-3.0.8.jar, osmdroid-packager-3.0.8.jar, and slf4j-android-1.6.1-RCq.jar. I've setting the classpath, and attempting to run using the commands below gives me the error
'Could not find or load main class
org.osmdroid.mtp.OSMMapTilePackager'
I've also tried different variations of setting the classpath (setting classpath, CLASSPATH, to the jars, to the current directory, with -classpath) with the same result. The best I can come up with is that the class is not in the jar.
The commands I tried from the website above were:
set classpath='osmdroid-android-3.0.8.jar;osmdroid-packager-3.0.8.jar;slf4j-android-1.6.1-RC1.jar;sqlitejdbc-v056.jar'
java org.osmdroid.mtp.OSMMapTilePackager -u http://tile.openstreetmap.org/%d/%d/%d.png -t Mapnik -d haarlem.zip -zmax 18 -n 52.4244 -s 52.3388 -e 4.6746 -w 4.594
java -cp . org.osmdroid.mtp.OSMMapTilePackager
also gives the same error.
I haven't downloaded a copy of sqlitejdbc yet, but I'm pretty sure that's not the issue.
Use a 3.0.3 version to osmdroid-packager , osmdroid-packager for example
Use the same versions od libriries to this prompt command
set classpath=osmdroid-android-3.0.3.jar;osmdroid-packager-3.0.3.jar;slf4j-android-1.5.8.jar;sqlitejdbc-v056.jar
java org.andnav2.osm.mtp.OSMMapTilePackager -u http://tile.openstreetmap.org/%d/%d/%d.png -t Mapnik -d haarlem.zip -zmax 18 -n 52.4244 -s 52.3388 -e 4.6746 -w 4.5949

Categories