cancel
Showing results for 
Search instead for 
Did you mean: 

How to share "common code" in many projects

Former Member
0 Kudos

Hello,

I have a lot of "utility code" that I want to be able to use in all/most of my projects. Having a difficult time figuring out how to make it available in them.

For example, I am writing a class in a Web Module project and I need to reference a class/method in one of my utility classes. How do I make that available to that class without having to recreate the class(es) in the new project?

I have tried several things with no luck:

1) Create a new Web Module Project called "MyApp"

2) Create a new class in the project.

3) Put this line in new class: "import mycode.utilities.*" This, of course, generates an error because it doesn't know where the package "mycode.utilities" is. I'll explain later how I try to make it available.

4) Write code in my new class that references classes/methods from the utility package. This also, of course, generates errors.

5) In the Package Explorer view, right-click on the "source" folder of "MyApp" project and choose Import

6) Choose "Zip file" from the "Import" screen

7) Select the jar file containing the class files of my utility code and check the whole package

😎 After the import I verify that the class files have been imported into the project. In the Package explorer view I only see the package name but if I switch to the J2EE Explorer view I see the individual classes in the tree structure.

9) Go back into my source code. The import statement is no longer an error but all the references to classes in that package are still errors.

10) I've tried importing the jar file into various other places in the project but none of them fix the problem.

I would appreciate any help.

Thanks.

David

Message was edited by: David Pantich

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi David,

There are several things you have do:

Create a library Project which includes your common jar file and reference this library Project to your application.

1. see http://help.sap.com/saphelp_nw04/helpdata/en/e6/2eb540e4c5782ae10000000a155106/frameset.htm

build a library project "myLib" and include your jar file. Deploy this project.

2. right-click to root of "MyApp" Project into J2EE Explorer -> Properties -> Java Build Path -> Tab Projects: select your created lib project.

3. right-click to root of "MyApp" Project into J2EE Explorer -> Properties -> Project References -> select your created lib project.

I hope this works.

Regards André

Answers (2)

Answers (2)

Former Member
0 Kudos

We ended up creating a separate DC of type Java. It contains all our common source code. We then 'exposed' that code as public parts.

If we needed to use 3rd party libraries, we put them in DCs of type External Library and created Public Parts for those.

Then we created Used DC entries pointing to the various Public Parts that each app's DC needed.

Former Member
0 Kudos

Thanks to all who responded and told me how to edit a message.

Message was edited by: David Pantich

Former Member
0 Kudos

Hi David,

You can edit your message using the "pencil" icon on the right side of your message instead of posting a reply to mark corrections.

Regards,

Sanjeev

Former Member
0 Kudos

Sanjeev,

Thanks for the tip. Now that you pointed it out I can't believe I didn't notice the "pencil" myself.

David

Former Member
0 Kudos

Hi David,

In order to access a method , or code from one project to another project the best bet is creating a DC, How to create a DC, Public parts etc.. more in fo you will get in the <b>Java Dovelopment Infrastructure</b> topic.

hope this helped you

(meanwhile to edit your message on the right top your message there is a pencil icon use this option to edit ur messages)

Regards,

RK

Former Member
0 Kudos

RK,

I have been going thru the Scenario 2+ tutorial for JDI. That has instructions for creating DCs, public parts, etc.

The problem is that the documentation is either incomplete or incorrect. I keep getting stuck on a specific step. I've started from scratch twice and gotten stuck at the same spot each time.

Today I plan on going thru it again and taking screen prints at every step.

Once I've done that, what is the best way to get SAP to help me figure out why it doesn't work like the documentation says? Has anyone had any luck using OSS to get Netweaver Studio help?

Thanks again RK.

David.