I have a desktop Java application that I'm developing that has an embedded Apache Derby database (Link) . Now, when I run the application through my IDE, everything works great and functions as expected. However when I create the fat jar (including all the dependencies), when I launch the application it boots fine, but I get the following error message:
java.sql.SQLSyntaxErrorException: Schema 'TDB' does not exist
To me, this suggests that the schema I have created has not been copied across into my new jar file, but in that case I'm not sure if I'm creating my jar correctly.
What I would like it to do is when I run the package goal of my pom, it will create a new jar, with all of the dependencies included, that I could effectively give to someone else and they could run it as a fully functional desktop application (in the same way I can run it through my IDE, just without the IDE).
Any help would be massively appreciated, I've been banging my head against this one for a few days now.
Stu
The way I see it there are two approaches to this:
You determine the file system location of your database files and make sure it is included in your deployment - this should be do-able from within the IDE
You include a start-up process that check if the database is present, and if not creates the schema on the fly
Related
I've created a java program and I'm wanting to run it from the iSeries. I've been able to get it to run from the QSH so I know it compiled and runs fine, but I need to run it from the command line not QSH. The program requires the jsch-0.1.55.jar file for the program to work correctly and I'm not 100% sure how to to call the jar file with the program its referencing to.
I've tried
RUNJVA CLASS(ANL0106J) CLASSPATH('/JAVA/Jars/jsch-0.1.55.jar')
That didn't work. Then I tried
RUNJVA CLASS('/JAVA/Jars.jsch-0.1.55.jar':. ANL0106J) CLASSPATH('/Java/Jars/jsch-0.1.55.jar')
That didn't work either. What am I doing wrong?
Having successfully done this many many times, your last try seems pretty close, but change the CLASS parameter to point to your class file which contains the main method. ANL0106J seems like a pretty weird class name.. Example would be:
CLASS(com.company.test.ApplicationMain)
With the CLASSPATH pointing to the required jars using the full path names. For example:
RUNJVA CLASS(com.company.test.ApplicationMain) CLASSPATH('/test/app.jar:/test/dependency.jar')
To make matters a bit easier, you could even include your dependency in your JAR file by using something like maven or Gradle to create your builds, which can then be configured to generate fat jars. Essentially, those are jars that contain the other JAR files that your application depends on. That way, you can also be pretty sure that your application will continue to work, even after you update a single jar file on your ibm i machine for example. Shadowjar for example is pretty easy to setup using a gradle project which will do this for you. Then it's just a matter of running the bootjar gradle task and using the RUNJVA command, simply pointing to your single JAR. Don't get caught up in dependency management hell, please. Save yourself and future devs by using something like maven or gradle. Gradle/maven can even be used to manage depencencies using a maven repository with a tool such as Sonatype Nexus which can also be hosted locally. If your JAR has a valid manifest, you don't have to do anything else. It would look like this:
RUNJVA CLASS('/test/app.jar')
Especially useful for using CI, which can build the JAR for you from a GIT repository and place the fat jar in the correct path, with you not having to do a single thing. Setting up Jenkins on an as400 isn't that difficult at all using the apache WebSphere application server which is an option that can be used to host WAR files, to put it simply (it can do a lot more than that though :P).
Hell, using only a single jar for the RUNJVA command should also speed up the time it takes to start your application since it only needs to verify a single jar. Just food for thought. Here's the maven entry by the way:
https://mvnrepository.com/artifact/com.jcraft/jsch/0.1.55
On a side note for java/react devs: Yes, fellow Java/react developers, one could use the RUNJVA command to modernize ibm i development to run Spring boot applications! We are successfully running react front end applications using a spring boot backend system, Works extremely fast, as expected :)
(Same answer given to you on Reddit, simply on this platform to make it visible for others that are looking for this on Stackoverflow)
I have created a simple springboot application with inbuild tomcat which works fine when I am running it as JAVA Application in Eclipse. I tried to export this as a WAR file and tried to run it in Windows command line and also in UNIX box. I tried to execute it like below,
java -jar C:\Users\Iam\Documents\SpringHelloWorld.war main.java.com.controller.SpringBootWebApplication
Error: An unexpected error occurred while trying to open file C:\Users\Iam\Documents\SpringHelloWorld.war
java -cp C:\Users\Iam\Documents\SpringHelloWorld.war main.java.com.controller.SpringBootWebApplication
Error: Could not find or load main class main.java.com.controller.SpringBootWebApplication
I just export it as a WAR file, should i need to define anything before exporting it as WAR in Springboot ( note: i am not using maven or gradle )
Below is my project structure :
enter image description here
Probably it is possible to do this without Maven/Gradle, but I would never take this approach.
Even considering the best case, you will end up re-creating what others have created in the Spring Boot parento pom.xml or in his Gradle equivalent, so why you would waste a lot of time recreating what is already created by someone else? If you really want to know how the war is created, then take a look in Spring Boot parent pom, but you should limit your work to wrap what is ready for production in order to compose your solution.
Also consider that Maven and Gradle are constantly developed and updated, along everything belongs to their ecosystems. If you plan to replace them, then you should be prepared to mantain and develop alone your own build platform, which is a non-trivial effort.
Better include Maven or Gradle, you'll be more productive.
I created a java application that uses an embedded derby database in netbeans. I managed to package the application as an exe installer so as to install on other systems. The problem is that when I install on other systems, the application tries to locate the database using the original url (which is on the computer I used in development). How can I solve the problem of packaging so that the database is packaged along with all the required classes of the application?
Well I believe I may have found a way around my problem. I ended up compressing the database folder into a jar file and adding it to the project library of my application. When the application is packaged and installed on another system, I put in a code that creates a directory inside the application folder and another code to extract the contents of the jar file (the database) and place them in the newly created directory.
Only problem I am facing now is what I believe to be a permissions problem because while I am able to create the folder to place the extracted database in, the code to extract the database jar file seems not to be working.
i have a java application which uses netbeans' Java DB/Derby.
i have "clean and build" the project creating a jar file, but it'll only run if i explicitly run netbeans and start database there.
how can i set the DB to start up automatically along with jar file and also, that if i sent that jar file to someone else, that database goes along with that(i have read it's possible to do that with derby. not sure though)
any help is appreciated
you need to include sql resources and create the database with these on running the project for the first time . This is a cumbersome process and platform depending ...
there are solutions available that allow for creation of a dictionary in a java project , hence making this platform independ. SAP NetWeaver has this but I'm sure there are others ..
I couldn't find any info in google on this one, someone changed properties on a project and I'm not sure why the project can no longer deploy to jar. It compiles ok, but won't build into a jar file even though the dependencies do so just fine.
Has anyone run into this issue in JDeveloper before?
I can rename the jar to a different name (it's a dependency as well) but I need that specific name to match up with the other project.
I'm working with JDeveloper 10g and the project has been building fine for the last few months, and just now I'm getting this error which I can find no source or help on.
I've fixed it, it plagued me for 3 days.
The project itself had some deploy profile stuck in it, directly in the properties file of the project, not the external "blah blah.deploy".
When looking under the "Miscellaneous Files" area I noticed an extra deploy file, i.e. two deploy files in that area even though I hadn't deployed yet. This is how I figured out it was stuck in the project properties not in the external files. Removing one of these from the project fixed the issue, although I imagine ridding the project of both and creating a new deploy profile (still need to do this) would also fix it.
10g for the lose :p