Folder permission issue with jarsigner - java

This is definitely a very beginner question that might not have to do anything with programming. After few days, I have finally identified the problem as for why I couldn't sign jar using jarsigner. I kept getting this error that says "jarsigner: unable to create hello.jar.sig".
Basically, what I did was to put a jar in Java jdk's bin folder and then I shift-left click there in the folder to click on "Open the command window here". I generated the key from keytool and also used selfcert. Then when I did the jarsigner for a jar already put in the bin folder, I got the error. I eventually figured out the reason. I couldn't create the jar.sig in the bin folder since I don't have sort of permission. The question is, how do I set the destination to some folder that is modifiable?
I have no idea how to set the path to java directory and calling jarsigner from desktop or elsewhere, so I had to learn to write command prompt right inside the java bin folder.

Move your JAR file to a directory you can read/write.
Run the original command:
"C:\Path\To\JDK\bin\jarsigner" [options] jar-file
By default the output will be written to the directory you ran the command from.
In the long term, you can add the JDK bin directory to your Windows path.

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

I could not understand why "javac: file not found: HelloWorld.java"

javac HelloWorld.java
Following error message keeps coming out every time when I run in cmd
javac: file not found: HelloWorld.java
However, when I added my file location
javac D:\User\Documents\Project\HelloWorld.java
It runs successfully.
Why?
I have tried to edit variable value of PATH to D:\User\Documents\Project
But it did not work.
You seem to have never used the command prompt before. The command prompt has a "current directory", just like in a file explorer window, there is a "current directory", the directory that you are viewing right now.
The current directory is usually shown just to the left of the caret.
The current directory on the above photo is C:\Users\Mrhope.
Type dir to see all the files and directories of the current directory. You can then use cd to navigate to a subdirectory. Say you are in Documents now, and you can do this
cd Project
to go to the Project folder. By the way ../ means the parent directory
The HelloWorld.java in javac HelloWorld.java is a path relative to the current directory, so this will only work if HelloWorld.java is in the current directory. You should try to use cd to navigate to the correct directory then use that command.
Setting the PATH environmental variable is quite irrelevant here because that is setting the path of the JRE. Please set it back.
I suggest you learn the basics of cmd first. Many tutorials are available online.
You have to enter the directory of where your Java file is.
Fastest way is to open the folder where your Jar file is then hold the shift key on your PC and right click on an empty space in the folder (while still holding the shift key). When the context menu comes up look for the open command window here option (for newer Windows 10 versions it's power shell window), select the appropriate option. When it opens run your command

Making a Java application for Mac users

I succesfully generated a dmg file thanks to this question. My issue now is that when I open the .app file, the program starts and immediately stops.
1) On Mac, how can I get the java error if any?
2) I think that the error occurs because the .app cannot access the files that are within the dmg. The same answer indicates that I could add my files to the .app file. I can do that, but then, how am I supposed to access these files from my application? What would be the path I should use?
3) For GNU/Linux and Windows users, I currently have a .jar file that updates my application by updating the myapp.jar file and some other files. If everything is packaged into the myapp.jar file, how am I supposed to do that?
Thanks for you help!
Have not tested the following but based on what’s described at Bundle Java program for Mac users with maven from GNU/Linux, the following are the steps I would try.
Open Terminal and cd to whatever directory .app is in.
Run find . -name java.
That will return something like foo/bar/jre1.8.0_112.jre/bin/java I guess.
Run find . -name myapp.jar where myapp.jar is the name of the jar you made.
That will return something like foo/bar/myapp.jar.
Run foo/bar/jre1.8.0_112.jre/bin/java foo/bar/myapp.jar.
If that runs, some error message will get emitted that should explain what else is not working.
Note that you can change files inside that .app directory; specifically, you can replace the jar file within the directory.

How do I install and set up Java speech (jsapi) for my iMac running the latest OS Sierra?

I am relatively new to Apple OS and thus am not able to figure out as to how do I download, install then set up Java speech jar files and set up the classpath.
I tried everything possible from
Downloading FreeTTS,jsapi and trying to add the jsapi.jar to /library/extensions folder
Trying to use chmod command
Trying to open the jar file (which returned an error and asked me to check console)
Tutorials asking me to drop jar into the "lib" folder (I can't really figure out what and where is the "lib" folder in mac)
Basically I want to use all the capabilities of javax.speech in my Java programs.
JSAPI is pretty much abandoned, you won't be able to get lot from it. If you want text-to-speech use OpenMary directly without JSAPI, it provides a good selection of modern voices.
Download FreeTTS. Extract. Open the extracted /lib folder. chmod +x ./jsapi.sh and afterwards sh ./jsapi. Read the BCEL and accept.
Accept (y/n)?:
y
sed: --print-text-domain-dir: No such file or directory
x - creating lock directory
x - extracting jsapi.jar (binary)
As you can see there is the jsapi.jarbeing extracted into the lib folder (which was not there before). Now you can add the lib folder (it says it will be enough to point to the lib/freetts.jar) to your class path of any application that is using FreeTTS.
You could add it into some directory in your userspace folder and add to your ~/.bash_profile the line export JS_API_HOME=~/the/path/lib where ~/the/path would be where you stored the extracted archive. Then, you have to add the environment variable $JS_API_HOME to every build/classpath where you want to use the library.
For example, java -cp $JS_API_HOME -jar moep.jar

jar not reading input file directory recursively

I'm having trouble running the jar command in cygwin. The input-files parameter isn't treating the directory I'm passing it recursively when I'm referencing it with ".."s in my path.
For example, I'm running this in the same directory as the "src" directory. src/ contains my package structure of class and java files. This runs properly and creates a jar containing my source and class files.
jar cf jarname.jar src
However when I run this next command, I get an empty jar except for a manifest file.
jar cf jarname.jar localdir/../src
I need to run this from a script that needs to find this directory with a ".." directory so I need the 2nd command to work.
Anybody know why this isn't working or have a workaround? I tried using realpath but it complains that it can't find that path at all. I may be using it wrong though.
The Directory path in cygwin is different . To navigate to any drive for example to C drive we need to type in:
/cygdrive/c
A very easy work around i found useful is just to type cmd in the terminal . This allows you to use the actual path than the cygwin specific path .
try typing cmd and then running the command , it worked for me

Categories