This question already has answers here:
generate java google endpoints server stub from swagger API
(2 answers)
Closed 3 years ago.
Does it exist any code generator that from .json will convert the file into an Api rest in Java ?
I'm aware that exist some framwork to generate the .json, such as io.swagger, io.springfox, com.mangofactory etc., but i wasn't able to find anything about the opposite process.
You can try this: https://swagger.io/tools/swagger-codegen/, not sure if it works for your use case but worked for me for similar use case
Please try OpenAPI Generator (free, open-source), which supports both OpenAPI spec v2, v3.
To use it, simply download the JAR or use Docker images, maven plug-in or gradle plug-in. The Getting Started section is a good starting point.
If you've Docker installed, please try:
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
-g java \
-o /local/out/java
Related
I would like to run a piece of Java code in AWS Lambda that calls a shell command (in my case wkhtmltopdf). I can't seem to figure out how to package the Lambda for this to work:
Cannot run program "wkhtmltopdf": error=2, No such file or directory: java.io.IOException
I've been able to make it work with Node.js. I guess this is due to the "package" being extracted once uploaded whereas with Java the jar stays compressed and thus the executable isn't accessible from java.lang.ProcessBuilder.
I was able to solve this using AWS Lambda Layers. Packagin bin/wkhtmltopdf into a zip file and creating a layer using something along the lines:
aws lambda publish-layer-version --layer-name wkhtmltopdf \
--description "wkhtmltopdf executable" \
--zip-file fileb://$(pwd)/wkhtmltopdf.zip \
--compatible-runtimes java8
After that I was able to select and apply the layer (remember to press save).
While generating the server stub, in my case spring type, I can specify the packages for api, model and invoker. And it works without problems.
I need also change the package for generated supporting files. I'm not able to find the way how to do that. The default package is io.swagger.configuration which needs to be changed in my case.
The Swagger-Codegen support the option when generate code. The detail you can check the official wiki section customizing-the-generator
Let me make an example by using generation to jersey2
java -jar ${your_swagger_codegen_jar} generate \
-i ${your_api_url} \
-l java --library=jersey2 \
-o ${your_output_folder} \
-c ./config.json
The config.json
{
"hideGenerationTimestamp":true,
"groupId":"science.mengxin",
"artifactId":"test-api-client",
"artifactDescription":"test-api-client",
"developerName":"xin.meng",
"developerEmail":"test#test.com",
"developerOrganization":"mengxin",
"developerOrganizationUrl":"mengxin.science",
"licenseName":"mengxin.science",
"invokerPackage":"science.mengxin.test.cloud.client",
"apiPackage":"science.mengxin.test.cloud.client.api",
"modelPackage":"science.mengxin.test.cloud.client.model"
}
Then check pom.xml and source code of generated code, you will find all these parameters has been customised.
The more options to customise the generated code can be found in the swagger-codegen book: English, Chinese
This question already has an answer here:
how to make makefile for java with external jar file
(1 answer)
Closed 8 years ago.
I want to write a Makefile that compiles and runs the following code. My question here is how to add an external library using Make syntax?
javac -cp commons-cli-1.2.jar Iperfer.java
java -cp .:commons-cli-1.2.jar Iperfer -c -h localhost -p 1234 -t 12
My question here is how to add an external library using Make syntax?
The Answer is in the question. You would use the same command as you would from the command line ...
This is really a Java agnostic question. It is really about how to write a Makefile. But presumably if your teachers want you to use make to build Java, they will have provided you with a sample / template Makefile to get you started. If you showed us that template, we could tell you how best to modify it.
But assuming that you don't have a specific template in mind, then this a duplicate of an existing Question.
This question already has answers here:
How to create windows service from java jar?
(7 answers)
Closed 10 years ago.
I have a JAR file and I would like to register and run it as a Windows service. With a well-configured JAR and already registered JVM shutdown hooks it should not be a big work to do this.
I already have a JAR with external lib dir, I can start it with java -jar My.jar and stop with Ctrl+C.
I also checked JSL, JSmooth, and procrun from Apache with no working solution.
I would need a working solution with a good tutorial.
Update: I succeeded with both procrun (at last), and the manual .net service wrapper too... Here is the code for the procrun version of my install.bat:
set PR_PATH=%CD%
SET PR_SERVICE_NAME=MyService
SET PR_JAR=MyService.jar
SET START_CLASS=org.my.Main
SET START_METHOD=main
SET STOP_CLASS=java.lang.System
SET STOP_METHOD=exit
rem ; separated values
SET STOP_PARAMS=0
rem ; separated values
SET JVM_OPTIONS=-Dapp.home=%PR_PATH%
prunsrv.exe //IS//%PR_SERVICE_NAME% --Install="%PR_PATH%\prunsrv.exe" --Jvm=auto --Startup=auto --StartMode=jvm --StartClass=%START_CLASS% --StartMethod=%START_METHOD% --StopMode=jvm --StopClass=%STOP_CLASS% --StopMethod=%STOP_METHOD% ++StopParams=%STOP_PARAMS% --Classpath="%PR_PATH%\%PR_JAR%" --DisplayName="%PR_SERVICE_NAME%" ++JvmOptions=%JVM_OPTIONS%
I presume to
run this from the same directory where the jar and prunsrv.exe is
the jar has its working MANIFEST.MF
and you have shutdown hooks registered into JVM (for example with context.registerShutdownHook() in Spring)...
not using relative paths for files outside the jar (for example log4j should be used with log4j.appender.X.File=${app.home}/logs/my.log or something alike)
Thanks to the apache procrun team (http://commons.apache.org/proper/commons-daemon//procrun.html) and to marifnst (http://a089lp.wordpress.com/tag/procrun-tutorial/)
Update 2: a new good tutorial with winsv: https://dzone.com/articles/spring-boot-as-a-windows-service-in-5-minutes
Try this java launcher
http://winrun4j.sourceforge.net/
free and open source
start service example at the end of the page
Write your own service from these samples:
http://www.codeproject.com/Articles/3990/Simple-Windows-Service-Sample
http://msdn.microsoft.com/en-us/library/windows/desktop/bb540476%28v=vs.85%29.aspx?bcsi-ac-bbaf765720ef3335=20190C4200000503o7MxKbMq7UL6Af4O24rqKSGuh1gPAwAAAwUAAPvrLQAIBwAAbwEAAGhCCQA=
http://code.msdn.microsoft.com/windowsdesktop/CppWindowsService-cacf4948?bcsi-ac-bbaf765720ef3335=20190C4200000503o7MxKbMq7UL6Af4O24rqKSGuh1gPAwAAAwUAAPvrLQAIBwAAbwEAAGhCCQA=
Into onStart you have to do CreateProcess( "java", "-jar", "MyJar.jar" ), keep its PID
Into onStop you have to kill by the PID
You can use Java Service Wrapper
http://wrapper.tanukisoftware.com/doc/english/download.jsp
They not to distribute compiled x86_64 windows version of Comunity Edition but you can build it by yourself.
I use a shared repository partly containing Java and Python code. The code basis mainly stands on python, but some libraries are written in Java.
Is there a possibility to parse or preprocess Java documentation in order to use
it later in Python-Sphinx or even a plugin?
javasphinx (Github) (Documentation)
It took me way to long to find all the important details to set this up, so here's a brief for all my trouble.
Installation
# Recommend working in virtual environments with latest pip:
mkdir docs; cd docs
python3 -m venv env
source ./env/bin/activate
pip install --upgrade pip
# Recommend installing from source:
pip install git+https://github.com/bronto/javasphinx.git
The pypi version seemed to have broken imports, these issues did not seem to exist in the latest checkout.
Setup & Configuration
Assuming you've got a working sphinx setup already:
Important: add the java "domain" to sphinx, this is embedded in the javasphinx package and does not follow the common .ext. extension-namespace format. (This is the detail I missed for hours):
# docs/sources/conf.py
extensions = ['javasphinx']
Optional: If you want external javadoc linking:
# docs/sources/conf.py
javadoc_url_map = {
'<namespace_here>' : ('<base_url_here>', 'javadoc'),
}
Generating Documentation
The javasphinx package adds the shell tool javasphinx-apidoc, if your current environment is active you can call it as just javasphinx-apidoc, or use its full path: ./env/bin/javasphinx-apidoc:
$ javasphinx-apidoc -o docs/source/ --title='<name_here>' ../path/to/java_dirtoscan
This tool takes arguments nearly identical to sphinx-apidoc:
$ javasphinx-apidoc --help
Usage: javasphinx-apidoc [options] -o <output_path> <input_path> [exclude_paths, ...]
Options:
-h, --help show this help message and exit
-o DESTDIR, --output-dir=DESTDIR
Directory to place all output
-f, --force Overwrite all files
-c CACHE_DIR, --cache-dir=CACHE_DIR
Directory to stored cachable output
-u, --update Overwrite new and changed files
-T, --no-toc Don't create a table of contents file
-t TOC_TITLE, --title=TOC_TITLE
Title to use on table of contents
--no-member-headers Don't generate headers for class members
-s SUFFIX, --suffix=SUFFIX
file suffix (default: rst)
-I INCLUDES, --include=INCLUDES
Additional input paths to scan
-p PARSER_LIB, --parser=PARSER_LIB
Beautiful Soup---html parser library option.
-v, --verbose verbose output
Include Generated Docs in Index
In the output directory of the javasphinx-apidoc command there will have been a packages.rst table-of-contents file generated, you will likely want to include this into your index.html's table of contents like:
#docs/sources/index.rst
Contents:
.. toctree::
:maxdepth: 2
packages
Compile Documentation (html)
With either your python environment active or your path modified:
$ cd docs
$ make html
or
$ PATH=$PATH:./env/bin/ make html
The javadoc command allows you to write and use your own doclet classes to generate documentation in whatever form you choose. The output doesn't need to be directly human-readable ... so there's nothing stopping you outputting in a Sphinx compatible format.
However, I couldn't find any existing doclet that does this specific job.
References:
Oracle's Doclet Overview
UPDATE
The javasphinx extension may be a better alternative. It allows you to generate Sphinx documentation from javadoc comments embedded in Java source code.
Sphinx does not provide a built-in way to parse JavaDoc, and I do not know of any 3rd party extension for this task.
You'll likely have to write your own documenter for the Sphinx autodoc extension. There are different approaches you may follow:
Parse JavaDoc manually. I do not think that there is a JavaDoc pParser for Python, though.
Use Doxygen to parse JavaDoc into XML, and parse that XML. The Sphinx extension breathe does this, though for C++.
Write a Doclet for Java to turn JavaDoc into whatever output format you can hande, and parse this output.