Java clashes with class of same name package

What product/components do you use and which version/fix level?

10.3

Are you using a free trial or a product with a customer license?

Customer License

What are trying to achieve? Please describe in detail.

I encountered this error when i create a new java service with a new folder
util/test.java:1: error: package mandiri.sams.util clashes with class of same name
package mandiri.sams.util;

Below is the screenshot of my java service location

Any Idea or Suggestion? Thanks
Tried to create a new java service with a different name but i still getting the same error

Are you trying to create a “real” Java service, and just sharing an example with a dummy name using “testmyjava”? Or are you new to wM IS development and exploring/learning?

I’m curious as to why the Java development perspective is being used instead of the Service Development perspective. The primary language of Integration Server is FLOW. Java can be used, certainly, but mostly for small, focused services. When creating those, you’ll want to use the Service Development perspective and place the Java services within the folder of choice.

Keep in mind that where Java services can be placed in folders in a package is somewhat restricted to avoid class name collisions. Refer to the documentation.

Avoid the temptation to do lots of things in Java. Most of the code should be FLOW, not Java. I mention this caveat because your post shows the Java perspective, which tends to indicate you want to “do Java” rather than FLOW develoment. But that may be an incorrect perception on my part.

hello reamon, i want to create a real java service but when i want to compile the java service, it always failed to compile, it’s weird that nothing have the same name on my folders but it keeps saying clashes with class of same name.

Also i use the java perspective to show the java services that i created, and need the java service because i want to invoke some thread asynchronously by doThreadInvoke

Hi @mcser76 ,
Please check out the linked topic where the same error is discussed . wM Java Error - The source was saved, but was not compiled due to the following errors: - Forum - webMethods - Software AG Tech Community & Forums
-NP

Groups them together, sure. But you can edit any Java service in Service Development perspective. Not sure what other benefit the Java perspective provides. I mention it not to object to the use of the Java perspective, but to caution about using “too much” Java.

May I ask the reason for doing so? Usually it is with the view that multiple threads will result in faster overall execution. That may be the case but depends upon a number of factors. Need to make sure the complexity and added error handling is offset by the benefit.

It may also be to simply kick off async processing with no intent to join the threads back together. We’ve found that useful though we now generally use pub/sub instead to get async handling.

In your screen shot, can you expand mandiri.sams.util? May be a conflict at a class/folder level. Each folder becomes a class. Having Java services in multiple nested folders is generally to be avoided. A common approach is to place all Java services in a single folder, usually near the top, in a given package to avoid this class collision issue.

i tried to check there are clearly no java service with a same name inside the folder and the outer directory


also i found another java service with the same name in another folder within the same package
image
this supposed to be fine as long its a different folder right?

Sorry I wasn’t very clear with the explanation. I asked about the content of the mandiri.sams.util to see if there were other Java services within. It is not about 2 services with the same name. It is about nested folders that both contain Java services. That cannot be done. Designer will let you create them, but once you edit the Java service in the nested folder, that is when the conflict arises. The way the Java code is managed is a combination of Java packages and classes.

For example:

image

The aggregated code, when you view the source in the file system on the server, looks like this:

image

The content of Sample/util.java is:

package Sample;
// -----( IS Java Code Template v1.2
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
// --- <<IS-START-IMPORTS>> ---
// --- <<IS-END-IMPORTS>> ---

public final class util
{
	// ---( internal utility methods )---
	final static util _instance = new util();
	static util _newInstance() { return new util(); }
	static util _cast(Object o) { return (util)o; }

	// ---( server methods )---
	public static final void myjava (IData pipeline)
        throws ServiceException
	{
		// --- <<IS-START(myjava)>> ---
		// @sigtype java 3.5
		// --- <<IS-END>> ---
	}
}

Note the name of the class.

The content of Sample/util/test.java is:

package Sample.util;
// -----( IS Java Code Template v1.2
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
// --- <<IS-START-IMPORTS>> ---
// --- <<IS-END-IMPORTS>> ---

public final class test
{
	// ---( internal utility methods )---
	final static test _instance = new test();
	static test _newInstance() { return new test(); }
	static test _cast(Object o) { return (test)o; }

	// ---( server methods )---
	public static final void yourjava (IData pipeline)
        throws ServiceException
	{
		// --- <<IS-START(yourjava)>> ---
		// @sigtype java 3.5
		// --- <<IS-END>> ---
	}
}

Note the package name. That is where the conflict is – package name (folder) collision with a class name (another folder). It is not the names of the Java services. It is the presence of Java services, with any name, at multiple levels within a single folder tree.

Editing and saving the Java service in the nested folder results in the error in your OP:

...packages/Sample/code/source/Sample/util/test.java:1: error: package Sample.util clashes with class of same name
package Sample.util;

Interestingly, the error does not appear when the Java service in the nested folder is initially created. Just when it is edited and saved.

Have you tried editing any of the Java services in any other child folder? My guess is the save will complain about those too.

Moving the Java services that are directly in the util folder to a child folder should do the trick.

1 Like

Thank you reamon, you solved the problem, thank you for your deep explanation about how the java classes work

this really solve the problem, now i get it and i will avoid making java service on the outer folder in the future.
Thank you so much raemon

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.