Groovy is not displaying output on command line - java

I unsuccessfully attempted to install Groovy 1.8.6 (zip distribution) on a Win XP (sp3) machine yesterday and today (the error messages stated it was unable to find the groovyStarter then I received a lengthy stack trace...). Needless to say, it was a frustrating experience. So, I decided to use the Windows installer for version 1.8.5. Groovysh functions as it should but if I write a small Groovy script and place it in a file:
println "Hello Groovy Programmer!"
...no output is displayed. Using groovy -e "println 'Hello!'" has the exact same behavior.
Any ideas of what might cause this?
Thanks.
~Caitlin

I'm not sure what you mean by "installing" the binary ZIP distribution. You don't really install anything in the usual sense of the term... you just unzip the ZIP file wherever you like. On my Windows XP laptop, I unzipped its contents into C:\groovy-1.8.6\.
I have heard some people complain of problems when they unzip into a path that contains spaces (such as C:\Documents and Settings\YourUsername\Desktop)... so perhaps that could be your issue, if you unzipped to your Desktop or something.
Just unzip the ZIP file somewhere, and add it's /bin directory to your PATH. On a Windows XP machine:
Right-click "My Computer"
Select "Properties"
Go to the "Advanced" tab
Click the "Environment Variables" button
Edit the PATH variable, and add C:\groovy-1.8.6\bin (or whatever)
The Groovy installation instructions also suggest that you add a GROOVY_HOME variable (pointing to C:\groovy-1.8.6), and a JAVA_HOME variable pointing to the root directory of your Java JDK (not the JRE located inside of the JDK). However, to be honest, I only remember to add these two environment variables half the time when putting Groovy on a a new machine, and it's never caused me problems.
With the ZIP file unzipped, and its /bin directory in your PATH, you just open a command-prompt and type:
groovy <script name>
... or, to run the GUI interface:
groovyConsole
If by chance you saw those "groovyStarter" errors because you tried to run startGroovy, then use one of the two commands above instead. The "startGroovy.bat" command is an internal script intended for indirect use through the other scripts under /bin. It will throw a java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter stacktrace if you call it directly... because it needs one of the other scripts to set some variable prior to calling it.
Good luck!

Related

Where should vecmath.jar go in MacOS(11.5.1) [duplicate]

This question already has answers here:
Import javax.vecmath
(6 answers)
Closed 1 year ago.
Preamble: So this all started with just trying to use javax.vecmath.Vector2d. I didn't have javax.vecmath so I spent a bit of time trying to get it, found that I needed to download Java3D.
After a long time of trying to download Java3D for Java (version 16.0.2), I eventually got it together with the vecmath.jar file landing in /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/lib/ext. This got rid of the error: package javax.vecmath does not exist error message.
Then, I got the message
<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; Use -classpath instead.
.Error: Could not create the Java Virtual Machine.
this also wasn't letting me use any java commands in shell.
A bit of research and I concluded the solution to be moving (via Finder select and drag) j3dutils.jar, vecmath.jar, and j3dcore.jar over to lib and just deleting the lib/ext directory. I have gotten rid of the <JAVA_HOME>/lib/ext exists problem but back to error: package javax.vecmath does not exist.
I don't even know what to do know. I just want to use javax.vecmath. Am I going about this the totally wrong way? How can I get this to work?
Okay, I figured it out.
How to use javax.vecmath in Mac OS(11.5.1) with Java(16.0.2)
I am giving a description that sort of includes why I do things, skip to the TLDR at the bottom if you just want an answer.
Step 1: Download the latest version of Java3D
This contains vecmath, along with j3dcore and j3dutils. It will download a .zip file. Unzip the file and it will expand into a new directory with another .zip file inside, j3d-jre.zip. Unzip j3d-jre.zip and it will expand into a directory lib. Inside lib will be a subdirectory, ext, with three .jar files inside: j3dcore.jar, j3dutils.jar, and vecmath.jar. You can put these literally anywhere, just make sure you keep track of their location (I put them in ~/Library/Java/Extensions, this location is on the hard drive and will need an admin password to do anything–use
sudo unzip /path/to/j3d-jre.zip
if you are doing things in shell). You CAN put the ext directory in JAVA_HOME/lib/ but after Java 6, this will cause a problem.
Step 2: Change CLASSPATH
Java has no idea how to find vecmath.jar so you have to specify it.
Option 1: Specify CLASSPATH with every shell command
The simplest version is using
javac -cp ".:/path/to/vecmath.jar:" MyMainProgram.java
to compile and
java -cp ".:/path/to/vecmath.jar:" MyMainProgram
to run the program (you can also replace -cp with -classpath and it will do the same thing)
This option won't ever destroy your CLASSPATH but you also have to include the -cp command every time you compile and run a program that imports javax.vecmath.
Option 2: Specify CLASSPATH with every new terminal window
A little more lasting than -cp, you can define CLASSPATH such that any changes will only take place in that terminal window. Use this form:
export CLASSPATH=".:/path/to/vecmath.jar:"
Now when you call
javac MyMainProgram.java
java MyMainProgram
Java will see that CLASSPATH is .:/path/to/vecmath.jar and everything will compile and run without adding the -cp command.
The main downside of this option is that if you update CLASSPATH again, you have to remember to add the previous CLASSPATH (which you can see at any time with echo $CLASSPATH)
Option 3: Permanently add CLASSPATH to terminal
Enter the following into terminal:
open ~/.bash_profile
this will open a window that may or may not have code in it. Regardless of any pre-existing code, scroll to the bottom and add
export CLASSPATH=".:/path/to/vecmath.jar:"
This option holds the CLASSPATH in all terminal windows forever or until you change it (using any method above).
TLDR
Download Java3D for macOS
Unzip java3d-1_5_1-macosx.zip and open the directory it creates
Unzip j3d-jre.zip and open the new directory /lib/ and the subdirectory /lib/ext/
Move vecmath.jar, j3dcore.jar, and j3dmath.jar to ~/Library/Java/Extensions (this requires an admin password) or any other location
Run the following line in terminal:
open ~/.bash_profile
Go to the bottom and add the following:
export CLASSPATH="/path/to/vecmath.jar:$CLASSPATH"
import javax.vecmath.* to any .java program you want
The jar file can go where you want, moving it to your project's lib folder is good. The real issue is you need your classpath to point to it.
Here is a full explanation.
If you are running from the command line you don't need to set the classpath variable, you can provide it in the java command. It would be something like this:
java -cp lib/vecmath.jar Example
This assumes that the program you are working on has been compiled into a class file named Example.class. If you main method is in a package you will need to fully qualify the classname so it might look like:
java -cp lib/vecmath.jar com.demo.Example
You can list multiple jar files on the classpath, separated by a colon (:).
You can also ask for help in the command line by invoking:
java -h

JAR File is not Executing

I am Cleaning and Building a project, which is creating its .jar file in its "dist" folder. However the issue is that, I'm not able to run it. I double click on it and nothing happens.
I have set up "bin" folder of JDK in "Path" option in environment variables.
Is there is anything that I am missing? I am new to all this and help is really appreciated.
Suggested
Learn how to make executable file yourself , rather than depending on auto generated jar file
Here is a tutorial.
In case of default jar file ,
most likely you have to execute
java -jar MY_AWESOME_JAR_FILE_NAME.jar
There are 3 common reasons for this:
On windows, and using sysin/sysout
Windows, because apparently microsoft is not capable of fixing ancient silliness, forces upon apps that they either have a terminal in which case an ugly black box always pops up, or they don't, and can't later make one. That means that on windows only, there are 2 java executables: java.exe and javaw.exe, with as only difference that javaw doesn't get a box. But, it doesn't get a box - sysin and sysout do pretty much completely nothing.
By default, double clicking a jar starts it with javaw, which means if your app's only interaction is reading from System.in and writing to System.out or System.err, you won't see anything.
There is no fix to this, other than to make a GUI app, or make a batch file (a windows only concept) that explicitly runs java.exe.
This doesn't apply to linux or macs.
jar file broken
A runnable jar file is one that has three properties:
There is a class inside the jar that has a public static void main(String[] args) method inside.
That class is named (fully qualified) in the manifest of the jar, under key Main-Class
Any deps needed are either baked into the jar, or in another jar, and those other jars are named, space-separated and relative to the dir that the jar you're double clicking lives in, in the manifest, under key Class-Path. Note that the global environment variable CLASSPATH does nothing when double clicking jars.
You can check all this; jars are just zip files. Also, the jar tool in your JDK can unpack them, and the manifest is just a file named META-INF/MANIFEST.MF inside. You can open it up, have a look if it's properly configured.
java install broken
Check any random runnable jar first. Maybe you installed a headless java. Note that these days (since JDK9 and up), an 'end user' wouldn't even install a java and the notion of double clicking a jar to run it is basically obsolete. To make 'desktop' java applications, you'd ship an entire JRE (treeshaken if you want) and you're responsible for an installer. There are some limited tools in the JDK (since 9) that help you out (such as jlink).
Use the CLI to see whether your Java is set up properly, the jar is corrupted, or the jar is incompatible with installed Java version.
Ensure the jar file is properly associated with Java binary. The instruction can be found here
Just edit manifest file adding main method in there. If you have any additional reference libraries simply put them into class path there.
Manifest specificatin is located here:
https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

JAR executable doesn't start if it's in Programs directory

I'm into a very strange issue that's making me crazy .-.
I'm working on a relatively big Java project on Windows, using NetBeans and IzPack to prepare the graphical installation package.
Everything is ok, the compiled installer seems to work and my program is copied in 'C:\Programs\MyProject' folder.
But... when I double click on the myproject.jar in that folder it doesn't start at all. I obviously tried to open a prompt and type 'java -jar myproject.jar' but nothing, not even a line of error code.
The curious facts are two:
if I open it using the prompt with administration rights it works
in the same folder there is another jar, 'uninstaller.jar' created by izpack, and it works with double click.
I double checked my JVM installation, the PATH/JAVA_HOME/... values, and Properties->Security tab of my JAR but the permissions to execute/read/write for every kind of user are ok, and also are equal to the uninstaller.
So what's the problem? Thanks
This is almost certainly caused by Windows UAC on Vista and Windows 7.
Your program is probably trying to write to data files in the same directory as it is installed.
On Windows, well behaved programs write to the users or all users app data directory.
The location of that directory varies depending on the version of Windows.
You can use the system property "user.home" to find a safe place to store data.
You can also get a list of environment variables for shared and per user program data folders from here.

Starting with Java

So I am trying to start with Java (as in, trying to get the dang thing to accept code). I download all the needed things (the SDK) from Java and such, but when it gets to the point where I have to do "javac" in Command Prompt to compile the notepad file, I just get the message saying that there is no command called "javac".
Anybody wanna share some insight?
To set the environment variable PATH: http://www.java.com/en/download/help/path.xml.
Also I recommend using an IDE such as netbeans or eclipse. They make it much easier when starting off in java, plus when getting into advanced projects with many classes, they help greatly.
You need to set the path to your java compiler for it to be found when you use the command prompt. This page explains how.
I would suggest setting the following environment variable:,
JAVA_HOME to point to the root of your java installation e.g. C:\Program Files\Java
than append the following to your PATH environment variable:
;%JAVA_HOME%\bin
than you will be able to use java and javac from the command line.
Also see this article from Microsoft on setting environment variables if your not familiar with it.
You need to add the Java bin directory (where javac.exe is located, assuming you're on Windows), to your system PATH.
Right click on "My Computer", go to Environment Variables, and add the bin directory where Java is installed to your PATH variable.
You will need to have the java bin directory on your path. So, on windows, if installed at c:\java, and bin is c:\java\bin (normally you have version number, jre vs sdk, etc), you will need to add that to your PATH environment variable. set PATH=c:\java\bin;%PATH% -- you could do this in a setlocal/endlocal block or set it permanatly for your machine.
Also, the JRE may not have javac -- you may need to dowload the SDK.
Starting with java by typing 'javac' at the command line satisfy my mother's definition of the phrase 'starting with' ... as in,
"Don't start with me, buddy."
You are likely to end up with a punch in the nose.
For your own sanity, pick one of Eclipse, or NetBeans, or IntelliJ, or the other popular IDEs, and start from there.

no output when .jar is executed

I built an application in Netbeans 6.8 and made project.jar file. When I run it, it works only on my computer, but not on any other computer. However, when I made any simple application, that doesnt use any libraries, it works fine on any computer.
Is there any way, how to invoke some error message, where is the problem?
My project use R 2.9.2, so I install this version on other computer and set the System Path variable exactly same. Other libraries listed in lib directory are: AbsoluteLayout.jar,DatePicker-V0.99-2006.09.01.jar,jcommon-1.0.16.jar,jfreechart-1.0.13.jar,jmathplot.jar,JRI.jar,pdf-renderer-1.0.5.jar
Thank you
You don't get any message at all? What do "works" and "not works" look like?
You sound like another person who hasn't taken the time to learn how to do things by hand on the command line without an IDE. I'd recommend doing that. Open a command shell and type in the java -jar -cp ... foo.jar command to run your stuff. The messages you get back will be educational.
Note the -cp command line argument. That's how you add your JARs to the CLASSPATH properly.
I solved this problem as follows, maybe it will help someone.I add 2 paths in PATH system variable:
Start -> Control Panel -> System -> Advanced
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH.
you must add both paths, to jri.dll and r.dll, in my case it were these:
C:/Program Files/R/R-2.9.2/bin/;C:/Program Files/R/R-2.9.2/library/rJava/jri/;
I have added these lines already, but with different different slash. So be careful, you must use it / not \ to define path!!!

Categories