I'm a beginning Java programmer and I had a project on my USB and I was trying to double click the source code just from the folder and not going into any software or IDEs.
However, it just opens the code in a Notepad and gives me an "Open with Visual Studio" option when I right click on the folder. There is no "Open with IntelliJ IDEA" option. Would be great if you guys could help me out.
I was also wondering how I could save projects in another folder or drive without having to go to the files program and copying and pasting into the drive I want it to be in.
Create a text file and add the following code in it:
#echo off
SET PhpStormPath=C:\Program Files\JetBrains\PhpStorm 2019.3.1\bin\phpstorm64.exe
echo Adding file entries
#reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm" /t REG_SZ /v "" /d "Open in PhpStorm" /f
#reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
#reg add "HKEY_CLASSES_ROOT\*\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
echo Adding within a folder entries
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm" /t REG_SZ /v "" /d "Open with PhpStorm" /f
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
#reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%V\"" /f
echo Adding folder entries
#reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm" /t REG_SZ /v "" /d "Open with PhpStorm" /f
#reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm" /t REG_EXPAND_SZ /v "Icon" /d "%PhpStormPath%,0" /f
#reg add "HKEY_CLASSES_ROOT\Directory\shell\PhpStorm\command" /t REG_SZ /v "" /d "%PhpStormPath% \"%%1\"" /f
pause
Rename the file with the extension to script.cmd or script.bat
Run this file as administrator.
However, it just opens the code on a notepad and gives me an open with visual studio option when I right click on the folder. There is no "open with Intellij idea" option
Sounds like you're on Windows and missed the option during Intellij installation to associate file types to the IDE.
In windows control center, there is file associations you can edit away from notepad or you can right click, go to properties, then change the "open with" options
Regarding opening whole folders, I don't typically go through right click menus, but if you want to edit code, you'd typically open the IDE anyway, so just open it, then open the folder as a project
For copying files, I don't quite understand the problem, but it's not going to be solved by Java or Intellij, and I don't know any easier way to copy files between directories or drives
When you 1st installed IntelliJ, you must have not checked the appropriate boxes to allow you to do those actions that you wanted. Installation Options when installing IntelliJ IDEA Community Edition
Under "Update context menu" you should check the box to Add "Open Folder as Project". This will allow you to choose your directory with all your Java files.
Under "Create Associations" you should check the box for .java. This will allow to double-click on your .java file to open IntelliJ.
Press W+R then type regedit and navigate to the displayed location. If those directories are not there then you can add them and add the value of the icon according to your software location.and then add these to command
Related
This syntax system("reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR /v Start /t REG_DWORD /d 4 /f");
i use in c++ but how to use disable usb in java i try but it gives a error on it that exception error.
I have a set of files, labeled file1.java, file2.java, ...
I want to pipe the output of the files to .txt files, such as output1.txt, output2.txt, etc. corresponding to each java file.
I know that I can do this by doing:
javac file1.java
java file1 > output1.txt
However, is there a way to do this of all files in a given directory? (instead of doing it manually)
This is a good for loop example:
Command line usage:
for /f %f in ('dir /b c:\') do echo %f
Batch file usage:
for /f %%f in ('dir /b c:\') do echo %%f
if the directory contains files with space in the names, you need to change the delimiter the for /f command is using. for example, you can use the pipe char.
for /f "delims=|" %%f in ('dir /b c:\') do echo %%f
If the directory name itself has a space in the name, you can use the usebackq option on the for:
for /f "usebackq delims=|" %%f in (`dir /b "c:\program files"`) do echo %%f
And if you need to use output redirection or command piping, use the escape char (^):
for /f "usebackq delims=|" %%f in (dir /b "c:\program files" ^|
findstr /i microsoft) do echo %%f
It shows both command line + batch for loop examples. Then you will have the filenames and can just run some commands on those filenames like javac and java.
Just try to break it down to small tasks:
Get list of files (all or just .class)
Loop through each file and call javac and java on them
Google is your best friend - search for "DOS batch" + what you need
Your job is much easier if you restructure your output file names a bit: file1.java --> file1_output.txt
From the command line:
for %F in (*.java) do #javac "%F" >"%~nF_output.txt"
If in a batch file:
#echo off
for %%F in (*.java) do javac "%%F" >"%%~nF_output.txt"
If you keep your original naming convention, then you must parse out the number form each file name. Very doable, but it doesn't seem worthwhile in your case.
My company's software utilizes Java Access bridge to function correctly.
We found that every time that Java updates itself, we have to once again re-install the Access Bridge components.
Is there a way to use an environment variable to point to either the Java Access Bridge or Java JRE to a folder that I can protect from getting updated?
When you update Java it installs it in a new folder and %JAVAHOME% changes.
JAVAHOME on my systems is set to C:\Program Files\Java\jdk1.7.0_13 and when I update that 13 is going to change to a 14.
Now the problem is that when you install Java Access Bridge files get copied into varies folders including %JAVAHOME%. So when you update Java the new Java home folder doesn't have the Java Access Bridge components.
There is really nothing you can do except reinstall Java Access Bridge.
See the installation doco at http://docs.oracle.com/javase/accessbridge/2.0.2/setup.htm#installing-jab-64-bit.
This is the batch file we went with:
#echo on
cd /d %~dp0
rem case sensitive jre - finds juice Java folder and puts to temp.txt into temp folder
:CHKFLEX
set temp1=%LOCALAPPDATA%\Juice\Flex
dir /AD /b %temp1% | find "jre" > %temp%\temp.txt
rem didnt find the jre folder in juice
if %errorlevel% NEQ 0 goto notfound
rem create environment variable to path found and written to temp.txt
for /f "delims=" %%x in (%temp%\temp.txt) do set temp2=%%x
rem path to juice subfolder created
set temp1
set temp2
set "_prog=%temp1%\%temp2%"
rem copy if files aren't there already
:x86
Set JAVAHOME32=%_prog%
#echo on
if exist "%JAVAHOME32%\bin\JavaAccessBridge-32.dll" goto theend
copy WindowsAccessBridge-32.dll %WINDIR%\SYSTEM32
copy JavaAccessBridge-32.dll %JAVAHOME32%\bin
copy JAWTAccessBridge-32.dll %JAVAHOME32%\bin
copy accessibility.properties %JAVAHOME32%\lib
copy access-bridge-32.jar %JAVAHOME32%\lib\ext
copy jaccess.jar %JAVAHOME32%\lib\ext
goto theend
rem Juice JRE folder not found
:notfound
echo "Alternate JRE folder not found..."
:theend
pause
Although we did have a more advanced batch file that can copy to both the Juice folder and to the Java folder by checking the registry for the java home path. Here is that one:
#echo on
cd /d %~dp0
:REGVAL
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion') DO set CurVer=%%B
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\% CurVer%" /v JavaHome') DO set JAVA_HOME=%%B
Set JAVA_HOME
:CHKFLEX
set temp1=%LOCALAPPDATA%\Juice\Flex
dir /AD /b %temp1% | find "JRE" > %temp%\temp.txt
if %errorlevel% NEQ 0 goto notfound
for /f "delims=" %%x in (%temp%\temp.txt) do set temp2=%%x
set temp1
set temp2
set "_prog=%temp1%\%temp2%"
pause
if not exist "%systemdrive%\Program Files (x86)" (
goto x86
) else (
goto x64
)
:x86
Set JAVAHOME32=%_prog%
#echo on
if exist "%JAVAHOME32%\bin\JavaAccessBridge-32.dll" goto x86_next
copy WindowsAccessBridge-32.dll %WINDIR%\SYSTEM32
copy JavaAccessBridge-32.dll %JAVAHOME32%\bin
copy JAWTAccessBridge-32.dll %JAVAHOME32%\bin
copy accessibility.properties %JAVAHOME32%\lib
copy access-bridge-32.jar %JAVAHOME32%\lib\ext
copy jaccess.jar %JAVAHOME32%\lib\ext
:x86_next
if exist "%JAVA_HOME%\bin\JavaAccessBridge-32.dll" goto theend
copy JavaAccessBridge-32.dll %JAVA_HOME%\bin
copy JAWTAccessBridge-32.dll %JAVA_HOME%\bin
copy accessibility.properties %JAVA_HOME%\lib
copy access-bridge-32.jar %JAVA_HOME%\lib\ext
copy jaccess.jar %JAVA_HOME%\lib\ext
goto theend
:x64
Set JAVAHOME32=%_prog%
Set JAVAHOME64=%_prog%
#echo on
if exist "%JAVAHOME64%\bin\JavaAccessBridge-64.dll" goto x64_next
copy WindowsAccessBridge-32.dll %WINDIR%\SYSWOW64
copy WindowsAccessBridge-64.dll %WINDIR%\SYSTEM32
copy JavaAccessBridge-64.dll %JAVAHOME64%\bin
copy JAWTAccessBridge-64.dll %JAVAHOME64%\bin
copy accessibility.properties %JAVAHOME32%\lib
copy access-bridge-64.jar %JAVAHOME64%\lib\ext
copy jaccess.jar %JAVAHOME64%\lib\ext
:x64_next
if exist "%JAVA_HOME%\bin\JavaAccessBridge-64.dll" goto theend
copy JavaAccessBridge-64.dll %JAVA_HOME%\bin
copy JAWTAccessBridge-64.dll %JAVA_HOME%\bin
copy accessibility.properties %JAVA_HOME%\lib
copy access-bridge-64.jar %JAVA_HOME%\lib\ext
copy jaccess.jar %JAVA_HOME%\lib\ext
goto theend
:notfound
echo "not found..."
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment" /v CurrentVersion') DO set CurVer=%%B
FOR /F "skip=2 tokens=2*" %%A IN ('REG QUERY "HKLM\Software\JavaSoft\Java Runtime Environment\%CurVer%" /v JavaHome') DO set JAVA_HOME=%%B
set CurVer
Set _prog=%JAVA_HOME%
set _prog
if not exist "%systemdrive%\Program Files (x86)" (
goto x86
) else (
goto x64
)
:theend
I have extracted an executable jar file containing xml,java class etc. Actually this executable jar file is a library with dependencies. i need to modify a single line of code in one of the class files in this library. I have successfully edited the class file, now i want to repack it to executable jar. how to do it.
Just zip the whole thing back, a jar is just a zip file.
Unzip the .jar
Modify the class
Rezip the whole structure into a .zip
Rename it to .jar
There you go.
You can automate it with the ant <jar> task for example.
As said by comments below you can use the jar tool that comes with the JDK installation.
jar -xvf your.jar to extract and jar -cvf your.jar inputfiles.
See the documentation.
What makes the JAR executable is that it contains in its structure a file located in META-INF/MANIFEST.MF that describe what is the entry point class, like:
Manifest-Version: 1.0
Main-Class: foo.bar.FooBar
using jar command you can do this
take a command prompt and got your root folder where all the classes. and use
following command
jar -cvf myjarname.jar *
* means all the files and folders in that location
Also, verify that you have the file association for executable jars. If you don't you can create this association with this batch file:
#ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: this script creates a file association for executable .jar files
ECHO Creating .jar file association...
ECHO JAVA_HOME is %JAVA_HOME%
IF NOT DEFINED JAVA_HOME GOTO :FAIL
REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKCR\jarfile\shell" /ve /f
REG ADD "HKCR\jarfile\shell\open" /ve /f
ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f
REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
ECHO Finished creating .jar file association for executable .jar files.
PAUSE
GOTO EOF
:FAIL
ECHO Script failed. JAVA_HOME not defined.
PAUSE
Alright i made a executable jar that holds a test game ran through a application. It runs fine for me but for my friend it does not. It says its unable to find the main class. So does he have to install java jdk or something? Is there a way around this?
Well, for one, he could be using the wrong command line arguments to the JVM to run the Java jar. Secondly, you could have not defined the main class correctly when you built the jar file (see: Unable to load main-class for jar file).
The way that you work around this? In the link I provided above, you'll see that there are a few command line parameters that can be supplied to the JVM that makes a big difference in how the JVM runs. Take those command line parameters and build a batch (or shell) file that end users can run to initialize the program correctly.
As your computer is setup differently, so may be the shell extension that handles files of type ".jar"
Try installing the newest version of java (JRE) on their machine (make sure it is of equal or higher version than the one your application was compiled against) and ensure that if you are using different architectures (x86 / x64) that you have the right versions of any libraries. I had this error only yesterday because I deployed a JDK 7u7 application to a machine with JRE 6u7.
Yes, there is a way around it. Run this script:
#ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
:: this .bat script creates a file association for executable .jar files
ECHO Creating .jar file association...
ECHO JAVA_HOME is %JAVA_HOME%
IF NOT DEFINED JAVA_HOME GOTO :FAIL
REG ADD "HKCR\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKCR\jarfile\shell" /ve /f
REG ADD "HKCR\jarfile\shell\open" /ve /f
ECHO REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
REG ADD "HKCR\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%**" /f
REG ADD "HKLM\jarfile" /ve /t REG_SZ /d "Executable Jar File" /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open" /ve /f
REG ADD "HKLM\SOFTWARE\Classes\jarfile\shell\open\command" /ve /t REG_SZ /d "\"%JAVA_HOME%\bin\javaw.exe\" -jar \"%%1\" %%*" /f
ECHO Finished creating .jar file association for executable .jar files.
PAUSE
GOTO EOF
:FAIL
ECHO Script failed. JAVA_HOME not defined.
PAUSE
install the new JRE .
while running the jar make sure you giv the class path in he command.
Eg. java -cp asd -jar file.jar