Environment variables not detected when deploying to AppFog - java

It seems that when deploying my Spring app to AppFog, that the environment variables are not being detected.
I have the environment variables declared in my console:
And I try to reference these from within my app code, like so:
<context:property-placeholder
location="classpath:server.common.properties,
classpath:server.${concorde-env}.properties"/>
However, this generates an error:
Caused by: java.io.FileNotFoundException: class path resource
[server.${concorde-env}.properties] cannot be opened because it does
not exist
This approach works fine in other (non AppFog) environments.
I logged out the properties by calling:
log.info("Properties: " + System.getProperties().toString());
And it doesn't show those properties as available.
However, if I do a af env <<MY_APP_NAME>>, it shows the variables as present:
+--------------------------+------------------+
| Variable | Value |
+--------------------------+------------------+
| concorde-env | test |
| spring.profiles.active | runtime,test |
+--------------------------+------------------+
What am I missing to make these variables exposed to my app at runtime?

Try accessing the value like this: System.getenv("concorde-env") to see if the environment var can even be accessed in code.
Based on the error message "class path resource [server.${concorde-env}.properties] cannot be opened because it does not exist" it seems like ${concorde-env} is not even being evaluated or replaced even with empty string.
It looks like Spring has other ways of accessing env vars. Try #{systemEnvironment['concorde-env']} instead of ${concorde-env}

Related

Jenkinsfile: pass env from another script

Consider a folder with two jenkins files, JenkinsfileA and JenkinsfileB.
# JenkinsfileA
node {
environment {
APP_NAME = 'APPLICATION_A'
# Load the other jenkins file
load `JenkinsfileB'
}
#JenkinsfileB
node{
echo "Got parameter $APP_NAME"
stage ('do something'){
echo 'doing something'
}
}
In B, the $APP_NAME param is coming up null. What is the canonical way to pass APP_NAME parameter from A into B? Should I be using load here or something else? Are env vars. preferred or can we make use of parameters somehow?
Update
I think the reason env isn't working for me is because jenkins is triggering second job in a completely separate workspace. I'd like to do something like this:
load 'JenkinsfileB', parameters: [[$class: 'StringParameterValue', name: 'MYPARAM', value: "some-value" ]]
But keep getting error
java.lang.IllegalArgumentException: Expected named arguments but got [{parameters=[{$class=StringParameterValue, name=MYPARAM, value=some-value}]}, JenkinsfileB]
And when I try to use build job syntax instead of load the build can't even find JenkinsfileB, so I am stumped.
Unreleated: is node still the correct directive to use to ensure builds run on any agent, or should I be using pipeline{ agent: any}? Got node from this article

Windows, Gradle and Cucumber combination throws an IOException upon generating reports

I'm working on a project which uses a combination of Windows, Java, Groovy, Gradle and Cucumber. This combination gives me some problems on my Windows machine that my *NIX colleagues are not experiencing. Upon running the gradle build, gradle wants to output some reports. The location and filename of these reports is apparently determined by the definition or output of the Cucumber tests. The name used is unfortunately not something that can be used as a filename, so I'm getting an IOException for each test report.
For the Cucumber test, we use the following structure:
Scenario Outline: Receive and parse ReturnItem from Service
Given The message from service return item outlined in <messagePath>
When We process the message
Then XXX posted a message to YYY on topic <topic> with event <eventType>
And payload matches <resultPath>
| messagePath | topic | eventType | resultPath |
| /test/testxml.xml | test_topic | EVENT_TYPE | /result/result.json |
After running this, I receive the following exception:
Caused by: org.gradle.api.UncheckedIOException: Could not write to file 'C:\xxx\project\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result\result.html'.
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:151)
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:127)
at org.gradle.internal.IoActions.writeTextFile(IoActions.java:45)
at org.gradle.reporting.HtmlReportRenderer$DefaultHtmlReportContext.renderHtmlPage(HtmlReportRenderer.java:118)
at org.gradle.api.internal.tasks.testing.report.DefaultTestReport$HtmlReportFileGenerator.run(DefaultTestReport.java:147)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.access$900(DefaultBuildOperationExecutor.java:48)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$ParentPreservingQueueWorker.execute(DefaultBuildOperationExecutor.java:342)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:230)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.access$600(DefaultBuildOperationQueue.java:172)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:209)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:203)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:154)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:203)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:177)
... 3 more
Caused by: java.io.IOException: Unable to create directory 'C:\xxx\project\project-test\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result'
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:141)
... 19 more
Does anybody know how to fix this? The only 'solution' I could come up with is disabling the reports, which works, but is more a workaround than a solution. For disabling I used the following configuration in the gradle.build for this:
apply plugin: 'java'
apply plugin: 'groovy'
test {
reports {
junitXml.enabled = false
html.enabled = false
}
}
(Inspired by: How to make Gradle build produce HTML test report instead of XML default?)
I finally found the culprit. Apparently these filenames correspond to the default behaviour of JUnit for report generation of Cucumber tests. On *NIX, this doesn't provide any problem. On Windows however, this will result in an exception due to the pipes in the Examples. The IOException is somewhat special apparently, since the most exceptions that I found on the internet were FileNotFoundExceptions. That explains why it took me so long to find an answer, I focused on the exception.
The solution here is to use the following JUnitOption as an #CucumberOptions annotation when running the Cucumber tests: --filename-compatible-names.
A code example for Java & Spring looks like this:
#RunWith(Cucumber.class)
#CucumberOptions(junit = {"--filename-compatible-names"})
public class CucumberRunner {
}
It would be nice if these kind of non-breaking OS dependent options would be default instead of optional.
Based upon the information provided, it looks like it's trying to create a directory called:
'C:\xxx\project\project-test\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result'
Can you show the code around passing in messagePath? I suspect you are passing in the entire row of data rather than just the messagePath (I'm going to take a wild guess that you are performing a .toString() on an array instead of passing in the first element of the array)

Java ClassLoader Not Finding Expected Resource

I have a jar file that contains the following:
LibJar Contents
dir1
|dir1-1
| |Class1-1-1
| |LClass1-1-2
|Ldir1-2
|LClass1-2-1
Ldir2
|LClass2-1
My java program (we can call it ProgJar, but I also run it in Netbeans IDE) has the following package structure:
ProgJar
dir1
|dir1-1
| |Class-1-1
| |PClass1-1-2 Different file name from LibJar
Pdir2
|PClass2-1
The only shared package structure between ProgJar and LibJar is "dir1/dir1-1/Class1-1-1". Everything else prefixed with a P is unique to ProgJar and everything prefixed with a L is unique to LibJar.
I use LibJar as a library in ProgJar.
This is the snippet of code I run in ProjJar:
ClassLoader clP = Pdir2.PClass2-1.class.getClassLoader();
ClassLoader clL = Ldir2.LClass2-1.class.getClassLoader();
URL u1 = clP.getResource("dir1/dir1-1");
URL u2 = clL.getResource("dir1/dir1-1");
System.out.printf(u1.toExternalForm());
System.out.printf(u2.toExternalForm());
When I run this in Netbeans I get the following output:
Netbeans Output:
jar:file:/C:/path/to/project/lib/LibJar.jar!/dir1/dir1-1
jar:file:/C:/path/to/project/lib/LibJar.jar!/dir1/dir1-1
When I run as a ProgJar as a built jar outside of netbeans, I get:
Jar Output:
jar:file:/C:/path/to/ProgJar/ProgJar.jar!/dir1/dir1-1
jar:file:/C:/path/to/ProgJar/ProgJar.jar!/dir1/dir1-1
What I expect to see is the following:
Netbeans Output:
jar:file:/C:/path/to/project/build/classes/dir1/dir1-1
jar:file:/C:/path/to/project/lib/LibJar.jar!/dir1/dir1-1
Jar Output:
jar:file:/C:/path/to/ProgJar/ProgJar.jar!/dir1/dir1-1
jar:file:/C:/path/to/ProgJar/libs/LibJar.jar!/dir1/dir1-1
I read through a few different articles, but this one seems somewhat relevant to this particular issue:
http://jeewanthad.blogspot.com/2014/02/how-to-solve-java-classpath-hell-with.html
How am I able to achieve my specified output?
Below code is not doing what you are expecting it to do:
ClassLoader clP = Pdir2.PClass2-1.class.getClassLoader();
ClassLoader clL = Ldir2.LClass2-1.class.getClassLoader();
Here clP amd clL are same Classloader instances(you system/application classloader to be specific).To verify, just see (clP == clL) should return true.
What you want to do is, use a custom classloader(URLClassLoader should do) to load your library. Then, the system classloader that loaded your ProgJar and your custom classloader will be different. Then rest of your code should work as expected.

fatal error: webkit2/webkit2.h: No such file or directory

On Arch Linux, after upgrading to Gnome 3.14, I have several troubles with Webkit2Gtk.
Vala:
Consider the following vala test:
using Gtk;
using WebKit;
public class ValaWebkit : Window {
private WebView web_view;
public ValaWebkit(){
this.title = "Testing youtube";
set_default_size (800, 600);
web_view = new WebView();
add(web_view);
//this.web_view.open ("http://www.youtube.com/");
this.web_view.load_uri ("https://www.youtube.com/");
}
public static int main (string[] args) {
Gtk.init (ref args);
new ValaWebkit().show_all();
Gtk.main();
return 0;
}
}
Before upgrading to Gnome 3.14, I could copile like this valac --pkg gtk+-3.0 --pkg webkit2gtk-3.0 --vapidir . valawebkit.vala (I'm not pasting here webkit2gtk-3.0.vapi because it's too long). Now with gnome 3.14 if I try to compile i get
/home/luca/Sources/vala/webkit test/valawebkit.vala.c:8:29: fatal error: webkit2/webkit2.h: No such file or directory
#include <webkit2/webkit2.h>
^
compilation terminated.
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Also, If I try to run the binary that I had compiled BEFORE upgrading to Gnome 3.14, I get this error:
./valawebkit: error while loading shared libraries: libwebkit2gtk-3.0.so.25: cannot open shared object file: No such file or directory
2) GJS / Eclipse / Java (SWT):
If I run either this gjs example, or eclipse (luna) or any other swt 4.4 based app, I get the following:
No bp log location saved, using default.
[000:000] Cpu: 6.58.9, x4, 2600Mhz, 7847MB
[000:000] Computer model: Not available
[000:000] Browser XEmbed support present: 1
[000:000] Browser toolkit is Gtk2.
[000:004] Using Gtk2 toolkit
[000:004] Warning(optionsfile.cc:47): Load: Could not open file, err=2
[000:004] No bp log location saved, using default.
I have the feeling that it is a kind of packaging issue on ArchLinux and Gnome 3.14. Does anyone is having the same issue? Is there a workaround both to compile and run against webkit2gtk?
EDIT
I made a little progress: I discovered that headers files I need are now under /usr/include/webkitgtk3.0 and /usr/include/libsoup-2.4. Now, compiling like this:
valac --pkg gtk+-3.0 --pkg webkit2gtk-3.0 --vapidir . --Xcc="-I/usr/include/webkitgtk-3.0" --Xcc "-I/usr/include/libsoup-2.4" --thread valawebkit.vala
works, but it sill fails on linker:
/tmp/ccQGhB3b.o: In function `vala_webkit_construct':
valawebkit.vala.c:(.text+0x6e): undefined reference to `webkit_web_view_new'
valawebkit.vala.c:(.text+0x101): undefined reference to `webkit_web_view_load_uri'
collect2: error: ld returned 1 exit status
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
There fact that you have to specify the --Xcc flags suggests that you are missing the pkgconfig file for WebKit. There should be a webkit2gtk-3.0.pc in /usr/lib/pkgconfig. The Arch package webkit2gtk has a pkgconfig file named webkit2gtk-4.0.pc. So, if you rename your VAPI file, that should link properly.
Actually with webkit2gtk-4.0 I don't need to provide a vapi file any more. So I can delete my webkit2gtk-4.0.vapi and complile like this (even simpler):
valac --pkg gtk+-3.0 --pkg webkit2gtk-4.0 --thread valawebkit.vala

Package name breaks JNI classpath?

I'm working on a JNI application. It is a C program that calls some Java methods.
I wrote it following some internet examples.
First I created a simple example in Eclipse Indigo (it created the Java files in a "default package"). Then I used something like this in the C code:
options.optionString = "-Djava.class.path=/home/elias/workspace/Funciones/bin";
All worked fine but then I re-made the Java proyect to have the Java code in a package called "Funciones", so I modified to:
options.optionString = "-Djava.class.path=/home/elias/workspace/Funciones/bin/Funciones";
But now I doesn't work... I supposed it is something I have wrong in the classpath.
Can someone help me please?
Thanks.
You want the class path to point at the directory (or directories, or jar files) holding the top-level packages you're using, not inside the packages. So if your code is laid out like this:
~/Funciones/bin/
|
>----Funciones
| |
| >----Funciones.class – this is the class Funciones.Funciones
|
>----some other package
|
:
you need to add ~/Funciones/bin to your classpath. To find the class, you need to use its fully qualified name – the class name prefixed with the package name:
Class clsFunciones = Class.forName("Funciones.Funciones");
or, in JNI, the class descriptor:
jclass clsFunciones = (*env)->FindClass(env, "Funciones/Funciones");

Categories