For the purposes of CI, I need to be able to generate an XCARCHIVE and an IPA file in our nightly build. The IPA is for our testers, to be signed with our ad-hoc keys, and the XCARCHIVE is to send to the client so that they can import it into Xcode and submit it to the app store when they're happy with it.
Generating the IPA is simple enough with a bit of googling, however how to generate the .XCARCHIVE file is what eludes me. The closest I've found is:
xcodebuild -scheme myscheme archive
However, this stores the .xcarchive in some hard-to-find folder, eg:
/Users/me/Library/Developer/Xcode/Archives/2011-12-14/MyApp 14-12-11 11.42 AM.xcarchive
Is there some way to control where the archive is put, what its name is, and how to avoid having to re-compile it? I guess the best possible outcome would be to generate the xcarchive from the DSYM and APP that are generated when you do an 'xcodebuild build' - is this possible?
Xcode 5 now supports an -archivePath option:
xcodebuild -scheme myscheme archive -archivePath /path/to/AppName.xcarchive
You can also now export a signed IPA from the archive you just built:
xcodebuild -exportArchive -exportFormat IPA -exportProvisioningProfile my_profile_name -archivePath /path/to/AppName.xcarchive -exportPath /path/to/AppName.ipa
Starting with Xcode 4 Preview 5 there are three environment variables that are accessible in the scheme archive's post-actions.
ARCHIVE_PATH: The path to the archive.
ARCHIVE_PRODUCTS_PATH: The installation location for the archived product.
ARCHIVE_DSYMS_PATH: The path to the product’s dSYM files.
You could move/copy the archive in here. I wanted to have a little more control over the process in a CI script, so I saved a temporary file that could easily be sourced in my CI script that contained these values.
BUILD_DIR=$PROJECT_DIR/build
echo "ARCHIVE_PATH=\"$ARCHIVE_PATH\"" > $BUILD_DIR/archive_paths.sh
echo "ARCHIVE_PRODUCTS_PATH=\"$ARCHIVE_PRODUCTS_PATH\"" >> $BUILD_DIR/archive_paths.sh
echo "ARCHIVE_DSYMS_PATH=\"$ARCHIVE_DSYMS_PATH\"" >> $BUILD_DIR/archive_paths.sh
echo "INFOPLIST_PATH=\"$INFOPLIST_PATH\"" >> $BUILD_DIR/archive_paths.sh
Then in my CI script I can run the following:
xcodebuild -alltargets -scheme [Scheme Name] -configuration [Config Name] clean archive
source build/archive_paths.sh
ARCHIVE_NAME=AppName-$APP_VERSION-$APP_BUILD.xcarchive
cp -r "$ARCHIVE_PATH" "$BUILD_DIR/$ARCHIVE_NAME"
I have just solved this one - just add the argument -archivePath to your xcode build command line, given the initial question that would mean:
xcodebuild -scheme myscheme archive
becomes ...
xcodebuild -scheme myscheme archive -archivePath Build/Archive
(Note: paths are relative, I output my build to $PWD/Build)
This will then place your .app folder in:
Build/Archive.xarchive/Products/Application
If your build target already has your signing certificate and provisioning profile in it you can then create your IPA file without re-signing using the following command:
xcrun -v -sdk iphoneos PackageApplication -v `pwd`'/Build/Archive.xarchive/Products/Application/my.app' -o `pwd`'/myapp.ipa'
(Note: xcrun doesn't like relative paths hence the pwd)
The -v args dump lots of useful information - this command can fail to sign properly and still exit with code 0, sigh!
If you are finding that you can't run the built .ipa it's probably a signing issue that you can do a double check on using:
codesign --verify -vvvv myapp.app
If it's signed correctly and un-tampered with the output will have this in:
myapp.app: valid on disk
myapp.app: satisfies its Designated Requirement
If not you will see something similar to this:
Codesign check fails : /blahpath/myapp.app: a sealed resource is missing or invalid
file modified: /blahpath/ls-ios-develop.app/Assets.car
... which generally means you are trying to use an intermediate output directory rather than the proper archive.
My current solution is to rename the user's existing archives folder, run the build, and do a 'find' to copy the archives where i want, then delete the archives folder and rename the old folder back as it was, with code like this in my ruby build script:
# Move the existing archives out of the way
system('mv ~/Library/Developer/Xcode/Archives ~/Library/Developer/Xcode/OldArchivesTemp')
# Build the .app, the .DSYM, and the .xcarchive
system("xcodebuild -scheme \"#{scheme}\" clean build archive CONFIGURATION_BUILD_DIR=\"#{build_destination_folder}\"")
# Find the xcarchive wherever it was placed and copy it where i want it
system("find ~/Library/Developer/Xcode/Archives -name *.xcarchive -exec cp -r {} \"#{build_destination_folder}\" \";\"")
# Delete the new archives folder with this new xcarchive
system('rm -rf ~/Library/Developer/Xcode/Archives')
# Put the old archives back
system('mv ~/Library/Developer/Xcode/OldArchivesTemp ~/Library/Developer/Xcode/Archives')
Its a bit hacky but i don't see a better solution currently. At least it preserves the user's 'archives' folder and all their pre-existing archives.
--Important note!--
I since found out that the line of code where i find the archive and cp it to the folder i want doesn't copy the symlinks inside the archive correctly, thus breaking the code signing in the app. You'll want to replace that with a 'mv' or something that maintains symlinks. Cheers!
Here's a bit of bash that I've come up with for our Jenkins CI system. These commands should be run in a script immediately after the xcodebuild archive command finishes.
BUILD_DIR="${WORKSPACE}/build"
XCODE_SCHEME="myscheme"
# Common path and partial filename
ARCHIVE_BASEPATH="${HOME}/Library/Developer/Xcode/Archives/$(date +%Y-%m-%d)/${XCODE_SCHEME}"
# Find the latest .xcarchive for the given scheme
NEW_ARCHIVE=$(ls -td "${ARCHIVE_BASEPATH}"* | head -n 1)
# Zip it up so non-Apple systems won't treat it as a dir
pushd "${NEW_ARCHIVE%/*}"
zip -r "${BUILD_DIR}/${NEW_ARCHIVE##*/}.zip" "${NEW_ARCHIVE##*/}"
popd
# Optional, disk cleanup
rm -rf "${NEW_ARCHIVE}"
The BUILD_DIR is used to collect artifacts so that it's easy to archive them from Jenkins with a glob such as build/*.ipa,build/*.zip
Similar to the others, but perhaps a little simpler since I try to record the .xcarchive file's location. (I also don't move the archives folder, so this will work better if you're doing multiple builds at the same time.)
My caller build script generates a new tempfile and sets its path to an environment variable named XCARCHIVE_PATH_TMPFILE. This environment variable is available in my scheme's Archive post-action shell script, which then that writes the .xcarchive's path to that file. The build script that can then read that file after it calls xcodebuild archive.
post-action shell script
echo $ARCHIVE_PATH > "$XCARCHIVE_PATH_TMPFILE"
On Xcode 4.6 it is possible to specify a post-build action for the scheme to be compiled into an xcarchive:
echo "ARCHIVE_PATH=\"$ARCHIVE_PATH\"" > $PROJECT_DIR/archive_paths.sh
A build script can be used to check if $ARCHIVE_PATH is defined after running xcodebuild and if this is the case, the output xcarchive can be moved into a designated folder.
This method is not very maintainable if the targets in the project are a large number, as for each one it is necessary to tag the corresponding scheme as 'shared' and add the post-build action.
To address this problem, I have created a build script that generates the archive path programmatically by extracting the last build that matches the target name on the current day. This method works reliably as long as there aren't multiple builds with the same target name running on the machine (this may be a problem in production environments where multiple concurrent builds are run).
#!/bin/bash
#
# Script to archive an existing xcode project to a target location.
# The script checks for a post-build action that defines the $ARCHIVE_PATH as follows:
# echo "ARCHIVE_PATH=\"$ARCHIVE_PATH\"" > $PROJECT_DIR/archive_paths.sh
# If such post-build action does not exist or sourcing it doesn't define the $ARCHIVE_PATH
# variable, the script tries to generate it programmatically by finding the latest build
# in the expected archiving folder
#
post_build_script=archive_paths.sh
build_errors_file=build_errors.log
OUTPUT=output/
XCODEBUILD_CMD='/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild'
TARGET_SDK=iphoneos
function archive()
{
echo "Archiving target '$1'"
# Delete $post_build_script if it already exists as it should be generated by a
# post-build action
rm -f $post_build_script
# Use custom provisioning profile and code sign identity if specified, otherwise
# default to project settings
# Note: xcodebuild always returns 0 even if the build failed. We look for failure in
# the stderr output instead
if [[ ! -z "$2" ]] && [[ ! -z "$3" ]]; then
${XCODEBUILD_CMD} clean archive -scheme $1 -sdk "${TARGET_SDK}" \
"CODE_SIGN_IDENTITY=$3" "PROVISIONING_PROFILE=$2" 2>$build_errors_file
else
${XCODEBUILD_CMD} clean archive -scheme $1 -sdk "${TARGET_SDK}"
2>$build_errors_file
fi
errors=`grep -wc "The following build commands failed" $build_errors_file`
if [ "$errors" != "0" ]
then
echo "BUILD FAILED. Error Log:"
cat $build_errors_file
rm $build_errors_file
exit 1
fi
rm $build_errors_file
# Check if archive_paths.sh exists
if [ -f "$post_build_script" ]; then
source "$post_build_script"
if [ -z "$ARCHIVE_PATH" ]; then
echo "'$post_build_script' exists but ARCHIVE_PATH was not set.
Enabling auto-detection"
fi
fi
if [ -z "$ARCHIVE_PATH" ]; then
# This is the format of the xcarchive path:
# /Users/$USER/Library/Developer/Xcode/Archives/`date +%Y-%m-%d`/$1\
# `date +%d-%m-%Y\ %H.%M`.xcarchive
# In order to avoid mismatches with the hour/minute of creation of the archive and
# the current time, we list all archives with the correct target that have been
# built in the current day (this may fail if the build wraps around midnight) and
# fetch the correct file with a combination of ls and grep.
# This script can break only if there are multiple targets with exactly the same
# name running at the same time.
EXTRACTED_LINE=$(ls -lrt /Users/$USER/Library/Developer/Xcode/Archives/`date
+%Y-%m-%d`/ | grep $1\ `date +%d-%m-%Y` | tail -n 1)
if [ "$EXTRACTED_LINE" == "" ]; then
echo "Error: couldn't fetch archive path"
exit 1
fi
# ls -lrt prints lines with the following format
# drwxr-xr-x 5 mario 1306712193 170 25 Jul 17:17 ArchiveTest 25-07-2013
# 17.17.xcarchive
# We can split this line with the " " separator and take the latest bit:
# 17.17.xcarchive
FILE_NAME_SUFFIX=$(echo $EXTRACTED_LINE | awk '{split($0,a," "); print a[11]}')
if [ "$FILE_NAME_SUFFIX" == "" ]; then
echo "Error: couldn't fetch archive path"
exit 1
fi
# Finally, we can put everything together to generate the path to the xcarchive
ARCHIVE_PATH="/Users/$USER/Library/Developer/Xcode/Archives/`date
+%Y-%m-%d`/$1 `date +%d-%m-%Y` $FILE_NAME_SUFFIX/"
fi
# Create output folder if it doesn't already exist
mkdir -p "$OUTPUT"
# Move archived xcarchive build to designated output folder
mv -v "$ARCHIVE_PATH" "$OUTPUT"
}
# Check number of command line args
if [ $# -lt 1 ]; then
echo "Syntax: `basename $0` <target name> [/path/to/provisioning-profile]
[<code sign identity]"
exit 1
fi
if [ ! -z "$2" ]; then
PROVISIONING_PROFILE="$2"
fi
if [ ! -z "$3" ]; then
SIGN_PROVISIONING_PROFILE="$3"
else
if [ ! -z "$PROVISIONING_PROFILE" ]; then
SIGN_PROVISIONING_PROFILE=$(cat "$PROVISIONING_PROFILE" | egrep -a -o
'[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}')
fi
fi
archive "$1" "$PROVISIONING_PROFILE" "$SIGN_PROVISIONING_PROFILE"
Full source code with an example Xcode project can be found here:
https://github.com/bizz84/Xcode-xcarchive-command
Related
Whenever I open a script (Python or R), I want Sublime automatically changes the current working directory to the path of that file. Is it possible?
I added the setting "working_dir": "$file_path", to Sublime preferences but it doesn't help.
Ok, I solved the problem. Here is what I did:
Install Sublime Text 3 package PackageResourceViewer
Open Command Palette, search for PackageResourceViewer: Open Resource
Browse to Python resource then open Python.sublime-build
Remove the default line "shell_cmd": "python -u \"$file\"",
Add the following 2 lines:
"cmd": ["python", "-u", "$file"],
"working_dir": "$file_path",
Alternately, you can replace the above 2 lines by:
"shell_cmd": "cd $file_path; python -u \"$file\""
Do the same thing for R or other build resources if you want Sublime Text 3 automatically change the current working directory in accordance with the active scripts' path.
You can open the python console using the Show Console command in View menu, and then type
import os
os.chdir('/my/directory')
It changes the working directory for the Sublime Text process and whatever process it spawns.
Another solution: You know the console opens with Alt+". When I use the combination Alt+1 it's directly chosing the current file path. And this way is something you have to do every single time you open sublime text.
I was having the same issue, plus if i wanted to import a module, it would always return module not found.
To fix this: I change the first line of my python.sublime-build file to what i have below
{
"shell_cmd": "cd $file_path; python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
{
"env": "PYTHONIOENCODING": "utf-8",
],
"variants":
}
{
"name": "Syntax Check",
"shell_cmd": "python -m py_compile \"${file}\"",
}
]
}
Being cuper curious, i wanted to know why this was happening, so after doing more investigations about my os, ran:
import os
for k, v in os.environ.items():
print(k, v)
print(os.getcwd())
which returns a dictionary of my environment variables and their values, including 2 that answered my questions in the build results PWD and OLDPWD:
PWD /Users/<myname>/code
OLDPWD /Users/<myname>/code/code_py
...
[Finished 0.0ms]
...
[shell_cmd: cd /Users/<myname>/code/code_py; python -u "/Users/<myname>/code/code_py/YT-tutorials.py"]
...
AHA!
because i previously added cd $HOME/code my ~/.bash_profile, so every time i would build (command+B) in sublime with python, my shell profile would change directories behind the scenes and move me into my ~/code directory.
Now, after changing the python.sublime-build file as mentioned above changed this build behavior has been fixed -- & i hope this helps you too!
I am following this blog:
http://maplekeycompany.blogspot.se/2012/03/very-basic-cowboy-setup.html
In short, I am trying to compile an application with rebar just as the person in the blog.
Everything goes smoothly until I want to run the command:
./rebar get-deps compile generate
This then give me the following errors and warnings,
> User#user-:~/simple_server/rebar$ ./rebar get-deps compile generate
> ==> rebar (get-deps)
> ==> rebar (compile) Compiled src/simple_server.erl Compiled src/simple_server_http.erl src/simple_server_http_static.erl:5:
> Warning: behaviour cowboy_http_handler undefined Compiled
> src/simple_server_http_static.erl
> src/simple_server_http_catchall.erl:2: Warning: behaviour
> cowboy_http_handler undefined Compiled
> src/simple_server_http_catchall.erl WARN: 'generate' command does not
> apply to directory /home/harri/simple_server/rebar Command 'generate'
> not understood or not applicable
I have found a similar post with the same error:
Command 'generate' not understood or not applicable
I think the problem is in the reltool.config but do not know how to proceed, I changed the path to the following: {lib_dirs, ["home/user/simple_server/rebar"]}
Is there a problem with the path? How can rebar get access to all the src files and also the necessary rebar file to compile and build the application?
You need to make sure your directory structure and its contents are arranged so that rebar knows how to build everything in your system and generate a release for it. Your directory structure should look like this:
project
|
-- rel
|
-- deps
|
-- apps
|
-- myapp
| |
| -- src
| -- priv
|
-- another_app
The rel directory holds all the information needed to generate a release, and the apps directory is where the applications that make up your project live. Application dependencies live in the deps directory. Each app such as myapp and another_app under the apps directory can have their own rebar.config files. While two or more such applications are possible here, normally you'd have just one and all others would be dependencies.
In the top-level project directory there's also a rebar.config file with contents that look like this:
{sub_dirs, ["rel", "apps/myapp", "apps/another_app"]}.
{lib_dirs, ["apps"]}.
If necessary, you can use rebar to generate your apps from application skeletons:
cd apps
mkdir myapp another_app
( cd myapp && rebar create-app appid=myapp )
( cd another_app && rebar create-app appid=another_app )
If an application has dependencies, you'll have to add a rebar.config to its directory and declare each dependency there. For example, if myapp depends on application foo version 1.2, create apps/myapp/rebar.config with these contents:
{deps,
[{foo, "1.*", {git, "git://github.com/user/foo.git", {tag, "foo-1.2"}}}]
}.
When you run rebar get-deps, rebar will populate the top-level deps directory to hold all dependencies, creating deps if necessary. The top-level rebar.config can also declare dependencies if necessary.
You also need to generate a node, necessary for your releases:
cd ../rel
rebar create-node nodeid=project
You then need to modify the reltool.config file generated by the previous step. You need to change
{lib_dirs, []},
to
{lib_dirs, ["../apps", "../deps"]},
and just after the line {incl_cond, derived}, add {mod_cond, derived}, so that releases contain only the applications needed for correct execution.
Next, wherever the atom 'project' appears, you need to replace it with the applications under the apps directory. For our example, we'd change this part:
{rel, "project", "1",
[
kernel,
stdlib,
sasl,
project
]},
to this:
{rel, "project", "1",
[
kernel,
stdlib,
sasl,
myapp,
another_app
]},
and change this part:
{app, project, [{mod_cond, app}, {incl_cond, include}]}
to this:
{app, myapp, [{mod_cond, app}, {incl_cond, include}]},
{app, another_app, [{mod_cond, app}, {incl_cond, include}]}
You might also need to add the line:
{app, hipe, [{incl_cond, exclude}]},
to exclude the hipe application since sometimes it causes errors during release generation or when trying to run the release. Try without it first, but add it if you see errors related to hipe when generating a release, or if attempts to run the generated release result in this sort of error:
{"init terminating in do_boot",{'cannot load',elf_format,get_files}}
you'll need to add it.
With all this in place you can now execute:
rebar get-deps compile generate
and you should be able to successfully generate the release. Note that running rebar generate at the top level rather than in the rel dir will result in a harmless warning like this, which you can ignore:
WARN: 'generate' command does not apply to directory /path/to/project
Finally, you can run the release. Here's how to run it with an interactive console:
$ ./rel/project/bin/project console
Exec: /path/to/project/rel/project/erts-6.2/bin/erlexec -boot /path/to/project/rel/project/releases/1/project -mode embedded -config /path/to/project/rel/project/releases/1/sys.config -args_file /path/to/project/rel/project/releases/1/vm.args -- console
Root: /path/to/project/rel/project
Erlang/OTP 17 [erts-6.2] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:false]
Eshell V6.2 (abort with ^G)
(project#127.0.0.1)1>
or you could run ./rel/project/bin/project start to start it in the background. Run ./rel/project/bin/project with no arguments to see all available options.
I have the following sub-directories under /mnt.
root#debian-server:/mnt# ls
Backup huge raid1 Scripts usb
I would like to backup /mnt/raid1 and ignore everything else (Backup, huge, Scripts, usb).
Currently it works if I gave all exclude options. However, I would like to simplify the script by picking /mnt/raid1 and ignore everything else in /mnt. So far, I have not had success. Can someone please suggest what is the equivalent way for backing up using include /mnt/raid1?
OPTIONS="
--archive
--verbose
--perms
--progress
--hard-links"
EXCLUDES="
--exclude=/mnt/Backup
--exclude=/mnt/huge
--exclude=/mnt/Scripts
--exclude=/mnt/usb
--exclude=/dev
--exclude=/proc
--exclude=/sys
--exclude=/tmp"
INCLUDES="
"
cd /
$RSYNC $OPTIONS $INCLUDES $EXCLUDES . $DEST 2> $ERRLOG 1> $LOG
I use Capistrano 3 to deploy my WordPress projects (as implemented in the Bedrock WP stack: https://github.com/roots/bedrock).
WordPress specifically supports a number of features that update the actual code of the production/staging sites (plugin updates, settings files for certain plugins etc) and there are various scenarios where I might want to commit these code changes to the project GIT repo directly from a server.
So, the question is, is there a way configure Capistrano Deploy to keep the .git repo in the relase dir?
I gather this was doable with the 'copy strategy' settings in Cap 2, but I can't find any info about this for Cap 3.
I've solved this by modifying the custom deployment strategy that's implemented by https://github.com/Mixd/wp-deploy project.
Note the changed context.execute line.
# Usage:
# 1. Drop this file into lib/capistrano/submodule_strategy.rb
# 2. Add the following to your Capfile:
# require 'capistrano/git'
# require './lib/capistrano/submodule_strategy'
# 3. Add the following to your config/deploy.rb
# set :git_strategy, SubmoduleStrategy
module SubmoduleStrategy
# do all the things a normal capistrano git session would do
include Capistrano::Git::DefaultStrategy
# check for a .git directory
def test
test! " [ -d #{repo_path}/.git ] "
end
# same as in Capistrano::Git::DefaultStrategy
def check
test! :git, :'ls-remote', repo_url
end
def clone
git :clone, '-b', fetch(:branch), '--recursive', repo_url, repo_path
end
# same as in Capistrano::Git::DefaultStrategy
def update
git :remote, :update
end
# put the working tree in a release-branch,
# make sure the submodules are up-to-date
# and copy everything to the release path
def release
release_branch = fetch(:release_branch, File.basename(release_path))
git :checkout, '-B', release_branch,
fetch(:remote_branch, "origin/#{fetch(:branch)}")
git :submodule, :update, '--init'
# context.execute "rsync -ar --exclude=.git\* #{repo_path}/ #{release_path}"
context.execute "rsync -ar #{repo_path}/ #{release_path}"
end
end
This solution now deploys the release as a GIT repo set to a custom branch based on the release id.
This can then be committed and pushed up to the master repo for merging as required.
All credit goes to Aaron Thomas, the creator of the WP-Deploy project.
I'm setting up Ubuntu 13.10 on a Dell desktop. I've installed sqldeveloper and have a created a sqldeveoper.desktop file in my Desktop/ dir to launch the program. See code below. My problem is this: on my desktop screen I see the .desktop file as a sqldeveloper icon (the round db icon with a green arrow on it). I double-click the icon and the program launches. The icon appears in my Unity bar and then the image changes to a '?' question-mark symbol.
Any ideas why this happens? The icon.png (image) is in the location the desktop file is pointing to. Maybe the file is not seeing the path correctly from the Unity bar?
sqldeveloper.desktop code:
[Desktop Entry]
Type=Application
Version=1.0
Name=SQL Developer
GenericName=Oracle Development Environment
Comment=Proprietary environment for managing Oracle databases
Exec=sqldeveloper %F
Icon=/opt/sqldeveloper/icon.png
Terminal=false
Categories=Development;IDE;
StartupNotify=true
Thanks for any direction in this.
JohnC
Background
In version 4.1.5 of SQL Developer, the splash screen has WM_CLASS(STRING) = oracle-ide-osgi-boot-OracleIdeLauncher. Setting this as the value for key StartupWMClass in your .desktop file will work fine at first while the splash screen is visible.
The problem comes when SQL Developer's main window appears, because this second window has the generic WM_CLASS(STRING) = sun-awt-X11-XFramePeer only. Setting this generic value for StartupWMClass in your .desktop file doesn't work for reasons I don't fully understand.
A working solution for this problem is a .desktop file that uses a custom bash script. The custom script launches Oracle's startup script asynchronously, then waits for the main window to appear, and finally changes its WM_CLASS programmatically to the same value used by the splash screen. That WM_CLASS is also referred to by the .desktop file.
Custom bash script
Store this as $HOME/bin/launch-sqldeveloper.sh
#!/bin/bash
JAVA_HOME=/usr/lib/jvm/java-8-oracle
SQLD_HOME=/opt/sqldeveloper
# Launch Oracle's startup script asynchronously
env JAVA_HOME=$JAVA_HOME $SQLD_HOME/sqldeveloper.sh $* &
i="0"
while [ $i -lt 20 ]
do
# Try to get SQL Developer window ID
WIN_ID=$(xwininfo -root -tree \
| grep -i 'oracle sql developer' \
| grep -oP '(0x[a-f0-9]+)')
# If it is non-empty (window already exists)
if [ -n "$WIN_ID" ]
then
echo "WIN_ID=$WIN_ID"
# Set WM_CLASS property of main window to same value
# that is used for the launcher window
xprop -id $WIN_ID \
-f WM_CLASS 8s \
-set WM_CLASS "oracle-ide-osgi-boot-OracleIdeLauncher"
# and exit loop
break
else
# Otherwise sleep for one second and increment loop counter
echo "Sleeping: $i"
sleep 1s
i=$[$i+1]
fi
done
echo "Done"
.desktop File
[Desktop Entry]
Type=Application
Terminal=false
Name=SQL Developer
Exec=sh -c '$HOME/bin/launch-sqldeveloper.sh %F'
Icon=/opt/sqldeveloper/icon.png
StartupWMClass=oracle-ide-osgi-boot-OracleIdeLauncher
Assuming that you already verified the icon is in the location pointed by sqldeveloper.desktop (you can try ls /opt/sqldeveloper/icon.png from terminal).
Just add this line to sqldeveloper.desktop file
StartupWMClass=oracle-ide-boot-Launcher
And don't forget to run the command sudo update-desktop-database after saving the changes.
This worked for me https://askubuntu.com/questions/458554/how-to-install-sql-developer-on-ubuntu-14-04