Jar entry not found by running gradle generated jar - spring

I've downloaded the source code (zip file) from the spring getting started guide: http://spring.io/guides/gs/rest-service/
Building the whole project within the folder "complete" was successful. Also running the generated jar file using Gradle (gradle run) was successful. But when I try to run it manually in the Windows command line with "java -jar build\libs\gs-rest-service-0.1.0.jar" the startup process failed with the following error:
2014-06-25 14:17:22.414 ERROR 6864 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: I/O failure during classpath scanning; nested exception is java.io.FileNotFoundException: JAR
entry /hello/ not found in D:\gs-rest-service-master\complete\build\libs\gs-rest-service-0.1.0.jar
Apparently spring can not find the folder "hello" even though it is located within the jar (I've checked it with the command "jar -ft").

You don't say which version of Boot you're using, but it sounds like you've hit a recently reported problem in 1.1.2 that's specific to Windows. You can either drop back to 1.1.1 or wait for 1.1.3 which, given the problems with 1.1.2 on Windows, should be available in the not too distant future.

Related

Error occurred during initialization of boot layer java.lang.module.FindException: Module jdk.management.agent not found

I am setting up my first Spring Boot application using Eclipse > New > Spring-Starter project
The project files are appearing and compiling.
I am even able to RunAs > Java project with console output.
On choosing RunAs > Spring Boot, I am getting the above error in the console:
Error occurred during initialization of boot layer java.lang.module.FindException: Module jdk.management.agent not found
My Java version is Java15, and I have also verified the same path is being used by Eclipse in About Eclispse > Installation Details > Configuration which shows
-vm C:\Program Files\Java\jdk-15.0.1\bin\server\jvm.dll
Running java --list-modules shows the management.agent module in the list shown in the command line output:
jdk.localedata#15.0.1
jdk.management#15.0.1
jdk.management.agent#15.0.1
jdk.management.jfr#15.0.1
Maven version installed is 3.3.6
I am not sure what I am missing. Any ideas?

How to debug start of eclipse plugin?

I try to migrate an eclipse plugin from Java8 to Java9. If I start a debug session (Run as Eclipse Application...) all works fine.
However, after installing my plugin I am not able to use it. If I use ss in the OSGI console I get following status for my plugin:
1102 STARTING org.treez.core_1.0.0.201712191435
and if I manually try to start it I get
osgi> start 1102
gogo: BundleException: Error loading bundle activator.
I tried to start a remote debug session, as suggested here:
Debugging Eclipse plug-ins
I set a break point in the constructor of my Activator but that break point is never reached.
=> How can I get additional information about why the loading of the bundle activator fails? Is there some log file? Can I somewhere set a logging level to TRACE?
I assume that the issue might be that a resource can be found while debugging the Eclipse Application but not when using the bundled jar. More info, e.g. the name of the resource that could not be found, would be very helpful.
Related questions:
Debugging Eclipse plug-ins
CQ5 OSGi bundle does not start:- Activator cannot be found
When plugins fail to start there is normally a message in the .log file in the workspace .metadata directory.
On Linux, Unix and macOS this file and directory are hidden so you may need to do something special to see them.

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

problems running state machine examples

Congratulations on the spring state machine, I found it yesterday and have been trying it out, specifically the turnstile example running in STS. I found it very easy and intuitive to build a FSM.
Because spring shell doesn't work well in STS I tracked down the instructions to run the examples from the command line in the reference doc,
"java -jar
spring-statemachine-samples-turnstile-1.0.0.BUILD-SNAPSHOT.jar"
,
but running it got an error
"no main manifest attribute, in spring-statemachine-samples-turnstile-1.0.0.BUILD-SNAPSHOT.jar".
Although not even a novice in using gradle, I tried fixing this by adding this line to build.gradle in the jar section
"manifest.attributes['Main-Class'] = 'demo.turnstile.Application'"
(which doesn't handle the various sub-projects I know) but got this error
"NoClassDefFoundError: org/springframework/shell/Bootstrap".
If it is possible to run the samples from gradle, could you include them in the reference document? I tried running the samples using
gradle run
but it there was no interaction with the shell scripts.
Samples are designed to be run as executable jar and with shell so that you can interact without a need to recompile with every change. Your error indicates that you didn't build that sample jar as mentioned in docs.
./gradlew clean build -x test
This will automatically use spring boot plugin which will add the necessary jar manifest headers to jar meta info to make it a true executable jar. Essentially every every sample is a spring boot app.
Building SM sample projects in Windows Environment:
Open Command prompt (windows key + r -->cmd-->Enter), Change directory to project root folder spring-statemachine-master (Inside the Extracted folder).
Run gradlew install to get all spring dependencies copied to local machine.
Run gradlew clean build -x test to get the spring shell jars built. Courtesy Janne
These steps should ideally get all .jar built, look into \build\libs folder of respective sample project for jar files.
Run the like any other java jar file java -jar [jar-file-name.jar] (make sure to be change directory to jar file directory location).
One more thing where I was stuck was, How to give events to SM:
It's like this sm event EVENT_NAME_AS_DEFINED_IN_CLASS. Ref
E.g.: sm event RINSE --> to washer project

Grails - How to add Oracle jdbc jar to classpath without placing in /lib?

I am attempting to get my grails application running locally with tomcat, but without placing ojdbc6.jar in /lib. My grails application is deployed to Glassfish and works fine on the server (because the ojdbc6.jar is available there). As expected the error is:
Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
(Failed) Approach #1
I first customized my GGTS run-configuration to include the VM arguments:
-cp :/somelocalpath/oracle-jdbc-drivers
However the error persisted.
(Failed) Approach #2
I'm currently looking to use the jvmArgs to point to a local version of the jar.
grails.tomcat.jvmArgs = ["-cp:/somelocalpath/oracle-jdbc-drivers/ojdbc6.jar"]
However a run-war results in:
| Error Server failed to start: tomcat exited prematurely with code '1' (error output: 'Unrecognized option: -cp:/apps/glassfish3/oracle-jdbc-drivers/ojdbc6.jar
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
')
I should clarify my main focus - I do not want the jar to be included in the final war.
Any help would be appreciated. Thanks!
From the documentation:
grails.war.resources lets you do any extra processing you want
before the WAR file is finally created.
In your case, you need to add something like that to your build config to exclude the Jar of the final WAR.
grails.war.resources = { stagingDir ->
delete(file:"${ stagingDir }/WEB-INF/lib/yourJarFile.jar")
}

Resources