How do I run PigUnit on the command line - hadoop

It isn't clear to me how to run PigUnit on the command line. I've seen some documentation that mentions some interaction with JUnit, but I don't have much experience with it.
So, if I have pigunit.jar, junit.jar and my PigUnitTests.jar in the same folder, how do I run PigUnit on the command line?
Using pig-0.10.0

You actually want to run jUnit, so assuming your jars are in the current directory, use:
java -cp ./pigunit.jar:./junit.jar:./PigUnitTests.jar org.junit.runner.JUnitCore <Your.Test.ClassName>

Related

Error: Unable to access jarfile build/libs/gs-spring-boot-0.1.0.jar?

I follow the instructions in https://spring.io/guides/gs/spring-boot/#scratch, but when it says to run:
./gradlew build && java -jar build/libs/gs-spring-boot-0.1.0.jar
the build fails with the above error.
There is message before the failure that says:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.8.1/userguide/command_line_interface.html#sec:command_line_warnings
but everyone online says that's just a warning.
The build doesn't appear to create or download build/libs/gs-spring-boot-0.1.0.jar.
Currently completely blocked on first attempt to use Gradle.
I just had this problem.
The tutorial is in error in what you need to run. It should be
$ gradlew build && java -jar build/libs/gs-rest-service-0.1.0.jar
I think that they updated the code, but forgot to update the tutorial.
I had the same issue when build a simple project with Maven on Intellij IDEA. (Ubuntu 18.04.2).
Just typed terminal (in project directory):
$ sudo mvn package
$ java -jar ./target/(your-project-name)-(<version> at pom.xml).jar
For example my project name is hello-world-spring and version name in pom.xml is <version>0.0.1-SNAPSHOT</version>, I have to type:
$ sudo mvn package
$ java -jar ./target/hello-world-spring-0.0.1-SNAPSHOT.jar
Maybe this method can work for gradle as well.
Please check the path of the jar file build/libs/gs-spring-boot-0.1.0.jar. For your case, the jar might be in a different folder. If your code is in a module in the main project, then the jar will be in the build folder of the module.
If you git clone the repo, then the tutorial works. If you "To start from scratch, move on to Build with Gradle.", then the tutorial doesn't work. There are missing setup steps.
I got the same issue and I changed the command to java -jar target/rest-service-0.0.1-SNAPSHOT.jar (I checked the .jar file in target folder and found that the file name was incorrect).
Parent folder of my project was having spaces in it's name, i changed it to the underscore and it worked.
Looked at the command line as it was in the official guide:
./gradlew clean build && java -jar build/libs/gs-actuator-service-0.1.0.jar
First, the above command line has two parts:
(1) ./gradlew clean build //Use gradle wrapper to build
(2) java -jar build/libs/gs-actuator-service-0.1.0.jar //To run an application packaged as a JAR file
Now, one might run into issues with one part or both parts. Separating them and running just on thing at a time helped troubleshoot.
(1) didn't work for my Windows, I did the following instead and that built the application successfully.
.\gradlew.bat clean build
Now moving to (2) java -jar build/libs/gs-actuator-service-0.1.0.jar
It literally means that "Run a jar file that is called gs-actuator-service-0.1.0.jar under this directory/path: build/libs/" Again, for Windows, this translates to build\libs\ , and there's one more thing that may catch you: The jar file name can be slightly different depending on how it was actually named by the configuration in initial/setting.gradle:
rootProject.name = 'actuator-service'
Note that the official guide changed it from 'gs-actuator-service' to 'actuator-service' in their sample code but hasn't updated the tutorial accordingly. But now you know where the jar file name comes from, that doesn't matter anymore, and you have the choice to rename it however you want.
Having all the factors adjusted, below is what eventually worked in my case:
java -jar build\libs\actuator-service-0.0.1-SNAPSHOT.jar
or
java -jar C:\MyWorkspace\Spring\gs-actuator-service\initial\build\libs\actuator-service-0.0.1-SNAPSHOT.jar //with fully qualified path
If you are curious where does "-0.0.1-SNAPSHOT" come from, here it is:
in build.gradle
version = '0.0.1-SNAPSHOT'
Again, you have the choice to modify it however you want. For example, if I changed it to 0.0.2-SNAPSHOT, the command line should be adjusted accordingly
java -jar build\libs\actuator-service-0.0.2-SNAPSHOT.jar
Reference: https://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html
Because you are trying to execute .jar file that doesn't exist. After building the project go to ./build/libs and check the name of freshly built .jar file and then in your project directory run:
./gradlew build && java -jar build/libs/name-of-your-jar-file.jar
or you can set version property to empty string in your build.gradle file
version = ''
after that:
./gradlew build && java -jar build/libs/your-project-name.jar
For Windows, these commands solved the problem: "Error: Unable to access jarfile springboot.jar":
cd target
java -jar springboot-0.0.1-SNAPSHOT.jar
run ./mvnw package
Now a folder named target is created and you can see a jar file inside it.
then execute java -jar target/<jarfilename>

How can I run single groovy class file independently in gradle?

I have 2 groovy class files under one rootProject. I want to run just one of them without running the other one. How can I do that using intellij command line and command prompt. Right now when I run the rootProject both files run one after the other. Is there any setting required build.gradle file then please explain hoow can I do that as I am very new to gradle and don't know much about it. Thanks!
If you have only those two groovy scripts (and there is nothing to compile etc.), you do not need Gradle to run it at all. From command line call
groovy <filename>.groovy
To run the script directly from Gradle Script, use
new GroovyShell().run(file('somePath'))
Yes you can create intellij config to run your script.
Follow these steps:
1) Edit configuration
2) Add new Groovy configuration
3) Browse you script
4) Run your script

Running a groovy script created in STS(Spring Tool Suite) using the command line

I have used the STS(Spring Tool Suite) to create a compiled groovy script which exists as a file on windows called Test.class. I am able to right click on the file in STS and execute it which works well.
However - I want to be able to execute the script on the windows command line, so far I have tried various ways but have not been successful. I have tried the following...
java -cp C:\Users\MyName\springsource\sts->
3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\
org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar Test.class
But that does not work it gives me an error --> Error: Could not find or load main class Test.class
Any Pointers?
You are trying to run a test case, so you really ned to be launching junit and ass this test as the test to run.
The easiest thing to do is to download a distribution of groovy, unzip, and run:
groovy Test.groovy
Step 1
In STS(Spring Tool Suite) ,Create a Groovy Class e.g. Customer.groovy file. Specify a Package Name e.g. com.customer. In the main method put in code to validate the code is being called e.g. println ‘test’.
Step 2
Go to your command line (Windows use command prompt). Switch\cd to the ROOT directory of your project. Execute the command below.
Step 3
execute java -cp C:\Users\Profile\springsource\sts-3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. com.customer.Customer
The code should run.
V Important
If like me, you do not have a class and you only have a groovy script then in step#3 specify the Groovy script name without the suffix.
Test is naked? (without package name?) try this.
java -cp C:\Users\MyName\springsource\sts-> 3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\ org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar;. package.Test
Pay attention to ;. and package name.

How run mahout in action example ReutersToSparseVectors?

I want run "ReutersToSparseVectors.java". I can compile and created JAR file without problem.
I compiled this file by below command:
javac -classpath hadoop-core-0.20.205.0.jar:lucene-core-3.6.0.jar:mahout-core-0.7.jar:mahout-math-0.7.jar ReutersToSparseVectors.java
created JAR file with below command:
jar cvf ReutersToSparseVectors.jar ReutersToSparseVectors.class
When I write java -jar ReutersToSparseVectors.jar to run, give me below error:
Failed to load Main-Class manifest attribute from
ReutersToSparseVectors.jar
Do you can help me to solve this problem?
IF this example can run with hadoop, please me that how i can run this with hadoop.
instead of using -jar option, then it's better to to run:
java -cp mahout-core.jar:... mia.clustering.ch09.ReutersToSparseVectors
or you can use mvn exec:java command, as described in README for examples...
mvn exec:java -Dexec.mainClass="mia.clustering.ch09.ReutersToSparseVectors"
Or you can run this file directly from your IDE (assuming, that you correctly imported Maven project).
P.S. your command isn't working, because to run with -jar switch, the .jar file should have special entry in manifest that describes that class should be started by default...
P.P.S. It's better to use book's examples with Mahout 0.7, as they were tested for it. You can use it with version 0.7 if you need, by then you need to take source code from mahout-0.7 branch of repository with examples (link is above)

How to Execute Clojure File?

How can I run a clojure file/script, which uses clojure-contrib, from the command line? My (winodws) machine has clojure-1.2.1.jar and clojure-contrib-1.2.0.jar on the classpath. Note: I can start the REPL with: java clojure.mainand I can execute *.clj files that DO NOT use clojure-contrib with: java clojure.main file-name.clj
You need to add the clojure-contrib jar to the classpath. Since you are using windows, you add multiple classpaths by separating the entries with semicolons.
java -cp clojure-1.2.1.jar;clojure-contrib-1.2.0.jar clojure.main file-name.clj
The above code should enable you to run your file-name.clj script which depends on clojure-contrib.
This line will run a clojure script "hello-world.clj". It first adds the clojure jar to the class path first and then will execute the file.
java -cp clojure.jar clojure.main hello-world.clj
for those used to text editor + lots of shell work
lein run isn't bad
and lein projects can help you organize deps and other proj-specific

Resources