I made a maven spring-boot project using Spring Initializr and added the basic dependencies like starter-web, tom-cat-jasper, dev-tools and etc.. then imported it in Eclipse.
I then added a new external JAR in my local repository that is not from maven repository using
mvn install:install-file
and added the new dependendcy in the pom.xml
<dependency>
<groupId>com.domain.project</groupId>
<artifactId>resourceName</artifactId>
<version>1</version>
</dependency>
And this external JAR has a .properties that's need to be added in order for it to connect to a database. I put this .properties file in src/main/resources and tested the methods in the external JAR and it works as intended in the Eclipse IDE.
After this I run the project as Maven build with goals: clean install so that it can be run as an executable JAR.
Then I run the JAR with start java -jar using a .bat file everything is working but whenever I used the methods from the external JAR via GET/POST request it gives the error:
java.util.MissingResourceException: Can't find bundle for base name resourceName, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1581) ~[?:1.8.0_241]
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1396) ~[?:1.8.0_241]
at java.util.ResourceBundle.getBundle(ResourceBundle.java:782) ~[?:1.8.0_241]
at com.domain.project.vitality.VitalityInfo.VitalityInfoDetails(VitalityInfo.java:28) ~[resourceName-1.jar!/:?]
This is the name of the external JAR: resourceName.jar and the required properties file: resourceName.properties.
I also encountered this error if I rename or removed the required .properties file in src/main/resources in Eclipse IDE.
If I run the project only in Eclipse IDE and access the said external JAR methods via GET/POST request it gives the usual JDBC SQL error.
How do I fix this whenver I build using maven any help is very much appreciated?
EDIT: This is the result from jar tf of executable JAR when using maven build.
BOOT-INF/classes/application.properties
BOOT-INF/classes/resourceName.properties
BOOT-INF/classes/log4j2-spring.xml
EDIT: Issue is resolved.
Turns out the solution was rather simple.
In my case the external JAR has this in its implementation
ResourceBundle bundle = ResourceBundle.getBundle("resourceName");
I changed this into
ResourceBundle bundle = ResourceBundle.getBundle("application");
And simply renamed resourceName.properties file into application.properties or just copy the content from resourceName.properties into your application.properties or any property file that spring-boot is able to read.
Related
I try load htmlunit jar files to micronaut project , set class path correctly but IntelliJ can not resolve the classes ,
However I can import the same jar files successfully to grails 4 project
Note : I use amazon corretto version 11
There is not enough information in the question to know for sure what is wrong. One possibility is that the dependency has been added in your build file (maven or gradle) and the IDE is out of date and not sync'd with what is in the build file.
Can we load any external jar file to micronaut project
Yes. In fact, there is no such thing as a Micronaut project that does not do that.
I try load htmlunit jar files to micronaut project , set class path
correctly but IntelliJ can not resolve the classes
If the CLASSPATH is set correctly, then IntelliJ will be able to resolve the classes. If IntelliJ can't, I think that means the CLASSPATH is not setup correctly.
I want to run a liquibase update by the liquibase-maven-plugin, but the changeset yml file is inside a .jar that I pull in by dependency.
When I open the .jar with TotalCommander, it has the following structure:
xy.jar/changelog/changeset.yml.
I tried including it as a resource directory, but it failed telling me the .jar is not a directory.
I also tried building to a WAR and just setting the liquibase changeLogFile property to the path leading to the .jar, like {projectDir}/target/..war/..lib/..jar/changelog/myFile.yml
But maven could not find it this way.
Is it possible to access this file somehow?
You can read the file using below code.
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("changelog/myFile.yml");
Thanks for the reply, but the solution was simpler, I'm just rusty in this area :) I simply had to add the required JAR from the WAR as a Maven Dependency. This adds the JAR's content to the classpath in the Maven build process, so I can reference to it's files as they were on the project root path.
TLDR: add JAR as dependency in the pom and use the path:
<changeLogFile>changelog/xy.jar</changeLogFile>
I created a spring boot job which relies on properties on the server and I can get it to run like so, no modifying manifest.
/bin/java -Dspring.config.location=/var/tmp/com.jdbc.properties -jar my.jar
and it works. But the application relies upon another jar that is an internal jar that lives under /usr/local/share/jni/foo.jar which I want to add to this mix.
I have tried countless runs trying such things as:
java -cp /usr/local/share/jni/foo.jar -Dspring(picking up original line)
When I start to google this, it takes me on magical tours of running:
'org.springframework.boot.loader.JarLauncher'
or
'org.springframework.boot.loader.PropertiesLauncher'
then mucking with manifest etc.
Spent last 4 hours with no success. Is there a best practice to run a standalone jar that needs to consume remote properties file and an additional jar file? Would like to keep it simple if possible.
If you are using Spring Boot and want to have a Fat-jar that encapsulates all your dependencies, the best way is to add the required Jar as a dependency to your project.
Assuming you are using Maven to build your project, the "foo.jar" needs to be added as a Maven dependency to your project. Then, spring Boot maven plugin will pick up the jar and includes it in your Fat-jar.
Even if the "foo.jar" does not exist in any Maven repo, you still can add it manually to your local Maven repo using the Maven command mvn install:install-file (See Maven doc).
Did you try using foo.jar as a provided dependency within your maven/gradle dependencies and building the project as executable war file?
See spring boot's maven plugin description of building executable war files.
Overall. Run spring boot standalone jar on a Linux server. Additionally read the database properties from a static file on the server, and path in a jar file that adds functionality that only lives on the server. Cannot include in the boot lib.
command line run (will convert to shell) and ran.
/path/to/..openjdk-1.7.0.55.x86_64/bin/java -cp /usr/somewhere/jni/Foo.jar:/path/where/lib/MYBOOTJAR.jar org.springframework.boot.loader.JarLauncher --spring.config.location=/path/to/properties/on/server/com.xxx.yyy.zzz.jdbc.properties
Seems like using the JarLauncher (no modifications to manifest, except excluding the Foo.jar from local)
Hope this helps someone else.
I have a maven based project where I have to invoke an external jar (say country.jar)
I added this jar on src/lib folder and did below setting in pom.xml
<dependency>
<groupId>country-stubs</groupId>
<artifactId>country-stubs</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\country.jar</systemPath>
</dependency>
While Running my application I am getting error
java.lang.NoClassDefFoundError: com/fsg/bpo/webservices/countWebService
Location(com/fsg/bpo/webservices/countWebService) is referring to the class present under country JAR
Do I need to add few more settings to configure external JAR in maven ?
If you are using scope system you are saying it is a provided jar later on. I would use runtime maybe. Have a look at maven scopes
If it is web application then your jar won't get bundled inside your war file. Then you will get this issue. you can directly copy this country.jar to your WEB-INF lib folder and use that system path.
1st u need to add ur external jar to ur local maven directory..
using below command on cmd..
mvn install:install-file -DgroupId= -DartifactId=aes-decryption -Dversion=1.0.0 -Dpackaging=jar -Dfile=./target/aes-decryption-1.0.0.jar -DgeneratePom=true
I'm trying to build web Service using maven and eclipse. Here is steps I followed.
Generated mvn folder struture using comman prompt
mvn archetype:generate - DarchetypeArtifactId=maven-archetype-webapp
Converted the mvn project into eclipse.
mvn eclipse:eclipse -Dwtpversion=2.0
Imported the project into my workspace.
Changed the project facets such as java version, servlet version, added cxf and jaxb feature and server runtime.
Copied the WSDL to Resources folder.
Since I do not want to add dependencies(as somebody else would be doing this job for me). I added spring and CXF lib into build path. and also to deployment assembly.
Generated the jaxb classes and operations from wsdl. Here all the java classes created instead of going to src/main/java to went to src/main/resources.
I run the app on tomcat. web.xml is invoked from that cxf framework got invoked and also spring bean creation got invoked. but while creating the bean for the webservice class it threw Class not found error.
When I opened up the war I could notice that while packaging instead of placeing the class files, the eclipse placed java file as it is in the war file.
Could some one help me in fixing this problem. Not sure how to configure eclipse to compile and place .class files in the war instead of .java filee.
Figured out the problem, while importing the file eclipse is adding command, exclude all the java files from src/main/resources in srource tab of java build path On removing it worked fine