cannot generate classes with JAXB - jaxb

i try to generate classes using JAXB but I a get an exception :
IllegalArgumentException: Illegal pattern character 'g'
I'using a complex XSD file and a binding file as below.
Can somebody give a clue to where investigate ?
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="IFX170_XSD.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="cy.com.netinfo.netteller.ifx"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="RemitDetail_Type.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="cy.com.netinfo.netteller.ifx.remitdetailinfo"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="$pain.001.001.01.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="cy.com.netinfo.netteller.ifx.swift.pain_001_001_1"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="$pain.002.001.01.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="cy.com.netinfo.netteller.ifx.swift.pain_002_001_1"/>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="$pain.004.001.01.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="cy.com.netinfo.netteller.ifx.swift.pain_004_001_1"/>
</jxb:schemaBindings>
</jxb:bindings>

At last I found the answer.
The problem is due to a mistake in the class Options in the package com.sun.tools.xjc.
In the method getPrologComment the class builds a localized message taking parameter fot date and time from a localized resource bundle, but then formats the date using a fixed Locale.ENGLISH. This behavior is inside JAXB 2.2.6.
I solved the problem simply updating the file MessageBundle_it.properties (in my case for italian) in the package com\sun\tools\xjc\ of the jar file jaxb-xjc.jar.
The changes I made was :
Driver.DateFormat = aaaa.MM.gg (original) to Driver.DateFormat = yyyy/MM/dd (new) and
Driver.TimeFormat = hh:mm:ss a z (original) to Driver.TimeFormat = HH:mm:ss (new)
With those changes I was able to generate the classes as needed.
HTH
Flavio

I have same error generating java objects form command line xjc.bat. You can solve adding option -no-header

I might guess that one of your xsd files have a regexp-based restriction attached to a type/element. Have you validated those files?

Related

FileProvider.getUriForFile() crashing app? [duplicate]

I'm trying to take a picture with camera, but I'm getting the following error:
FATAL EXCEPTION: main
Process: com.example.marek.myapplication, PID: 6747
java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/com.example.marek.myapplication/files/Pictures/JPEG_20170228_175633_470124220.jpg
at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:711)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:400)
at com.example.marek.myapplication.MainActivity.dispatchTakePictureIntent(MainActivity.java:56)
at com.example.marek.myapplication.MainActivity.access$100(MainActivity.java:22)
at com.example.marek.myapplication.MainActivity$1.onClick(MainActivity.java:35)
AndroidManifest.xml:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.marek.myapplication.fileprovider"
android:enabled="true"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
Java:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
Toast.makeText(getApplicationContext(), "Error while saving picture.", Toast.LENGTH_LONG).show();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.marek.myapplication.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="my_images" path="images/"/>
</paths>
I was searching whole day about this error and trying to understand FileProvider, but I have no idea what this error message tries to tell me. If you want more info/code, write me in the comment.
Your file is stored under getExternalFilesDir(). That maps to <external-files-path>, not <files-path>. Also, your file path does not contain images/ in it, so the path attribute in your XML is invalid.
Replace res/xml/file_paths.xml with:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="my_images" path="/" />
</paths>
UPDATE 2020 MAR 13
Provider path for a specific path as followings:
<files-path/> --> Context.getFilesDir()
<cache-path/> --> Context.getCacheDir()
<external-path/> --> Environment.getExternalStorageDirectory()
<external-files-path/> --> Context.getExternalFilesDir(String)
<external-cache-path/> --> Context.getExternalCacheDir()
<external-media-path/> --> Context.getExternalMediaDirs()
Ref: https://developer.android.com/reference/androidx/core/content/FileProvider
This may resolve everyones problem:
All tags are added so you don't need to worry about folders path.
Replace res/xml/file_paths.xml with:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
EDIT: 1st June 2021
We should use only specific path which we need.
Try alternate path on your own and use which you needed.
See Accepted answer for more information: https://stackoverflow.com/a/42516202/4498813
Got similar problem after enabled flavors (dev, stage).
Before flavors my path resource looked like this:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="my_images"
path="Android/data/pl.myapp/files/Pictures" />
</paths>
After added android:authorities="${applicationId}.fileprovider"
in Manifest appId was pl.myapp.dev or pl.myapp.stage depends on flavor and app started crashing.
I removed full path and replaced it with dot and everything started working.
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="my_images"
path="." />
</paths>
I am sure I am late to the party but below worked for me.
<paths>
<root-path name="root" path="." />
</paths>
If you are using internal cache then use.
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<cache-path name="cache" path="/" />
</paths>
Lost 2 weeks trying to find some solution... If you arrive here after try everthing above:
1 - Verify if your tag provider are inside tag application
<application>
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.companyname.Pocidadao.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths"></meta-data>
</provider>
</application>
2 - If you try a lot paths way without success, then test with this:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="cache" path="." />
<external-path name="external" path="." />
<root-path name="root" path="." />
<files-path name="my_images" path="/" />
<files-path name="my_images" path="myfile/"/>
<files-path name="files" path="." />
<external-path name="external_files" path="." />
<external-path name="images" path="Pictures" />
<external-path name="my_images" path="." />
<external-path name="my_images" path="Android/data/com.companyname.yourproject/files/Pictures" />
<external-path name="my_images" path="Android/data/com.companyname.yourproject/files/Pictures/" />
<external-files-path name="images" path="Pictures"/>
<external-files-path name="camera_image" path="Pictures/"/>
<external-files-path name="external_files" path="." />
<external-files-path name="my_images" path="my_images" />
<external-cache-path name="external_cache" path="." />
</paths>
Test this, if camera works, then start eliminate some lines and continue testing...
3 - No forget verify if camera are actived in your emulator.
Be aware that external-path is not pointing to your secondary storage, aka "removable storage" (despite the name "external"). If you're getting "Failed to find configured root" you may add this line to your XML file.
<root-path name="root" path="." />
See more details here FileProvider and secondary external storage
This confusing me a bit too.
The problem is on "path" attribute in your xml file.
From this document FileProvider
'path' is a subdirectory,
but in another document (camera/photobasics) shown
'path' is full path.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="Android/data/com.example.package.name/files/Pictures" />
</paths>
I just change this 'path' to full path and it just work.
I would be late but I found a solution for it.Working fine for me, I just changed the paths XML file to:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<root-path name="root" path="." />
</paths>
Check how many storages your device offers - sharing files from secondary storage is not supported. Look at FileProvider.java source (from support-core-utils 25.3.1):
} else if (TAG_EXTERNAL_FILES.equals(tag)) {
File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null);
if (externalFilesDirs.length > 0) {
target = externalFilesDirs[0];
}
} else if (TAG_EXTERNAL_CACHE.equals(tag)) {
File[] externalCacheDirs = ContextCompat.getExternalCacheDirs(context);
if (externalCacheDirs.length > 0) {
target = externalCacheDirs[0];
}
}
So, they take only the first storage.
Also, you can see that getExternalCacheDirs() is used to obtain list of storages through the ContextCompat interface. See documentation for its limits (it's told to not recognize USB Flashes for example). Best is to make some debug output of list of storages from this API on your own, so that you can check that path to storage matches the path passed to getUriForFile().
There's already a ticket assigned (as for 06-2017) in Google's issue tracker, asking to support more than one storage. Eventually, I found SO question on this as well.
I have spent 5 hours for this..
I have tried all the methods above but it depends on the what storeage your app currently using.
https://developer.android.com/reference/android/support/v4/content/FileProvider#GetUri
Check the documentation before trying the codes.
In my case
since files-path sub directory will be Context.getFilesDir().
The funky thing is it Context.getFilesDir() notes one another subdirectory.
what I am looking for is
data/user/0/com.psh.mTest/app_imageDir/20181202101432629.png
Context.getFilesDir()
returns
/data/user/0/com.psh.mTest/files
so the tag should be
....files-path name="app_imageDir" path="../app_imageDir/" ......
Then it works!!
None of this worked for me. The only approach that works is not to declare an explicit path in xml. So do this and be happy:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="." />
</paths>
Here too has a excelent tutorial about this question:
https://www.youtube.com/watch?v=9ZxRTKvtfnY&t=613s
My issue was that I had overlapping names in the file paths for different types, like this:
<cache-path
name="cached_files"
path="." />
<external-cache-path
name="cached_files"
path="." />
After I changed the names ("cached_files") to be unique, I got rid of the error. My guess is that those paths are stored in some HashMap or something which does not allow duplicates.
This Worked for me as well.Instead of giving full path i gave path="Pictures" and it worked fine.
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path
name="images"
path="Pictures">
</external-files-path>
</paths>
What I did to solve this -
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.mydomain.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/filepaths"/>
</provider>
filepaths.xml (Allowing the FileProvider to share all the files that are inside the app's external files directory)
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="files"
path="/" />
</paths>
and in java class -
Uri fileProvider = FileProvider.getUriForFile(getContext(),"com.mydomain.fileprovider",newFile);
It depends what kind of storage you want to do, INTERNAL or EXTERNAL
for EXTERNAL STORAGE
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="my_images" path="my_images" />
</paths>
but for INTERNAL STORAGE, be careful with the path, because it uses getFilesDir() method
which mean that your file will be located in the root directory for the app ("/")
File storeDir = getFilesDir(); // path "/"
So your provider file must be like this:
<paths>
<files-path name="my_images" path="/" />
</paths>
Change your main/res/xml/provider_paths.xml
From
<paths>
<files-path path="images/" name="myimages" />
<external-path name="download" path="download/"/>
</paths>
To
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
I had the same problem, I tried the below code for its working.
1.Create Xmlfile : provider_paths
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path name="my_images" path="myfile/"/>
</paths>
2. Mainfest file
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.ril.learnet.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
3.In your Java file.
File file = new File(getActivity().getFilesDir(), "myfile");
if (!file.exists()) {
file.mkdirs();
}
String destPath = file.getPath() + File.separator + attachmentsListBean.getFileName();
file mfile = new File(destPath);
Uri path;
Intent intent = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
path = FileProvider.getUriForFile(AppController.getInstance().getApplicationContext(), AppController.getInstance().getApplicationContext().getPackageName() + ".provider", mfile );
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
path = Uri.fromFile(mfile);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(path, "image/*");
getActivity().startActivity(intent);
none of the above worked for me,
after a few hours debugging I found out that the problem is in createImageFile(), specifically absolute path vs relative path
I assume that you guys are using the official Android guide for taking photo. https://developer.android.com/training/camera/photobasics
private static File createImageFile(Context context) throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
Take note of the storageDir, this is the location where the file will be created. So in order to get the absolute path of this file, I simply use image.getAbsolutePath(), this path will be used in onActivityResult if you need the Bitmap image after taking photo
below is the file_path.xml, simply use . so that it uses the absolute path
<paths>
<external-path
name="my_images"
path="." />
</paths>
and if you need the bitmap after taking photo
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bmp = null;
try {
bmp = BitmapFactory.decodeFile(mCurrentPhotoPath);
} catch (Exception e) {
e.printStackTrace();
}
}
If nothing helps and you are getting the error
failed to find configured root that contains /data/data/...
then try changing some line like:
File directory = thisActivity.getDir("images", Context.MODE_PRIVATE);
to:
File directory = new File(thisActivity.getFilesDir(), "images");
and in the xml file:
<files-path name="files" path="." />
which is weird, since the folder I access is /images.
The problem might not just be the path xml.
Following is my fix:
Looking into the root course in android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile():
public File getFileForUri(Uri uri) {
String path = uri.getEncodedPath();
final int splitIndex = path.indexOf('/', 1);
final String tag = Uri.decode(path.substring(1, splitIndex));
path = Uri.decode(path.substring(splitIndex + 1));
final File root = mRoots.get(tag); // mRoots is parsed from path xml
if (root == null) {
throw new IllegalArgumentException("Unable to find configured root for " + uri);
}
// ...
}
This means mRoots should contains the tag of requested uri. So I write some code to print mRoots and tag of uri, and then easily find the tags do not match.
It comes out that setting provider authority as ${applicationID}.provider is a stupid idea! This authority is so common that might be used by other providers, which will mess up the path config!
I was getting this error Failed to find configured root that contains...
The following work around resolves my issue
res/xml/file_paths.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="media" path="." />
</paths>
AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="[PACKAGE_NAME]"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths">
</meta-data>
</provider>
ActivityClass.java
void shareImage() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this,"com.slappstudio.pencilsketchphotomaker", selectedFilePath));
startActivity(Intent.createChooser(intent,getString(R.string.string_share_with)));
}
Android official document says file_paths.xml should have:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images"
path="Android/data/com.example.package.name/files/Pictures" />
</paths>
But to make it work in the latest android there should be a "/" at the end of the path, like this:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images"
path="Android/data/com.example.package.name/files/Pictures/" />
</paths>
The following change in xml file_paths file worked for me.
<external-files-path name="my_images" path="Pictures"/>
<external-files-path name="my_movies" path="Movies"/>
My Problem Was Wrong File Name:
I Create file_paths.xml under res/xml while resource was set to provider_paths.xml in Manifest:
<provider
android:authorities="ir.aghigh.radio.fileprovider"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
I changed provider_paths to file_paths and problem Solved.
If your file path is like /storage/emulated/0/"yourfile"
you just need modify your FileProvider xml
<paths>
<external-path name="external" path="." />
</paths>
then call this function when you need share file
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri fileUri = FileProvider.getUriForFile(getContext(),
"com.example.myapp.fileprovider",
file);
sharingIntent.setType("*/*"); // any flie type
sharingIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(sharingIntent, "Share file"));
it works on android M ~ Pie
The Answer from #CommonsWare is great.
But in my case, I had to add multiple paths.
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
<files-path name="external_files" path="." />
</paths>
I see that at least you're not providing the same path as others in file_paths.xml.
So please make sure you provide the exact the same package name or path in 3 places including:
android:authorities attribute in manifest
path attribute in file_paths.xml
authority argument when calling FileProvider.getUriForFile().
For Xamarin.Android users
This could also be the result of not updating your support packages when targeting Android 7.1, 8.0+. Update them to v25.4.0.2+ and this particular error might go away(giving you´ve configured your file_path file correctly as others stated).
Giving context: I switched to targeting Oreo from Nougat in a
Xamarin.Forms app and taking a picture with the Xam.Plugin.Media
started failing with the above error message, so updating the packages
did the trick for me ok.
I noticed that the policy or behaviour regarding the path.xml file changed between Support Library 26 and 27. For capturing a picture from the camera, I saw the following changes:
With 26, I had to use <external-path> and the full path given in the path argument.
With 27, I had to use <external-files-path> and only the subfolder in the path argument.
So what specifically worked for me with Support Library 27 as the path.xml file was
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="camera_image" path="Pictures/"/>
</paths>

jaxb binding customization without having xsd

I've a wsdl (I dont have the .xsd file) and I want to generate the classes from it.
Using wsimport I get a tree of classes that is the standard mapping of the webservice schemas itself and of its dependencies.
I obtain something like com->(microsoft,mycompany), org->(apache).
However I need to remap the package com.mycompany and all the classes inside into com.mycompany.test.
So I've tried to use the option of -b of ws import creating a a docbinding.xml that is Schema Customization XML. The content is :
<jxb:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings node="wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='http://mycompany.com/test/']">
<jaxb:package name="com.mycompany.test"/>
</jxb:bindings>
</jxb:bindings>
launching wsimport with this syntax :
wsimport -p com.mycompany -b docbinding.xml https://mycompany.com/nicews/test.svc?wsdl
I obtain a initial error that stops the generation of the classes:
[ERROR] XPath error: null
...
How can I fix the binding XML ?
If the types are in seperate XSD files. This is the way to do it.
Create two configuration files.
wsdl.jxb
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="https://mycompany.com/nicews/test.svc?wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:package name="com.mycompany.wsdl"/> <!-- namespace what you want here -->
</jaxws:bindings>
xsds.jxb
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<!-- This is used becuase we don't need to differentiate between absent and nil elements, you may want to differentiate. If so, remove this binding -->
<jaxb:globalBindings generateElementProperty="false">
<xjc:simple />
</jaxb:globalBindings>
<!-- REPEAT THIS SECTION FOR EACH XSD, replacing schemaLocation and package with whatever you want -->
<jaxb:bindings
schemaLocation="http://mycompany.com/someWsdlIncludeLocation?xsd=xsd0"
node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.mycompany.dto.saml" />
</jaxb:schemaBindings>
</jaxb:bindings>
<!-- END SECTION -->
</jaxb:bindings>
Create a batch file in the same directory
rmdir /S /Q build
rmdir /S /Q dist
rmdir /S /Q src
mkdir build
mkdir dist
mkdir src
"%JAVA_HOME%\bin\wsimport.exe" -b wsdl.jxb -b xsds.jxb -s src -d build -keep http://mycompany.com/someWSDLlocation?wsdl
"%java_home%\bin\jar" cf dist/mycompanyClient.jar -C build/ .
"%java_home%\bin\jar" cf dist/mycompanyClient-src.jar -C src/ .
See if that works for you. Make sure to edit the JXB files appropriately for your wsdl/xsd locations, and packages you want.

Applying external JAXB binding file to schema elements imported from WSDL

The XPath expression in my external binding files can't target the elements in my XML schemas which are imported into my WSDL.
Everything runs if I do inline binding customization but I really wanted to have external binding files that way I never accidentally overwrite(refresh) the files containing my customizations.
The start of my binding file:
<jaxb:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
version="2.1">
<jaxb:bindings schemaLocation="../wsdl/localhost_7001/ExampleSessionBean/ExampleSessionBeanService.wsdl#types?schema1">
<jaxb:bindings node="//xs:schema[#targetNamespace='urn:myExample']">
My WSDL contains:
<types>
<xsd:schema>
<xsd:import namespace="urn:myExample" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://ejbs/" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=2"/>
</xsd:schema>
</types>
No matter what I do XPath can't find anything in the xsd:import'ed schemas. The error I get is:
[ERROR] XPath evaluation of "//xs:schema[#targetNamespace='urn:myExample']" results in empty target node
I've tried accessing the xs:schema by index number instead of the namespace and that doesn't work either. It seems like my XPath expressions can't reach elements from imported schemas...is there anyway to fix this?
This is a Java SE 7 project being developed under NetBean 7.2. I'm using NetBeans to do all my wsimport stuff if that matters but the command output looks fairly standard for RI/Metro.
EDIT:
I figured out that I can get an external binding file to work if I use SCD. This XPath example doesn't work:
<bindings node="//xsd:schema[#targetNamespace='urn:myExample']">
<bindings node="//xs:complexType[#name='myType']">
<class name="MyClass"/>
</bindings>
</bindings>
But this SCD example does.
<bindings scd="x-schema::tns" xmlns:tns="urn:myExample">
<bindings scd="~tns:myType">
<class name="MyClass"/>
</bindings>
</bindings>
Is this a known thing where XPath doesn't work in xjb files when using wsimport but SCD does?
you should use it like:
<jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[#targetNamespace='http://duke.example.org']">
<jaxb:schemaBindings>
<jaxb:package name="fromwsdl.server"/>
</jaxb:schemaBindings>
</jaxws:bindings>
Be careful with the namespaces
It all is explained here:
https://jax-ws.java.net/nonav/2.1.2/docs/customizations.html
You could compile each of the XML schemas to Java classes individually. Then you can leverage episode files so that the generated classes can be used when you compile schemas that import that XML schema.
Below is an example of how you produce an episode file.
xjc -b binding1.xml -episode common.episode common.xsd
And below is an example of how you consume and episode file. The episode file is just a JAXB external bindings file and therefore is specified using the -b flag.
xjc -d out main.xsd -extension -b common.episode
For More Information
http://blog.bdoughan.com/2011/12/reusing-generated-jaxb-classes.html
For new people, you can simply use two binding files, one applied to wsdl and other applied to the schema by using the -b option of wsdl2java cxf code generation class accepts multiple binding files:
<java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
<arg value="-d"/>
<arg value="${src}"/>
<arg value="-b"/>
<arg value="${wsdl.home}\jaxws-bindings.xml"/>
<arg value="-b"/>
<arg value="${wsdl.home}\jaxb-bindings.xml"/>
<arg value="${wsdl.home}\YOUR_WSDL.wsdl"/>
<classpath>
<path refid="cxf.classpath"/>
</classpath>
</java>
Content of file 'jaxws-bindings.xml':
<jaxws:bindings wsdlLocation="YOUR_WSDL.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
Content of 'jaxb-bindings.xml':
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings schemaLocation="ManagePartyCustomerDataManagement_PARTY_G7-IOP_In_1.0.xsd">
<jaxb:bindings node="//xsd:element[#name='eventDate']">
<jaxb:javaType name="java.util.Date"
parseMethod="com.sofrecom.gaia.ebs.provider.utils.jaxb.StringDateAdapter.parseDate"
printMethod="com.sofrecom.gaia.ebs.provider.utils.jaxb.StringDateAdapter.printDate" />
</jaxb:bindings>
Adding this section to my JAXB configuration helped to do away with a similar error:
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
<jaxws:enableAsyncMapping>false</jaxws:enableAsyncMapping>
</jaxws:bindings>
Complete configuration:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings version="2.1"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
<jaxws:enableAsyncMapping>false</jaxws:enableAsyncMapping>
</jaxws:bindings>
<jaxb:bindings schemaLocation="ContactService.wsdl" node="/wsdl:definitions/wsdl:types/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="za.org.kuali.kfs.sys.integration.iapi.contactservice"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Credits:
https://stackoverflow.com/a/7890753/315385
https://stackoverflow.com/a/38077750/315385

xjc inverse package name order

I run the following command
java -jar "C:\Program Files\eclipse\plugins\org.jvnet.jaxbw.eclipse_1.1.0\lib\jaxb-xjc.jar" -d src -catalog xsd\catalog.cat xsd\componentsData.xsd
xsd\componentsData.xsd contain the following lines:
xmlns:txtColor="com.my.company.product.jaxb.TextColor"
xmlns="com.my.company.product.jaxb.componentsData"
targetNamespace="com.my.company.product.jaxb.componentsData"
<xsd:import
schemaLocation="TextColor.xsd"
namespace="com.my.company.product.jaxb.TextColor"/>
xsd\TextColor.xsd contain the following
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
xmlns="com.my.company.product.jaxb.TextColor"
targetNamespace="com.my.company.product.jaxb.TextColor"
>
this is my catalog:
<!DOCTYPE catalog
PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system
systemId="com.my.company.product.jaxb.TextColor.TextColor.xsd"
uri="TextColor"/>
and my files got generated in the following path - THE ORDER IS INVERTED WHY ?:
componentsData.jaxb.product.company.my.com
and
TextColor.jaxb.product.company.my.com
if i add the following argument files got generated in the right order but the catalog.cat don't seem to be taken in consideration
-p com.my.company.product.jaxb.componentsData
I needed to add a binding file (-b option with xjc)
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="2.1">
<jaxb:bindings schemaLocation="componentsData.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.my.company.product.jaxb.componentsData"/>
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="TextColor.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.my.company.product.jaxb.TextColor"/>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
But i still have a question:
I Started using xjc because i didn't succeed doing it with eclipse, how can i do it with eclipse gui

MSBuild: Permanently Change PropertyGroup Property of a Project

I was hoping to find a way to set a value in my csproj file during my build to a value. Is there a task in MSBuild that I can use to set a property permanently to a value? In the example below, can I set CustomValue = Yes permanently?
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
.....
<CustomValue>XXXX</CustomValue
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids></ProjectTypeGuids>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
You can use the XmlPoke task to do that. It seems a little odd to be altering projects this way though. Alternatively, you can set up a tiny import file,
<!-- in your main project file, right below the PropertyGroup -->
<Import
Condition="Exists('Custom.props')"
Project="Custom.props"
/>
Then dynamically create this property file, as,
<?xml version="1.0" encoding="utf-8"?>
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0">
<PropertyGroup>
<CustomValue>True</CustomValue>
</PropertyGroup>
</Project>
You can either use XmlPoke on just this .props file, or use WriteLinesToFile to create the entire file. This secondary file wouldn't need to be checked into source control, the condition on the import makes the project functional when the file doesn't exist.
The XmlPoke task would look like this,
<XmlPoke
XmlInputPath="./Custom.props"
Namespaces="<Namespace Prefix='x'
Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
Query="//x:PropertyGroup/x:CustomValue/#Value"
Value="True"
/>

Resources