Before everybody tells me this is a duplicate, please hear me out...
When you need the absolute executable path from inside a running jar (= path to self) regardless of the current working directory, in the old days (Java 6 JRE 1.6) this used to work like a charm:
getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
Nowadays in Java 7 (JRE 1.7) this just returns "./". If you want to test this, you'll need to create a runnable jar because when compiling from the source, you will get the path as expected.
This is driving me mad as I have been searching for a solution for what seems like an eternity. I resorted to hardcoding the absolute path, but obviously that means the jar is not portable.
Does anyone know what to do?
Thanks!!!
Just stumbled across the same problem after exporting one of my older Java 6 projects which also used the same method to get the execution path.
Here's a quick workaround (replace 'Start.class' with your class name or use 'getClass()'):
String path = Start.class.getProtectionDomain().getCodeSource().getLocation().getPath();
path = new File(rootFolder).getAbsolutePath();
Most likely you will end up with a path still ending with a period. So you might want to fix that using:
if (path.endsWith(".")) path = path.substring(0, path.length() - 1);
Tested using Oracle JRE 7 on Windows 7 64bit and Xubuntu 14.04
Related
I downloaded Gurobi and verified that my license is working.
I'm trying to add the Gurobi package to Julia, but it seems that the dll file can't be found, even though my GUROBI_HOME variable is okay.
Here is the output of Pkg.build("Gurobi") :
Found GUROBI_HOME = C:\gurobi902\win64
Does this point to the correct install location?
on Windows, this might be C:\Program Files\gurobi810\win64\
alternatively, on Windows, this might be C:/Program Files/gurobi810/win64/
on OSX, this might be /Library/gurobi810/mac64/
on Unix, this might be /home/my_user/gurobi810/linux64/
Note: this has to be a full path, not a path relative to your current
directory or your home directory.
We're going to look for the Gurobi library in this directory:
C:\gurobi902\win64\bin
That directory has the following files:
C:\gurobi902\win64\bin\grbcluster.exe
C:\gurobi902\win64\bin\grbgetkey.exe
C:\gurobi902\win64\bin\grbprobe.exe
C:\gurobi902\win64\bin\grbtune.exe
C:\gurobi902\win64\bin\grb_ts.exe
C:\gurobi902\win64\bin\gurobi.bat
C:\gurobi902\win64\bin\gurobi.env
C:\gurobi902\win64\bin\gurobi90.dll
C:\gurobi902\win64\bin\Gurobi90.NET.dll
C:\gurobi902\win64\bin\Gurobi90.NET.XML
C:\gurobi902\win64\bin\gurobi90_light.dll
C:\gurobi902\win64\bin\GurobiJni90.dll
C:\gurobi902\win64\bin\gurobi_cl.exe
C:\gurobi902\win64\bin\pysetup.bat
C:\gurobi902\win64\bin\vslauncher.exe
C:\gurobi902\win64\bin\vswhere.exe
We were looking for (but could not find) a file named like
libgurobiXXX.so, libgurobiXXX.dylib, or gurobiXXX.dll. You
should update your GUROBI_HOME environment variable to point to the
correct location.
Have you tried to look for the specific dll in your hard disk and update the GARUBI_HOME accordingly, as per error message? Did you double-check that this specific dll exists on that folder?
I'm looking to reach this folder, with a relative path:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks
With something like this:
$(EXAMPLE)
or this:
$(EXAMPLE)/Frameworks
or this:
$(EXAMPLE)/Library/Frameworks
Is there such variable available? The Build Settings Reference doesn't seem to have one. But I find it odd that it doesn't.
Thank you!
You want: ${DEVELOPER_FRAMEWORKS_DIR}
Here's an example from a compilation run I did a while back (and documented to track such variables):
setenv DEVELOPER_FRAMEWORKS_DIR /Users/andy/Applications/Xcode46-DP4.app/Contents/Developer/Library/Frameworks
(as you can see, this is from Xcode 4.6 DP4, installed in my user Application folder).
I was looking for cross compiler which is compiling for MIPS-I version 1 target and I found this:
ftp://ftp.dd-wrt.com/others/sourcecode/toolchains/current-toolchains.tar.bz2
After archive extraction I copied "toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1" folder to /opt/ and added PATH to /root/.profile file like here:
PATH="/opt/toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1/usr/bin:${PATH}"
export PATH
then I'd log out and log in and thought that everything is all right, but it is not.
I can't even compile simple app. Here is the example output produced by dhcp-3.x compilation attempt:
http://pastebin.com/MPMwirhg
What's wrong ?
Do I still have to set up something ?
How to correct the problem ?
There are hardcoded paths in libraries, so that's why it didn't work. Placing "toolchain-mips_gcc-4.3.3+cs_uClibc-0.9.30.1" folder in /home/xfs/openwrt/trunk2/trunk/staging_dir/ makes it working ok
A while ago when I started with Cake, I managed to get the console running in my Windows environment, and I have no idea how. I'm now having problems to make it work again in another computer.
This is what I've done in the new machine:
Downloaded my Cake code from source control (so all the files are exactly the same as the computer where it worked, including the configuration files)
Added PHP and "c:\my_cake_path\cake\console" to the path
If I run "cake OneOfMyShells", either standing on the /app, or in /cake/console directories, I get the following error:
Warning: get_object_vars() expects parameter 1 to be object, null given in C:\my_cake_path\cake\libs\model\connection_manager.php on line 199
Error: Missing Database Connection. Try 'cake bake'
"cake Bake", if run normally, when I try to get it to do the DB config ends up throwing another error (which is not that relevant to this)
However, if I run: cake bake -app "c:\my_cake_path\app"
Then bake works, I can do the database config, and it writes the DB config file (which is useless at this point, since I already had one)
Then, of course: cake OneOfMyShells -app "c:\my_cake_path\app"
does work perfectly well.
So, everything's working fine, I just need to manually specify the path to "app" every single time, which is very annoying.
How can I get around this? Where is Cake looking for to find the path to app?
Thanks!
Daniel
Not much of a difference in the sense you still need to type but you can run cake from the app dir like this: C:\XXX\project\app> ..\cake\console\cake.bat
To make it smaller you can put that line on a .bat or just add the \cake\console dir the windows path
In a .LST file for my VB6 installer there are two lines as follow:
File1=#VB6STKIT.DLL,$(WinSysPathSysFile),......
File2=#wshom.ocx,$(WinSysPath),.....
After installing my application, I found out that both go to the same \Windows\System32 folder. Do you know what is the difference between both paths?
Thanks
This dates back from VB4, I think, a version that could still generate 16-bit executables. Where the system directory was c:\windows\system, the synonym of $(WinSysPath). $(WinSysPathSysFile) is c:\windows\system32. There should be no difference on a 32-bit operating system, but worth a check. wshom.ocx really does belong in system32. It is already there on any recent operating system.
They both go to the same system folder (The windows folder if it's not writable). The latter just marks it as a system file so it's not uninstalled.
Snippets from Setup1.bas in the PDW:
fSystem As Boolean 'whether the file is a system file (i.e. should be installed but never removed)
If InStr(strInitialDestDir, gstrWINSYSDESTSYSFILE) Then
sFile.fSystem = True
End If
Case gstrWINSYSDEST, gstrWINSYSDESTSYSFILE
strResolved = gstrWinSysDir