I have a basic java app using java.awt Swing UI and I want to create a snap for it so when it's installed there is a launcher available and my UI Launches. I use gradle and the jar task to create a jar which works fine.
Naturally I have in a class that when called loads my app just fine:
package com.foo
class Bar() {
static void main(String... args) { launchUI() }
}
I created a snap folder at the root of the project and a snap.yaml where i followed the instructions on https://snapcraft.io/docs/java-applications so i have a snap yaml that produces a snap file which also installs fine:
name: deepthought
base: core18
version: '0.0.7'
summary: ""
icon: gui/foo.png
description: |
Computes the ultimate answer for life the universe and everything
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots
# This doesn't work
#apps:
# htmldoc:
# command: desktop-launch $SNAP/bin/foo.sh
## desktop: share/applications/htmldoc.desktop
# plugs: [home, network, x11]
parts:
foopart:
plugin: gradle
source: https://github.com/bsautner/foo.git
source-type: git
gradle-options: [] # suppress running of tests and run the war task
gradle-output-dir: build/libs
I've spent quite some time trying to figure out:
If i create a shell script to run a java -jar foo.jar command it ends up in the /snap directory but it's not on the users path so they can't get to it
I've tried creating launchers but always get an error that my launcher can't be found, if i put it in my root folder as /bin/launch.sh snap can't find it and if i put it in the snap/bin/ folder i also get errors to not put things in the snap folder
When I do install my snap, i don't see where it puts my jar i want to execute, so i can't write a script that does that
I'd really appreciate if anyone can share a working snap.yaml for a java program with a launcher and if there is any mention of a path to something that you note where those files are in relation to the path of the /snap/snap.yaml file
ok figured it out - the docs don't say this but the files are relative to the root of the project so even though the yaml says this is the launch
apps:
cmd3:
command: usr/bin/foo.sh
foo.sh should be in the root of the project and the orginize section here moves it to the bin dir
foo:
plugin: gradle
source-type: local
source: .
build-packages:
- openjdk-11-jdk
stage-packages:
- openjdk-11-jdk
- x11-utils
organize:
${SNAPCRAFT_PART_BUILD}/jg-snap: usr/bin/foo.sh
The jar is in the /snap/foo/current/usr/jar directory
Related
I'm tired of searching for answers, my problem is:
I want to create an executable file, I am working on a large program, and I encounter this problem, I did not find a solution, I created a new program to look for the problem, the new program does not have any code, just a line in order to show 'Hello Word' and added a picture in another package, And again encountered the same problem:
ant -f 'MyPath'\\New -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: 'MyPath'\New\build\built-clean.properties
Deleting directory 'MyPath'\New\build
clean:
init:
deps-jar:
Created dir: 'MyPath'\New\build
Updating property file: 'MyPath'\New\build\built-jar.properties
Created dir: 'MyPath'\New\build\classes
Created dir: 'MyPath'\New\build\empty
Created dir: 'MyPath'\New\build\generated-sources\ap-source-output
Compiling 1 source file to 'MyPath'\New\build\classes
Copying 1 file to 'MyPath'\New\build\classes
Attempt to copy 'MyPath'\New\src\pic\1.png to 'MyPath'\New\build\classes\pic\1.png using NIO Channels failed due to 'MyPath'\New\build\classes\pic\1.png (Accès refusé)'. Falling back to streams.
'MyPath'\New\nbproject\build-impl.xml:931: Failed to copy 'MyPath'\New\src\pic\1.png to 'MyPath'\New\build\classes\pic\1.png due to java.io.FileNotFoundException 'MyPath'\New\build\classes\pic\1.png (Accès refusé)
BUILD FAILED (total time: 2 seconds)
I'm using Netbeans IDE 8.2 , Sys : Windows 10.
It's a file/folder permissions problem. Your user does not have the rights to make changes to certain files/folders involved in the build process, so neither does Netbeans. You can validate this by running that ant command as root through the command line - it should suddenly work.
I solved the problem on mac by changing the group permissions for the parent folder listed in the error message and adding my user to said group.
I'm not an expert when it comes to permissions on Windows, so I shouldn't try to tell you how to do the same there, but you could reference something like this - https://www.online-tech-tips.com/computer-tips/set-file-folder-permissions-windows/ - for help in achieving the same thing.
I'm really new to maven and storm so I'm trying to follow the instructions in https://github.com/apache/storm/tree/master/examples/storm-starter. My current path is /home/luc/theTest/storm/examples/storm-starter. Inside the target folder there is a storm-starter-2.0.0-SNAPSHOT.jar file. I'm getting stuck when running
storm jar target/storm-starter-*.jar org.apache.storm.starter.ExclamationTopology -local
I get this error
ionTopology -local
Running: /usr/lib/jvm/java-8-openjdk-amd64/bin/java -client -Ddaemon.name= -Dstorm.options= -Dstorm.home=/home/luc/stormTest/apache-storm-1.1.1 -Dstorm.log.dir=/home/luc/stormTest/apache-storm-1.1.1/logs -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /home/luc/stormTest/apache-storm-1.1.1/lib/servlet-api-2.5.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/slf4j-api-1.7.21.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/objenesis-2.1.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/kryo-3.0.3.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/log4j-core-2.8.2.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/log4j-over-slf4j-1.6.6.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/storm-core-1.1.1.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/log4j-slf4j-impl-2.8.2.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/minlog-1.3.0.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/log4j-api-2.8.2.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/clojure-1.7.0.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/ring-cors-0.1.5.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/asm-5.0.3.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/reflectasm-1.10.1.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/disruptor-3.3.2.jar:/home/luc/stormTest/apache-storm-1.1.1/lib/storm-rename-hack-1.1.1.jar:target/storm-starter-2.0.0-SNAPSHOT.jar:/home/luc/stormTest/apache-storm-1.1.1/conf:/home/luc/stormTest/apache-storm-1.1.1/bin -Dstorm.jar=target/storm-starter-2.0.0-SNAPSHOT.jar -Dstorm.dependency.jars= -Dstorm.dependency.artifacts={} org.apache.storm.starter.ExclamationTopology -local
Error: Could not find or load main class org.apache.storm.starter.ExclamationTopology
Am I doing something wrong? I'm also a bit confused on whether I have to run the nimbus and supervisor first. I tried with and without them and neither worked anyways. Been searching the web but nothing works. Not sure what else to try.
This is usually caused by inconsistent versions of storm-client and storm-starter. Try following these steps to get the example working.
download the latest release from http://storm.apache.org/downloads.html
in this example, we will use version 1.1.1
extract this to a folder, lets call it ${STORM_HOME}
cd into ${STORM_HOME}/examples/storm-starter
execute mvn package -DskipTests=true
this should build the storm-starter jar in target folder
${STORM_HOME}/examples/storm-starter/target/storm-starter-1.1.1.jar
run the example from ${STORM_HOME} directory:
./bin/storm jar examples/storm-starter/target/storm-starter-1.1.1.jar org.apache.storm.starter.ExclamationTopology
don't add the -local flag since it seems like the ExclamationTopology is only deployed in a LocalCluster if no args are passed. You can check the source code here: ${STORM_HOME}/examples/storm-starter/src/jvm/org/apache/storm/starter/ExclamationTopology.java
I have previously been deploying a java application successfully in Cloud Foundry. However, now the developers have added a shared library compiled from C. I have added the .so to the .zip file (I'm using universal packager and deploying to Cloud Foundry by zip file) and ensured the .so is executable. However, when I deploy I get an error:
2016-12-23T14:39:01.013+00:00 [STG/0] [OUT] -----> Java Buildpack Version: eba4df6 | git://github.com/cloudfoundry/java-buildpack.git#eba4df6
2016-12-23T14:39:01.017+00:00 [STG/0] [ERR] [Buildpack] ERROR Compile failed with exception #<RuntimeError: No container can run this application. Please ensure that you’ve pushed a valid JVM artifact or artifacts using the -p command line argument or path manifest entry. Information about valid JVM artifacts can be found at https://github.com/cloudfoundry/java-buildpack#additional-documentation.
2016-12-23T14:39:01.017+00:00 [STG/0] [ERR] No container can run this application. Please ensure that you’ve pushed a valid JVM artifact or artifacts using the -p command line argument or path manifest entry. Information about valid JVM artifacts can be found at https://github.com/cloudfoundry/java-buildpack#additional-documentation.
2016-12-23T14:39:01.022+00:00 [STG/0] [ERR] Failed to compile droplet
2016-12-23T14:39:01.024+00:00 [STG/0] [OUT] Exit status 223
So my understanding is that I need to created a Custom Buildpack from the Java Buildpack. However, I am getting stuck with the code at this point:
https://github.com/ONSdigital/java-buildpack/blob/master/bin/compile#L28
# Adding crf tagger library
status "Adding crf tagger support"
cp $bp_dir/parsers/src/main/resources/libbackend.so $build_dir/vendor/
# update the PATH
status "Building runtime environment"
mkdir -p $build_dir/.profile.d
echo "export PATH=\"$HOME/bin:\$HOME/vendor/:\$PATH\";" > $build_dir/.profile.d/crftagger.sh
echo "export LD_LIBRARY_PATH=\"\$HOME/vendor/\";" >> $build_dir/.profile.d/crftagger.sh
From what I can gather I only need to modify the compile stage. What do I need to do to copy over the .so and have the Buildpack run successfully.
Please take a look to this https://docs.cloudfoundry.org/devguide/deploy-apps/deploy-app.html#profile
Pre-Runtime Hooks that's you need. I can't give you more details because you haven't provided enough information (project structure, do you have .profile in you root and etc.).
If you need to add shared libs try to use attr_reader :additional_libraries https://github.com/cloudfoundry/java-buildpack/blob/master/docs/extending-droplet.md
I have Netbeans set up on my project so that "Right click project -> Package As -> EXE Installer" will create an executable installer for the application.
The issue is that the installer sets up the application locally in
C:\%USERNAME%\AppData\Local\ApplicationName.
Is there any way to have the installer allow for selecting installation directory or, at the very least, install the application for all users?
usually we use C:\program files\...
I ended up no using the tools that Netbeans has built in since I find them very limiting.
Netbeans uses Inno Setup to create its executable files. Though it may exists, I could not find where to edit the script that Inno uses to create those executable files, so I went about it on my own.
I used this guide to combine all the dependencies into my application. If you have more than one, you add extra lines where the file says to do so.
I used Launch4j to package my .jar as a .exe.
I used Inno Setup to take that executable and make an installer with an icon, desktop icon and start menu icon support, and uninstall support. This is the script that I used (mostly generated with the gui) with removed personal info:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId=generated guid
AppName=app name
AppVersion=1.0
;AppVerName=app version name
AppPublisher=company name
AppPublisherURL=company name
AppSupportURL=company site
AppUpdatesURL=company site
DefaultDirName={pf}\app name
DefaultGroupName=app name
AllowNoIcons=yes
OutputDir=output directory
OutputBaseFilename=setup
SetupIconFile=icon directory
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "exe location"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\application name"; Filename: "{app}\exe file"
Name: "{group}\{cm:UninstallProgram,application name}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\application name"; Filename: "{app}\application name.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\application name.exe"; Description: "{cm:LaunchProgram,application name}"; Flags: nowait postinstall skipifsilent
I know this didn't really get a lot of traffic, but I hope it helps anyone that comes across it later.
I've to "compile" compass files dynamically in my java soft'. So, following explications found on stackoverflow, I've done these steps :
Get JRuby (1.7.3), configure PATH to jruby.jar and binaries (gem, rake ...) and learn to launch ruby script from Java
Get compass and dependancies gems into a local directory, using following command line
gem install -i ./compass compass
=> So I get a directory ./compass/ containing bin, cache,doc, gems & specifications directories.
Put gems in a jar using following command line (think to use a jar name which is not the same as the gems, to avoid JRuby "require" the jar instead of the gems)
jar cf compass-lib.jar -C compass .
Write a test script test.rb in local directory to test my jar. It contains :
require 'compass'
Compass.add_configuration(
{
:project_path => '.',
:sass_path => 'styles/scss',
:css_path => 'styles/css'
},
'custom' # A name for the configuration, can be anything you want
)
Compass.compiler.compile('test.scss', 'test.css')
Execute this script with JRuby, with following command line :
jruby -I . -rcompass-lib.jar test.rb
And get this error ...
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre
LoadError: no such file to load -- jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/s
ass-3.2.8/lib/sass/../sass
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass/ver
sion.rb:5
require at org/jruby/RubyKernel.java:1027
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
require at org/jruby/RubyKernel.java:1027
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/sass-3.2.8/lib/sass.rb:
9
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:60
(root) at jar:file:C:/jruby-1.7.3/lib/jruby.jar!/gems/compass-0.12.2/lib/comp
ass/dependencies.rb:6
each at org/jruby/RubyArray.java:1613
(root) at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
require at org/jruby/RubyKernel.java:1027
require at c:/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:36
(root) at test.rb:1
An idea of the problem and, maybe, of solution ? ;) Thanks by advance.
[UPDATE #1]
After Jörg W Mittag obvious suggestion, the error disapear. Thanks ;) Now, it just don't find the scss file, so it's a "normal problem" ;)
[UPDATE #2]
Having used compass with success in IRB, it's time to transpose the test through Java. So, I wrote some lines in Java to execute my ruby script, using only absolute path to avoid problems in a first time.
InputStream myFile = ISRessources.getFile("C:/Path/To/My/test.rb");
new ScriptingContainer().runScriptlet(myFile, "test.rb");
But ... how to "load" my compass-lib.jar ? What's the equivalent of the -r in JRuby ? I've tried to includ gems into jruby.jar, to add compass-lib.jar in externals jars in java build path, but both don't work, I still have :
LoadError: no such file to load -- compass
require at org/jruby/RubyKernel.java:1027
(root) at test.rb:1
Any idea ?
The error message says:
Unable to load Sass. Please install it with one of the following commands:
gem install sass --pre