Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:33:18+00:00 2026-06-01T16:33:18+00:00

In my current Java project, I have written a Java program that copies some

  • 0

In my current Java project, I have written a Java program that copies some Java files from package “fr.inria.arles.pankesh.gen” to package “fr.inria.arles.pankesh.impl”.

After copying Java files from package “fr.inria.arles.pankesh.gen” to package “fr.inria.arles.pankesh.impl” , my java files are giving errors , due to package Information change of Java file.

My question is “Is there any way to change package information ( thru java code, not manually) in header , when my program copies Java files from package “fr.inria.arles.pankesh.gen” to package “fr.inria.arles.pankesh.impl”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:33:19+00:00Added an answer on June 1, 2026 at 4:33 pm

    If you copy java source files, you need to

    1. Open the source file.
    2. Open the destination file.
    3. Copy everything from the source into the destination, up until you see the package keyword.
    4. Copy the package keyword into the destination file.
    5. Write the “corrrect” package location into the destination file
    6. Skip over the “incorrect” package location in the source file
    7. Write the remainder of the contents from the source file into the destination file.

    Note that this will correctly “rebase” a file’s package; but it will do nothing to “rebase” other files which might expect to find that file in the “old” package. To fix those other files (if they exist, perhaps your project is designed to not have so many reference, or you intend to copy all the files), you need to open up each file in your project looking for the “moved” class in an import statement. If you find it, you need to not copy the import but copy in the correct replacement.

    When working with a file that doesn’t really “move” but needs to be changed, the best strategy is to write a temporary file, and then to replace the original with the temporary file after the temporary file is completely written. Like so:

    (reading) MyClass.java
    (writing) .tempMyClass.java
    (done writing)
    (moving)  .tempMyClass.java to MyClass.java
    

    This allows you to not be constrained by a number of nasty items, like writing in the file past where you need to read from (which will destroy the information you need before you read it).

    The packages java.io and the class java.lang.String have all the utilities to allow you to write these tools, but to go into detail would be far too long a post. Try writing a little bit, search the web for (how do I read lines from a file with java, how do I write lines to a file with java) when you get stuck, post the code for how far you have gotten and your specific error or misunderstanding, and plenty of people will be happy to help.

    If you want to do this for already-compiled files, you need to either read up a bit on the java class file format, and find the class name constant string, and alter it by a similar procedure above (except you will be writing binary bytes), or you could use a library like ASM to do the same procedure as above (but perhaps save you the mistakes you might make when doing it by hand).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a java project full of Hibernate (3.3.1) mapping files that have
I have a Java project that has just about every class and package depending
I have a Java program that stores a lot of mappings from Strings to
How can I change the current working directory from within a Java program? Everything
My current task is taking a Java project written and developed in Ubuntu NetBeans
I have a Java project that expects external modules to be registered with it.
We have a current Java EE project and a new requirement to introduce a
I'm working on a java project that utilizes XML files in Eclipse; however, I
I'm a .Net developer, but for my current project I have to create some
In my current project I use IKVM to cross-compile several Java libraries that deal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.