Spring Boot Project Jar file not reading File placed on classpath - spring-boot

I am connecting my Spring Boot app with Google Cloud Sql and it got connected by placing Credential File in src/main/resources but Issue comes when I try to run the Jar File - [FileNotFound]
:: Spring Boot :: (v2.0.3.RELEASE)
application.properties-
spring.cloud.gcp.credentials.location=classpath:ArpanShoppingApp-863d536d1f93.json
and running jar file gives exception
java -jar CloudSQLConnect-1.0.jar
Exception-
2018-06-22 10:46:38.393 INFO 1172 --- [ main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Default MYSQL JdbcUrl provider. Connecting to jdbc:mysql://google/google_sql?cloudSqlInstance=mindful-highway-207309:asia-south1:shopping-db&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false with driver com.mysql.jdbc.Driver
2018-06-22 10:46:38.401 INFO 1172 --- [ main] o.s.c.g.s.a.GcpCloudSqlAutoConfiguration : Error reading Cloud SQL credentials file.
java.io.FileNotFoundException: class path resource [ArpanShoppingApp-863d536d1f93.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/Users/arpan/Documents/workspace-sts-3.8.4.RELEASE/CloudSQLConnect/target/CloudSQLConnect-1.0.jar!/BOOT-INF/classes!/ArpanShoppingApp-863d536d1f93.json
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:217) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:133) ~[spring-core-5.0.7.RELEASE.jar!/:5.0.7.RELEASE]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.setCredentialsProperty(GcpCloudSqlAutoConfiguration.java:167) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration.defaultJdbcInfoProvider(GcpCloudSqlAutoConfiguration.java:107) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]
at org.springframework.cloud.gcp.sql.autoconfig.GcpCloudSqlAutoConfiguration$$EnhancerBySpringCGLIB$$edf77794.CGLIB$defaultJdbcInfoProvider$1(<generated>) [spring-cloud-gcp-starter-sql-1.0.0.M1.jar!/:1.0.0.M1]

This appears to be a limitation of spring-cloud-gcp. It seems like credential files must be on the filesystem and cannot be package into a jar. The latest code has a better error message than the M1 version that you're using.

Related

Unable to connect non stop SQL from Spring boot applivcation

My project uses non stop SQL/MX as RDBMS database, a product from HP.I am not able to connect to the data source using Spring Boot's standard practice of defining JDBC URL, user, password inside application.properties file.
spring.datasource.driverClassName = com.tandem.sqlmx.SQLMXDriver
spring.datasource.url = jdbc:sqlmx:
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SqlmxDialect
spring.datasource.hikari.connection-test-query=SELECT 1 FROM $USER1.TLFM3SQL.IF09CSTB
This is the error:
com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver does not support get/set network timeout for
connections. (com.tandem.sqlmx.SQLMXConnection.getNetworkTimeout()I)
JdbcEnvironmentInitiator: could not obtain connection to query metadata: Unable to resolve name
[org.hibernate.dialect.SqlmxDialect ] as strategy [org.hibernate.dialect.Dialect]
I had not included SQLMX hibernate jar in project.
It worked after I included that jar in my pom.

Apache Nifi windows unable to load NAR library bundles

I'm only attempting to launch the Nifi UI as a local instance to start playing with it. I've unzipped the package and made sure to set the JAVA_HOME variable to my Java 1.8. When I try to bin/run-nifi, in my nifi-app log, the error message is:
2018-05-03 15:03:50,585 INFO [main] org.apache.nifi.NiFi Launching NiFi...
2018-05-03 15:03:52,330 INFO [main] o.a.nifi.properties.NiFiPropertiesLoader Determined default nifi.properties path to be 'Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\conf\nifi.properties'
2018-05-03 15:03:52,363 INFO [main] o.a.nifi.properties.NiFiPropertiesLoader Loaded 146 properties from Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\conf\nifi.properties
2018-05-03 15:03:52,423 INFO [main] org.apache.nifi.NiFi Loaded 146 properties
2018-05-03 15:03:52,779 INFO [main] org.apache.nifi.BootstrapListener Started Bootstrap Listener, Listening for incoming requests on port 64802
2018-05-03 15:03:53,071 INFO [main] org.apache.nifi.BootstrapListener Successfully initiated communication with Bootstrap
2018-05-03 15:03:53,181 WARN [main] org.apache.nifi.nar.NarUnpacker Unable to load NAR library bundles due to java.io.IOException: Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\work\nar\framework directory does not have read/write privilege Will proceed without loading any further Nar bundles
2018-05-03 15:03:53,242 ERROR [main] org.apache.nifi.NiFi Failure to launch NiFi due to java.io.IOException: Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\work\nar\framework could not be created
java.io.IOException: Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\work\nar\framework could not be created
at org.apache.nifi.util.FileUtils.ensureDirectoryExistAndCanReadAndWrite(FileUtils.java:48)
at org.apache.nifi.nar.NarClassLoaders.load(NarClassLoaders.java:155)
at org.apache.nifi.nar.NarClassLoaders.init(NarClassLoaders.java:131)
at org.apache.nifi.NiFi.<init>(NiFi.java:133)
at org.apache.nifi.NiFi.<init>(NiFi.java:71)
at org.apache.nifi.NiFi.main(NiFi.java:292)
2018-05-03 15:03:53,383 INFO [Thread-1] org.apache.nifi.NiFi Initiating shutdown of Jetty web server...
2018-05-03 15:03:53,387 INFO [Thread-1] org.apache.nifi.NiFi Jetty web server shutdown completed (nicely or otherwise).
I've followed the installation instructions and haven't been able to trouble shoot. How do I load these NAR files upon running Nifi?
Thanks
I believe the underlying error in your output is java.io.IOException: Z:\DoE\LOCAL-~1\NIFI-1~1.0\.\work\nar\framework could not be created.
NiFi requires file permissions to create and write several directories, there is a list in the NiFi Admin Guide: How to install and start NiFi. NiFi does this to unpack the NAR files, write logs, and for various data repositories that comprise your data flow.
You have a few options:
Modify the permissions of the directory to allow NiFi read/write access. This can be done for each individual child directory.
Copy the entire NiFi distribution to a read/write location and run it from there.
Edit the conf/nifi-properties file to change the locations of these directories to read/write locations. See NiFi Admin Guide: System Properties for help on the properties.
Symlinks are a great solution for systems that support symlinks.
Two things you can try:
Run NiFi with administrator privilege (not a good practice) by going to ~\<NIFI_INSTALLATION_DIR>\bin and right click run-nifi.bat. Click Run as Administrator
Move NiFi directory to a location where the logged in user has full access to. Ex: C:\Users\<YOUR_USER>\Documents\. Now try to execute bin\run-nifi.bat
Similarly to the resolution that James proposed. I had to do the below 3-step process.
My scenario: I'm using docker containers and had the same problem. Even changing the user of my container to root didn't work. So, I did the following:
1 - Download Minifi https://nifi.apache.org/minifi/download.html
2 - Untar and execute the Minifi agent on my own laptop (I'm using MAC) so that the necessary folders and files will be created.
3 - Tar it up again and add to the DockerFile of my container creation
Done! Everything worked fine after that.

Spring Boot and Axis2 client runtime issue with Rampart

I am trying to use Axis 2 client to work with a soap based web service. I use Rampart 1.7.1 for WSO Authentication. After I created the stub code using axis2tools I installed the jar files into maven repository and use them as dependency in my pom.xml file. Also I use spring boot for the rest of application which I use the generated libraries as soap client api.
Everything is good in dev environment I can work with web service. And also when I use
mvn spring-boot:run
it works fine and webservice communication is good from UI to Webservice and back(end to end).
when I use
java -jar target/fatjar.jar
When I send request to web service I receive the following error at console:
2017-11-17 16:00:35.140 WARN 31114 --- [nio-8080-exec-2] o.a.axis2.deployment.AxisConfigBuilder : Unable to instantiate deployer org.apache.axis2.deployment.ServiceDeployer; see debug logs for more details
2017-11-17 16:00:35.161 INFO 31114 --- [nio-8080-exec-2] o.a.axis2.deployment.DeploymentEngine : No services directory was found under /home/mehdi/Workspace/EclipseWS/src/main/resources/axis.
2017-11-17 16:00:35.179 INFO 31114 --- [nio-8080-exec-2] o.a.axis2.deployment.ModuleDeployer : Deploying module: rampart-1.7.1 - file:/home/mehdi/Workspace/EclipseWS/src/main/resources/axis/modules/rampart-1.7.1.mar
2017-11-17 16:00:35.185 ERROR 31114 --- [nio-8080-exec-2] o.a.axis2.deployment.ModuleDeployer : The rampart-1.7.1.jar module, which is not valid, caused The /home/mehdi/Workspace/EclipseWS/target/cybersourceClient-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/rampart-1.7.1.jar file cannot be found.
org.apache.axis2.AxisFault: The /home/mehdi/Workspace/EclipseWS/target/cybersourceClient-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/rampart-1.7.1.jar file cannot be found.
at org.apache.axis2.deployment.repository.util.DeploymentFileData.setClassLoader(DeploymentFileData.java:118) [axis2-kernel-1.7.1.jar!/:1.7.1]
at org.apache.axis2.deployment.ModuleDeployer.deploy(ModuleDeployer.java:133) ~[axis2-kernel-1.7.1.jar!/:1.7.1]
at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:144) [axis2-kernel-1.7.1.jar!/:1.7.1]
at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:585) [axis2-kernel-1.7.1.jar!/:1.7.1]
at org.apache.axis2.deployment.RepositoryListener.loadClassPathModules(RepositoryListener.java:222) [axis2-kernel-1.7.1.jar!/:1.7.1]
same line when I use "mvn spring-boot:run" is
2017-11-17 16:13:14.270 WARN 7823 --- [nio-8080-exec-9] o.a.axis2.deployment.AxisConfigBuilder : Unable to instantiate deployer org.apache.axis2.deployment.ServiceDeployer; see debug logs for more details
2017-11-17 16:13:14.286 INFO 7823 --- [nio-8080-exec-9] o.a.axis2.deployment.DeploymentEngine : No services directory was found under /home/mehdi/Workspace/EclipseWS/src/main/resources/axis.
2017-11-17 16:13:14.301 INFO 7823 --- [nio-8080-exec-9] o.a.axis2.deployment.ModuleDeployer : Deploying module: rampart-1.7.1 - file:/home/mehdi/Workspace/EclipseWS/src/main/resources/axis/modules/rampart-1.7.1.mar
2017-11-17 16:13:14.304 INFO 7823 --- [nio-8080-exec-9] o.a.axis2.deployment.ModuleDeployer : Deploying module: rampart-1.7.1 - file:/home/mehdi/.m2/repository/org/apache/rampart/rampart/1.7.1/rampart-1.7.1.jar
Please notice that it fails for:
...The rampart-1.7.1.jar module, which is not valid,...
I don't know why with maven launch it works but with java -jar throws exception.
According to Spring Boot documentation (Further Config section) in here
I needed to add the rampart library to unpacked list in spring-boot-maven-plugin as follows:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<requiresUnpack>
<requiresUnpack>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart</artifactId>
</requiresUnpack>
</requiresUnpack>
</configuration>
</plugin>

log4j2 shutdownHook="disable" not working

I have the shutdownhook error in my Spring boot application in which i use log4j2.
I saw that it was a bug in log4j2 and shutdownHook="disable" was suppossed to resolve it. But inspite of using the same i still get the same error.
I am using spring boot version 1.3.7.RELEASE and the dependecy for log4j2 is
spring-boot-starter-log4j2 .
Error which i get whetry to close the session using Ctrl-C
2016-08-23 13:38:56,098 Thread-7 ERROR No log4j2 configuration file found. Using
default configuration: logging only errors to the console.
2016-08-23 13:38:56,105 Thread-7 FATAL Unable to register shutdown hook because
JVM is shutting down. java.lang.IllegalStateException: Cannot add new shutdown h
ook as this is not started. Current state: STOPPED
at org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry.ad
dShutdownCallback(DefaultShutdownCallbackRegistry.java:113)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.addShutdownCal
lback(Log4jContextFactory.java:271)
at org.apache.logging.log4j.core.LoggerContext.setUpShutdownHook(LoggerC
ontext.java:256)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:
216)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log
4jContextFactory.java:146)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log
4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:185)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(Abstrac
tLoggerAdapter.java:103)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFac
tory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(Abstract
LoggerAdapter.java:42)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFact
ory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at com.worldline.frm.dataloader.policy.CustomQueueRoutePolicy.onStop(Cus
tomQueueRoutePolicy.java:90)
at org.apache.camel.impl.RouteService.doStop(RouteService.java:249)

Configuration file not found - JBoss7

I wanted to deploy a simple jsp application: I created and copied the myApp.war file to the $JBOSS_HOME/standalone/deployment folder.
Instead of deploying the war file , JBoss created *.war.failed ,
So I thought maybe it's a good idea to restart the jboss to see if it affects the deployment.
In some forums it was suggested to restart the JBoss through : $JBOSS_HOME/bin/jboss-cli.sh
But there was no shutdown or restart command.
While I was trying to restart , I ran the following command :
/usr/local/jboss7/bin/jboss-cli.sh -c ":shutdown(restart=true)"
JBoss stopped working , but it didn't start again.
Now , I want to start it again by :
$JBOSS_HOME/bin/standalone.sh
But it gives me the following exception :
=========================================================================
JBoss Bootstrap Environment
JBOSS_HOME: /usr/local/jboss7
JAVA: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java
JAVA_OPTS: -server -XX:+UseCompressedOops -XX:+TieredCompilation -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.server.default.config=standalone.xml
=========================================================================
17:29:43,399 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
17:29:43,536 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
17:29:43,567 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
17:29:43,876 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '*' (code 42) (expected a name start character)
at [row,col {unknown-source}]: [190,160]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
at com.ctc.wstx.sr.StreamScanner.parseLocalName(StreamScanner.java:1798)
at com.ctc.wstx.sr.BasicStreamReader.handleNsAttrs(BasicStreamReader.java:2975)
at com.ctc.wstx.sr.BasicStreamReader.handleStartElem(BasicStreamReader.java:2926)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2802)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1050)
at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1125)
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.nextTag(XMLExtendedStreamReaderImpl.java:152) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.as.server.deployment.scanner.DeploymentScannerParser_1_1.readElement(DeploymentScannerParser_1_1.java:85)
at org.jboss.as.server.deployment.scanner.DeploymentScannerParser_1_1.readElement(DeploymentScannerParser_1_1.java:28)
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:894) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:330) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:127) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:100) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
... 3 more
17:29:43,882 FATAL [org.jboss.as.server] JBAS015957: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.
17:29:43,889 INFO [org.jboss.as] JBAS015950: JBoss AS 7.1.1.Final "Brontes" stopped in 4ms
I searched for the cause of the problem , and I found that probably there's a problem with standalone.xml file.
In /usr/local/jboss7/standalone/configuration/standalone_xml_history I have the following files , but not the standalone.xml
2014xxxx-xxxxxxxx
snapshot
standalone.initial.xml
current
standalone.boot.xml
standalone.last.xml
I'd like to know if I have to rename any of these files to standalone.xml ? (actually I tried renaming standalone.boot.xml to standalone.xml but it didn't work either !) or download a new one ? may I remove these xml files after having the new standalone.xml ?
If JBoss-7 is installed in $JBOSSHOME, the default standalone configuration file is $JBOSS_HOME/standalone/configuration/standalone.xml; $JBOSSHOME/standalone/configuration is the default value of the jboss.server.config.dir property; and running $JBOSSHOME/bin/standalone.sh with no options will start JBoss in standalone mode on Linux/Unix systems.
In order to use a different standalone configuration file it can be renamed to standalone.xml, put in jboss.server.config.dir if it is not already there and standalone.sh run with no options; or its file name can be given to standalone.sh as an argument to its -c option after it is put in jboss.server.config.dir, for example:
$JBoss_home/bin/standalone.sh -c standalone-full.xml
RedHat documentation for this is at https://docs.jboss.org/author/display/AS71/Command+line+parameters
I have had the best success with standalone/configuration/standalone-full.xml since it has the full configuration. It is shipped with JBoss-7. If you don't have it you could download a fresh copy of the distro to get it. What I always do is archive a zip of the distro for recovery in case something gets corrupted or lost in the working copy.

Resources